日期:2014-05-18 浏览次数:21495 次
public static bool InStock(SqlParameter[] OrderParas, List<SqlParameter[]> InStockParas, DataTable DetailTable) { bool _pass = false; string connectString = Encrypt.DecryptString(System.Configuration.ConfigurationManager.AppSettings["ConnetString"]); using (SqlConnection Conn = new SqlConnection(connectString)) { Conn.Open(); using (SqlTransaction Tran = Conn.BeginTransaction()) { try { using (SqlCommand Comm = new SqlCommand()) { Comm.Transaction = Tran; Comm.Connection = Conn; Comm.CommandType = CommandType.StoredProcedure; Comm.CommandText = "p_OutOrderStateUpdate_Update"; Comm.Parameters.AddRange(OrderParas); Comm.ExecuteNonQuery(); Comm.CommandText = "p_ProductsInStorage_Insert"; for (int j = 0; j < InStockParas.Count; j++) { Comm.Parameters.Clear(); Comm.Parameters.AddRange(InStockParas[j]); Comm.ExecuteNonQuery(); } } using (SqlBulkCopy copy = new SqlBulkCopy(Conn, SqlBulkCopyOptions.CheckConstraints, Tran) { DestinationTableName = "tbInStockDetail" }) { for (int i = 0; i < DetailTable.Columns.Count; i++) { copy.ColumnMappings.Add(DetailTable.Columns[i].ColumnName, DetailTable.Columns[i].ColumnName); } copy.WriteToServer(DetailTable); } Tran.Commit(); _pass = true; } catch (Exception ex) { Tran.Rollback(); throw new Exception(ex.ToString()); } } } return _pass; }