public bool UpdataCai(List <CAI_POCai> Cais) { using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlTransaction tan = conn.BeginTransaction(); SqlCommand objCommand = conn.CreateCommand(); objCommand.Transaction = tan; CAI_POCaiService CaiSer = new CAI_POCaiService(); try { objCommand.Parameters.Clear(); #region 采购 for (int i = 0; i < Cais.Count; i++) { if (Cais[i].IfUpdate == true && Cais[i].Ids != 0) { CaiSer.Update(Cais[i], objCommand); } else if (Cais[i].Ids == 0) { CaiSer.Add(Cais[i], objCommand); } } #endregion tan.Commit(); } catch (Exception) { tan.Rollback(); return(false); } } return(true); }
public bool updateTran(VAN_OA.Model.JXC.CAI_POOrder model, VAN_OA.Model.EFrom.tb_EForm eform, tb_EForms forms, List <CAI_POOrders> orders, string IDS, List <CAI_POCai> Cais, string CAI_IDS) { using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlTransaction tan = conn.BeginTransaction(); SqlCommand objCommand = conn.CreateCommand(); objCommand.Transaction = tan; CAI_POOrdersService OrdersSer = new CAI_POOrdersService(); CAI_POCaiService CaiSer = new CAI_POCaiService(); 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); //for (int i = 0; i < orders.Count; i++) //{ // orders[i].Id = model.Id; // //if (orders[i].IfUpdate == true && orders[i].Ids != 0) // //{ // OrdersSer.Update(orders[i], objCommand); // //} // //else if (orders[i].Ids == 0) // //{ // // OrdersSer.Add(orders[i], objCommand); // //} //} //if (IDS != "") //{ // IDS = IDS.Substring(0, IDS.Length - 1); // OrdersSer.DeleteByIds(IDS, objCommand); //} #region 采购 for (int i = 0; i < Cais.Count; i++) { Cais[i].Id = model.Id; if (Cais[i].IfUpdate == true && Cais[i].Ids != 0) { CaiSer.Update(Cais[i], objCommand); } else if (Cais[i].Ids == 0) { CaiSer.Add(Cais[i], objCommand); } } //if (CAI_IDS != "") //{ // CAI_IDS = CAI_IDS.Substring(0, CAI_IDS.Length - 1); // CaiSer.DeleteByIds(CAI_IDS, objCommand); //} #endregion tan.Commit(); } catch (Exception) { tan.Rollback(); return(false); } } return(true); }
public int addTran(VAN_OA.Model.JXC.CAI_POOrder model, VAN_OA.Model.EFrom.tb_EForm eform, List <CAI_POOrders> orders, List <CAI_POCai> caiOrders, out int MainId, bool isCopy = false) { CG_POCaiService poCaiSer = new CG_POCaiService(); var caiList = poCaiSer.GetCaiList(model.CG_ProNo); int id = 0; MainId = 0; using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlTransaction tan = conn.BeginTransaction(); SqlCommand objCommand = conn.CreateCommand(); objCommand.Transaction = tan; CAI_POOrdersService OrdersSer = new CAI_POOrdersService(); CAI_POCaiService caiSer = new CAI_POCaiService(); try { objCommand.Parameters.Clear(); tb_EFormService eformSer = new tb_EFormService(); string proNo = eformSer.GetAllE_No("CAI_POOrder", 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++) { orders[i].Id = id; OrdersSer.Add(orders[i], objCommand); if (isCopy == false) { CAI_POCai cai = new CAI_POCai(); cai.GuestName = orders[i].GuestName; cai.Num = orders[i].Num; cai.InvName = orders[i].InvName; cai.Id = id; cai.GoodId = orders[i].GoodId; var pocaiModel = caiList.Find(p => p.GoodId == orders[i].GoodId); if (pocaiModel != null) { cai.FinPrice1 = pocaiModel.FinPrice1; cai.FinPrice2 = pocaiModel.FinPrice2; cai.FinPrice3 = pocaiModel.FinPrice3; cai.SupperPrice = pocaiModel.SupperPrice; cai.SupperPrice1 = pocaiModel.SupperPrice1; cai.SupperPrice2 = pocaiModel.SupperPrice2; cai.Supplier = pocaiModel.Supplier; cai.Supplier1 = pocaiModel.Supplier1; cai.Supplier2 = pocaiModel.Supplier2; } caiSer.Add(cai, objCommand); } else { var pocaiModel = caiOrders.Find(p => p.GoodId == orders[i].GoodId); pocaiModel.GuestName = orders[i].GuestName; pocaiModel.Num = orders[i].Num; pocaiModel.InvName = orders[i].InvName; pocaiModel.Id = id; caiSer.Add(pocaiModel, objCommand); } } tan.Commit(); } catch (Exception) { tan.Rollback(); return(0); } return(id); } }