public void btnSave_Click(object sender, EventArgs e) { try { if (!PageValidate.IsNumberTwoDecimal(this.txtMaterialQuantity.Text.Trim())) { ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('数量只能是数字 ')</script>"); return; } if (!PageValidate.IsNumberTwoDecimal(this.txtMaterialUnitPrice.Text.Trim())) { ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('单价只能是数字,且只能有两位小数 ')</script>"); return; } if (!PageValidate.IsNumberTwoDecimal(this.txtMaterialAmount.Text.Trim())) { ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('金额只能是数字,且只能有两位小数 ')</script>"); return; } using (db = new MMSProDBDataContext(ConfigurationManager.ConnectionStrings["mmsConString"].ConnectionString)) { MaterialInfo mi = db.MaterialInfo.SingleOrDefault(u => u.MaterialCode == this.txtMaterialCode.Text.Trim()); if (mi == null) { ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('系统中不存在此物料编码,请先创建!')</script>"); return; } CommitInDetailed SID = new CommitInDetailed(); SID.CommitInID = Convert.ToInt32(Request.QueryString["CommitInID"]); SID.MaterialID = mi.MaterialID; SID.SpecificationModel = this.txtMaterialMod.Text.Trim(); SID.QuantityGentaojian = Convert.ToDecimal(this.txtGTJ.Text.Trim()); SID.QuantityMetre = Convert.ToDecimal(this.txtMetre.Text.Trim()); SID.QuantityTon = Convert.ToDecimal(this.txtTon.Text.Trim()); if (this.ddlUnit.SelectedItem.Text == "--请选择--") { ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('所选单位不能为空')</script>"); return; } SID.CurUnit = this.ddlUnit.SelectedItem.Text; SID.Quantity = Convert.ToDecimal(this.txtMaterialQuantity.Text.Trim()); SID.UnitPrice = Convert.ToDecimal(this.txtMaterialUnitPrice.Text.Trim()); SID.Amount = Convert.ToDecimal(this.txtMaterialAmount.Text.Trim()); if (this.ddlStorage.SelectedIndex == 0) { ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('请选择所属仓库!')</script>"); return; } if (this.ddlPile.SelectedIndex == 0) { ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('请选择所属垛位!')</script>"); return; } SID.PileID = Convert.ToInt32(this.ddlPile.SelectedValue.Trim()); ////财务编码重复 //CommitInDetailed code = db.CommitInDetailed.SingleOrDefault(u => u.financeCode == this.txtMaterialfinance.Text.Trim()); //if (code != null) //{ // ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('财务编码重复!')</script>"); // return; //} SID.financeCode = this.txtMaterialfinance.Text.Trim(); SID.StorageTime = this.DateTimeStorageIn.SelectedDate; if (this.ddlSupplier.SelectedIndex == 0) { ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('请选择供应商!')</script>"); return; } SID.SupplierID = Convert.ToInt32(this.ddlSupplier.SelectedValue.Trim()); if (reEmpId(this.txtWarehouseWorker.Text.Trim()) == 0) { ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('不存在物资管理员,请同步AD账户!')</script>"); return; } if (reEmpId(this.txtManager.Text.Trim()) == 0) { ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('不存在仓库员,请同步AD账户!')</script>"); return; } SID.MaterialsManager = reEmpId(this.txtManager.Text.Trim()); if (reEmpId(this.txtWarehouseWorker.Text.Trim()) == 0) { ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('不存在此资产管理员,请同步AD账户!')</script>"); return; } SID.WarehouseWorker = reEmpId(this.txtWarehouseWorker.Text.Trim()); SID.Remark = this.txtRemark.Text.Trim(); db.CommitInDetailed.InsertOnSubmit(SID); db.SubmitChanges(); if (!string.IsNullOrEmpty(this.txtID.Text.Trim())) { //更新委外关系表 RelationCommitIn rc = new RelationCommitIn(); rc.CommitMaterial = SID.CommitDetailedID; rc.CommitOutMaterial = Convert.ToInt32(this.txtID.Text.Trim()); rc.CreateTime = this.DateTimeStorageIn.SelectedDate; db.RelationCommitIn.InsertOnSubmit(rc); db.SubmitChanges(); } else { ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('委外数据获取异常!')</script>"); return; } //判断是否有任务 if (!string.IsNullOrEmpty(Request.QueryString["TaskStorageID"])) { Response.Redirect("CommitInDetailedManage.aspx?CommitInID=" + Request.QueryString["CommitInID"] + "&&TaskStorageID=" + Request.QueryString["TaskStorageID"] + "&&CommitMid=" + this.txtID.Text.Trim() + ""); } else { Response.Redirect("CommitInDetailedManage.aspx?CommitInID=" + Request.QueryString["CommitInID"] + "&&CommitMid=" + this.txtID.Text.Trim() + ""); } } } catch (Exception ex) { MethodBase mb = MethodBase.GetCurrentMethod(); LogToDBHelper lhelper = LogToDBHelper.Instance; lhelper.WriteLog(ex.Message, "错误", string.Format("{0}.{1}", mb.ReflectedType.Name, mb.Name)); ClientScript.RegisterClientScriptBlock(typeof(string), "提示", string.Format("<script>alert('{0}')</script>", LogToDBHelper.LOG_MSG_INSERTERROR)); } }