{
string pwdchars = "AHSHJSHSDHDJDJDJJD121334344444";
USERDB.Model.A_OrderInfo OrderInfoModel = new USERDB.Model.A_OrderInfo();
OrderInfoModel.OrderCode = MakeRandomStr(pwdchars, 20, 10);
OrderInfoModel.Money = 3000;
OrderInfoModel.Consignee = "张三";
OrderInfoModel.CreateDate = DateTime.Now;
OrderInfoModel.Address = "漕溪路250号";
OrderInfoModel.Ctiy = "徐汇区";
IDbConnection connection = new SqlConnection(Config.Connection);
if (connection == null)
{
return;
}
if (connection.State != ConnectionState.Open)
{
connection.Open();
}
int count = 0;
IDbTransaction transaction = connection.BeginTransaction();
try
{
count = new USERDB.BLL.A_OrderInfo().Add(OrderInfoModel, connection, transaction);
if (count > 0)
{
USERDB.Model.A_OrderPro OrderProModel = new USERDB.Model.A_OrderPro();
OrderProModel.CreateDate = DateTime.Now;
OrderProModel.CreateUserID = 1;
OrderProModel.OrderID = count;
OrderProModel.OrderCode = OrderInfoModel.OrderCode;
OrderProModel.ProName = "TCL电视机";
int ProId = new USERDB.BLL.A_OrderPro().Add(OrderProModel, connection, transaction);
if (ProId > 0)
{
transaction.Commit();
}
}
}
catch (Exception ex)
{
string ek = ex.Message;
transaction.Rollback();
}
finally
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
}
}
public static string MakeRandomStr(string pwdchars, int pwdlen, int rd)
{
string tmpstr = "";
int iRandNum;
Random rnd = new Random(unchecked(rd * Convert.ToInt32(DateTime.Now.ToString("mmss"))));
for (int i = 0; i < pwdlen; i++)
{
iRandNum = rnd.Next(pwdchars.Length);
tmpstr += pwdchars[iRandNum];
}
return tmpstr;
}