private int AddCai() { CAI_OrderInHousesService ordersSer = new CAI_OrderInHousesService(); orders_CaiIn = ordersSer.GetListArray(" 1=1 and CAI_OrderInHouses.id=1"); //采购单 CAI_POOrder order = new CAI_POOrder(); order.AppName = 1; order.CaiGou = "admin"; order.AE = ""; order.GuestName = ""; order.GuestNo = ""; order.INSIDE = ""; order.PODate = Convert.ToDateTime("2012-06-19"); order.POName = "库存初始化"; order.POPayStype = "1"; order.POTotal = Convert.ToDecimal(628650.72000); order.PONo = ""; order.BusType = "1"; order.CG_ProNo = ""; order.cRemark = ""; List <CAI_POOrders> POOrders = new List <CAI_POOrders>(); foreach (var m in orders_CaiIn) { CAI_POOrders cai = new CAI_POOrders(); cai.InvName = m.GoodName; cai.Num = m.GoodNum; cai.CostPrice = m.GoodPrice; cai.OtherCost = 0; cai.ToTime = Convert.ToDateTime("2012-06-26 00:00:00.000"); cai.Profit = 0; cai.GoodId = m.GooId; cai.CG_POOrdersId = 0; POOrders.Add(cai); } List <CAI_POCai> caiOrders = new List <CAI_POCai>(); foreach (var m in orders_CaiIn) { CAI_POCai cai = new CAI_POCai(); cai.Supplier = "本部门(含税)"; cai.SupperPrice = m.GoodPrice; cai.UpdateUser = "******"; cai.Idea = ""; cai.Num = m.GoodNum; cai.FinPrice1 = m.GoodPrice; cai.GoodId = m.GooId; cai.cbifDefault1 = true; cai.lastSupplier = "本部门(含税)"; cai.IsHanShui = true; cai.LastTruePrice = m.GoodPrice; caiOrders.Add(cai); } tb_EForm eform = new tb_EForm(); eform.appPer = 1; eform.appTime = DateTime.Now; eform.createPer = 1; eform.createTime = DateTime.Now; eform.proId = 20; eform.state = "通过"; eform.toPer = 0; eform.toProsId = 0; CAI_POOrderService POOrderSer = new CAI_POOrderService(); int MainId = 0; return(POOrderSer.addTran(order, eform, POOrders, caiOrders, out MainId, false)); }
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); } }
protected void gvCai_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#EAF1FD',this.style.fontWeight='';"); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';"); CAI_POCai model = e.Row.DataItem as CAI_POCai; if (model.IsHanShui == false) { e.Row.BackColor = System.Drawing.Color.LightGray; } if (model.Total1 != null) { if (SumPOCai.Total1 == null) { SumPOCai.Total1 = 0; } SumPOCai.Total1 += model.Total1; } if (model.Total2 != null) { if (SumPOCai.Total2 == null) { SumPOCai.Total2 = 0; } SumPOCai.Total2 += model.Total2; } if (model.Total3 != null) { if (SumPOCai.Total3 == null) { SumPOCai.Total3 = 0; } SumPOCai.Total3 += model.Total3; } if (model.Num != null) { if (SumPOCai.Num == null) { SumPOCai.Num = 0; } SumPOCai.Num += model.Num; } } Label lblPrice1 = e.Row.FindControl("lblSupperPrice") as Label; //Label lblFinPrice1 = e.Row.FindControl("lblFinPrice1") as Label; //if (lblPrice1 != null && lblFinPrice1 != null) //{ // if (lblPrice1.Text != "" && lblFinPrice1.Text != "") // { // if (Convert.ToDecimal(lblPrice1.Text) != Convert.ToDecimal(lblFinPrice1.Text)) // { // e.Row.Cells[6].ForeColor=System.Drawing.Color.Red; // } // } //} Label lblPrice2 = e.Row.FindControl("lblSupperPrice1") as Label; //Label lblFinPrice2 = e.Row.FindControl("FinPrice2") as Label; //if (lblPrice2 != null && lblFinPrice2 != null) //{ // if (lblPrice2.Text != "" && lblFinPrice2.Text != "") // { // if (Convert.ToDecimal(lblPrice2.Text) != Convert.ToDecimal(lblFinPrice2.Text)) // { // e.Row.Cells[10].ForeColor = System.Drawing.Color.Red; // } // } //} Label lblPrice3 = e.Row.FindControl("lblSupperPrice2") as Label; //Label lblFinPrice3 = e.Row.FindControl("FinPrice3") as Label; //if (lblPrice3 != null && lblFinPrice3 != null) //{ // if (lblPrice3.Text != "" && lblFinPrice3.Text != "") // { // if (Convert.ToDecimal(lblPrice3.Text) != Convert.ToDecimal(lblFinPrice3.Text)) // { // e.Row.Cells[14].ForeColor = System.Drawing.Color.Red; // } // } //} List <decimal> pricelMax = new List <decimal>(); if (lblPrice1 != null && lblPrice1.Text != "") { pricelMax.Add(Convert.ToDecimal(lblPrice1.Text)); } if (lblPrice2 != null && lblPrice2.Text != "") { pricelMax.Add(Convert.ToDecimal(lblPrice2.Text)); } if (lblPrice3 != null && lblPrice3.Text != "") { pricelMax.Add(Convert.ToDecimal(lblPrice3.Text)); } if (pricelMax.Count > 0) { decimal minPrice = pricelMax.Min(); decimal lirun = 0; List <CAI_POOrders> POOrders = ViewState["Orders"] as List <CAI_POOrders>; Label lblGoodId = e.Row.FindControl("lblGoodId") as Label; CAI_POOrders po = null; if (POOrders != null && lblGoodId != null) { po = POOrders.Find(p => p.GoodId.ToString() == lblGoodId.Text); if (po != null && po.SellTotal != 0) { lirun = ((po.SellTotal - minPrice * po.Num - po.OtherCost) / po.SellTotal) * 100; } else if (po != null) { decimal yiLiTotal = po.SellTotal - minPrice * po.Num - po.OtherCost; if (yiLiTotal != 0) { lirun = -100; } } } Label lblCaiLiRun = e.Row.FindControl("lblCaiLiRun") as Label; if (lblCaiLiRun != null) { lblCaiLiRun.Text = string.Format("{0:n2}", lirun); if (po != null && po.Profit != null && lirun < po.Profit.Value) { lblCaiLiRun.ForeColor = System.Drawing.Color.Red; } } } //ImageButton btnEdit = e.Row.FindControl("lblFinPrice1") as ImageButton; //if (btnEdit != null) //{ //// string val = string.Format("javascript:window.showModalDialog('WFPOCai.aspx?indexcai={0}',null,'dialogWidth:500px;dialogHeight:450px;help:no;status:no')", e.Row.DataItemIndex); //// btnEdit.Attributes.Add("onclick", val); //} if (e.Row.RowType == DataControlRowType.Footer) { setValue(e.Row.FindControl("lblNum") as Label, SumPOCai.Num == null ? "" : SumPOCai.Num.ToString()); //数量 setValue(e.Row.FindControl("lblTotal1") as Label, SumPOCai.Total1 == null ? "" : SumPOCai.Total1.ToString()); //小计1 setValue(e.Row.FindControl("lblTotal2") as Label, SumPOCai.Total2 == null ? "" : SumPOCai.Total2.ToString()); //小计2 setValue(e.Row.FindControl("lblTotal3") as Label, SumPOCai.Total3 == null ? "" : SumPOCai.Total3.ToString()); //小计3 List <decimal> totalMax = new List <decimal>(); if (SumPOCai.Total1 != null) { totalMax.Add(SumPOCai.Total1.Value); } if (SumPOCai.Total2 != null) { totalMax.Add(SumPOCai.Total2.Value); } if (SumPOCai.Total3 != null) { totalMax.Add(SumPOCai.Total3.Value); } if (totalMax.Count > 0) { decimal minPrice = totalMax.Min(); decimal lirun = 0; decimal sellTotal = 0; decimal otherCost = 0; List <CAI_POOrders> POOrders = ViewState["Orders"] as List <CAI_POOrders>; foreach (var model in POOrders) { sellTotal += model.SellTotal; otherCost += model.OtherCost; } if (sellTotal != 0) { lirun = ((sellTotal - minPrice - otherCost) / sellTotal) * 100; } else { decimal yiLiTotal = sellTotal - minPrice - otherCost; if (yiLiTotal != 0) { lirun = -100; } } setValue(e.Row.FindControl("lblCaiLiRun") as Label, ConvertToObj(lirun).ToString());//数量 } } }