protected void btnSave_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtNum.Text)&&CommHelp.VerifesToNum(txtNum.Text)==false) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('数量 格式有误!');</script>"); return; } if (!string.IsNullOrEmpty(txtOtherCost.Text) && CommHelp.VerifesToNum(txtOtherCost.Text) == false) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('管理费 格式有误!');</script>"); return; } if (!string.IsNullOrEmpty(txtSellPrice.Text) && CommHelp.VerifesToNum(txtSellPrice.Text) == false) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('销售单价 格式有误!');</script>"); return; } if (!string.IsNullOrEmpty(txtCostPrice.Text) && CommHelp.VerifesToNum(txtCostPrice.Text) == false) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('成本单价 格式有误!');</script>"); return; } if (txtToTime.Text != "") { try { Convert.ToDateTime(txtToTime.Text); } catch (Exception) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('到帐日期格式有误!');</script>"); return; } } if (CommHelp.GetByteLen(lblModel.Text) > 20 * 2) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('型号长度不能超过20个汉字符,请修正!');</script>"); return; } if (CommHelp.GetByteLen(txtDetailRemark.Text) > 20 * 2) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('备注长度不能超过20个汉字符,请修正!');</script>"); return; } int goodId = goodsSer.GetGoodId(txtInvName.Text, lblSpec.Text, lblModel.Text,lblGoodSmTypeName.Text,lblUnit.Text); if (goodId == 0) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('你填写的商品不存在!');</script>"); return; } try { Convert.ToDecimal(txtSellPrice.Text); Convert.ToDecimal(txtCostPrice.Text); } catch (Exception) { base.ClientScript.RegisterStartupScript(base.GetType(), null, "<script>alert('你填写的单价格式有误!');</script>"); return; } // var goodModel = goodsSer.GetModel(goodId); CG_POOrders s = new CG_POOrders(); s.GoodNo = txtGoodNo.Text;// goodModel.GoodNo; s.GoodId = goodId; s.GoodUnit =lblUnit.Text; s.GoodName = txtInvName.Text; s.GoodSpec = lblSpec.Text; s.Good_Model = lblModel.Text; s.GoodTypeSmName = lblGoodSmTypeName.Text; s.CostPrice = Convert.ToDecimal(txtCostPrice.Text); s.DetailRemark = txtDetailRemark.Text; s.InvName = txtInvName.Text; s.Num = Convert.ToDecimal(txtNum.Text); if (txtOtherCost.Text != "") s.OtherCost = Convert.ToDecimal(txtOtherCost.Text); if (txtProfit.Text != "") s.Profit = Convert.ToDecimal(txtProfit.Text); s.SellPrice = Convert.ToDecimal(txtSellPrice.Text); if (txtToTime.Text != "") { s.ToTime = Convert.ToDateTime(txtToTime.Text); } s.CostTotal = s.CostPrice * s.Num; s.SellTotal=s.SellPrice*s.Num; s.YiLiTotal = s.SellTotal - s.CostTotal - s.OtherCost; if (s.SellTotal != 0) s.Profit = s.YiLiTotal / s.SellTotal * 100; else if (s.YiLiTotal != 0) { s.Profit = -100; } else { s.Profit = 0; } //修改 if (Request["index"] != null) { int index = Convert.ToInt32(Request["index"]); //List<CG_POOrders> POOrders = Session["Orders"] as List<CG_POOrders>; CG_POOrders model = ViewState["m"] as CG_POOrders; s.Ids = model.Ids; s.IfUpdate = true; s.UpdateIndex = Convert.ToInt32(Request["index"]); Session["m"] = s; this.ClientScript.RegisterStartupScript(this.GetType(), null, "<script> window.close();</script>"); } else { if (ViewState["Orders"] == null) { List<CG_POOrders> POOrders = new List<CG_POOrders>(); POOrders.Insert(POOrders.Count, s); ViewState["Orders"] = POOrders; } else { List<CG_POOrders> POOrders = ViewState["Orders"] as List<CG_POOrders>; POOrders.Insert(POOrders.Count , s); ViewState["Orders"] = POOrders; } clear(); } // this.ClientScript.RegisterStartupScript(this.GetType(), null, "<script> window.close();</script>"); }