public bool updateTran(VAN_OA.Model.JXC.TB_SupplierAdvancePayment model, VAN_OA.Model.EFrom.tb_EForm eform, tb_EForms forms, List <SupplierToInvoiceView> orders, string IDS) { using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlTransaction tan = conn.BeginTransaction(); SqlCommand objCommand = conn.CreateCommand(); objCommand.Transaction = tan; try { objCommand.Parameters.Clear(); model.Status = eform.state; Update(model, objCommand); tb_EFormService eformSer = new tb_EFormService(); eformSer.Update(eform, objCommand); tb_EFormsService eformsSer = new tb_EFormsService(); eformsSer.Add(forms, objCommand); TB_SupplierAdvancePaymentsService OrdersSer = new TB_SupplierAdvancePaymentsService(); for (int i = 0; i < orders.Count; i++) { if (orders[i].IfCheck == false) { continue; } var modelSupplierInvoices = new TB_SupplierAdvancePayments(); modelSupplierInvoices.Ids = orders[i].payIds; modelSupplierInvoices.Id = model.Id; modelSupplierInvoices.CaiIds = orders[i].Ids; modelSupplierInvoices.SupplierFPNo = orders[i].SupplierFPNo; modelSupplierInvoices.SupplierInvoiceDate = orders[i].SupplierInvoiceDate.Value; modelSupplierInvoices.SupplierInvoiceNum = orders[i].SupplierInvoiceNum; modelSupplierInvoices.SupplierInvoicePrice = orders[i].SupplierInvoicePrice; modelSupplierInvoices.SupplierInvoiceTotal = orders[i].SupplierInvoiceTotal; if (eform.state == "通过" && (orders[i].SupplierProNo == null || orders[i].SupplierProNo == "")) { modelSupplierInvoices.SupplierProNo = GetAllE_No("TB_SupplierAdvancePayments", objCommand); } OrdersSer.Update(modelSupplierInvoices, objCommand); } tan.Commit(); } catch (Exception) { tan.Rollback(); return(false); } } return(true); }
public int addTran(VAN_OA.Model.JXC.TB_SupplierAdvancePayment model, VAN_OA.Model.EFrom.tb_EForm eform, List <SupplierToInvoiceView> orders, out int MainId) { int id = 0; MainId = 0; using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlTransaction tan = conn.BeginTransaction(); SqlCommand objCommand = conn.CreateCommand(); objCommand.Transaction = tan; TB_SupplierAdvancePaymentsService OrdersSer = new TB_SupplierAdvancePaymentsService(); try { objCommand.Parameters.Clear(); tb_EFormService eformSer = new tb_EFormService(); string proNo = eformSer.GetAllE_No1("TB_SupplierAdvancePayment", objCommand); model.ProNo = proNo; eform.E_No = proNo; model.Status = eform.state; id = Add(model, objCommand); MainId = id; eform.allE_id = id; eformSer.Add(eform, objCommand); for (int i = 0; i < orders.Count; i++) { if (orders[i].IfCheck == false) { continue; } var modelSupplierInvoices = new TB_SupplierAdvancePayments(); modelSupplierInvoices.Id = id; modelSupplierInvoices.CaiIds = orders[i].Ids; modelSupplierInvoices.SupplierFPNo = orders[i].SupplierFPNo; modelSupplierInvoices.SupplierInvoiceDate = orders[i].SupplierInvoiceDate.Value; modelSupplierInvoices.SupplierInvoiceNum = orders[i].SupplierInvoiceNum; modelSupplierInvoices.SupplierInvoicePrice = orders[i].SupplierInvoicePrice; modelSupplierInvoices.SupplierInvoiceTotal = orders[i].SupplierInvoiceTotal; if (eform.state == "通过" && (orders[i].SupplierProNo == null || orders[i].SupplierProNo == "")) { modelSupplierInvoices.SupplierProNo = GetAllE_No("TB_SupplierAdvancePayments", objCommand); } OrdersSer.Add(modelSupplierInvoices, objCommand); } var otherOrders = orders.FindAll(t => t.IfCheck == false); foreach (var otherOrder in otherOrders) { string insertSql = string.Format("insert into TB_TempSupplierInvoice values(0,{1},{0})", id, otherOrder.payIds); objCommand.CommandText = insertSql; objCommand.ExecuteNonQuery(); } tan.Commit(); } catch (Exception) { tan.Rollback(); return(0); } return(id); } }