事物
#region IOrder 成员
bool IDal.IOrder.ProcessOrder(IList<Modal.CartItem> li, string user)
{
using (SqlConnection connection = new SqlConnection(Common.Common.cn))
{
connection.Open();
SqlTransaction sqlTran = connection.BeginTransaction();
SqlCommand command = connection.CreateCommand();
command.Transaction = sqlTran;
try
{
command.CommandText =
"select id from Users where Name=" + user;
int userID= Convert.ToInt32( command.ExecuteScalar());
command.CommandText =
"INSERT INTO Orders(UserId,OrderTime,BillNo,State,Des) VALUES(userID,getdate(),convert(nvarchar(10),userID)+'-'+'...',0,'')";
command.ExecuteNonQuery();
command.CommandText =
"select max(id) from Orders";
int oID = Convert.ToInt32(command.ExecuteScalar());
sqlTran.Commit();
return true;
}
catch (Exception ex)
{
sqlTran.Rollback();
return false;
}
}
}
#endregion