//保存数据到线上库 private StockOnline StorageToOnLine(GridViewRow gvr) { StockOnline sol = new StockOnline(); sol.StorageInType = "回收入库"; sol.BatchIndex = "N/A"; sol.MaterialCode = gvr.Cells[4].Text; sol.QuantityGentaojian = Convert.ToDecimal(gvr.Cells[8].Text); sol.QuantityMetre = Convert.ToDecimal(gvr.Cells[9].Text); sol.QuantityTon = Convert.ToDecimal(gvr.Cells[10].Text); sol.UnitPrice = Convert.ToDecimal(gvr.Cells[11].Text); sol.CurUnit = gvr.Cells[12].Text; sol.Amount = sol.UnitPrice * Convert.ToDecimal(gvr.Cells[GetPricingIndex(sol.CurUnit)].Text); sol.StorageTime = Convert.ToDateTime(gvr.Cells[13].Text); sol.Remark = (gvr.Cells[15].Controls[0] as TextBox).Text.Trim(); sol.ExpectedProject = projectid; sol.StorageID = Convert.ToInt32(gvr.Cells[17].Text); sol.PileID = Convert.ToInt32(gvr.Cells[18].Text); sol.ManufacturerID = Convert.ToInt32(gvr.Cells[19].Text); sol.MaterialID = Convert.ToInt32(gvr.Cells[20].Text); return(sol); }
void btnOK_Click(object sender, EventArgs e) { try { using (MMSProDBDataContext db = new MMSProDBDataContext(ConfigurationManager.ConnectionStrings["mmsConString"].ConnectionString)) { //decimal count = 0; decimal countcell = 0; for (int a = 0; a < this.gv.Rows.Count; a++) { //switch (this.gv.Rows[a].Cells[6].Text.Trim()) //{ // case "根/台/套/件": // count += Convert.ToDecimal(this.gv.Rows[a].Cells[2].Text.Trim()); // break; // case "米": // count += Convert.ToDecimal(this.gv.Rows[a].Cells[3].Text.Trim()); // break; // case "吨": // count += Convert.ToDecimal(this.gv.Rows[a].Cells[4].Text.Trim()); // break; //} countcell += Convert.ToDecimal((this.gv.Rows[a].Cells[5].Controls[0] as TextBox).Text.Trim()); } if (countcell > _quantity) { lblout.Visible = true; lblout.Text = "默认填写物资数量为:" + countcell + ",已超出待转线上数值,请修改!"; return; } #region modify by adonis 2011-2-15 //写入线上库存 StockOnline so = new StockOnline(); so.OrderNum = MaterialOnLine.TempDataEdit.OrderNum; so.OnlineCode = MaterialOnLine.TempDataEdit.OnlineCode; so.OnlineDate = MaterialOnLine.TempDataEdit.OnlineDate; so.CertificateNum = MaterialOnLine.TempDataEdit.CertificateNum; so.OnlineUnit = MaterialOnLine.TempDataEdit.OnlineUnit; so.CurQuantity = MaterialOnLine.TempDataEdit.CurQuantity; so.OnlineTotal = MaterialOnLine.TempDataEdit.OnlineTotal; so.StorageInID = MaterialOnLine.TempDataEdit.StorageInID; so.StorageInType = MaterialOnLine.TempDataEdit.StorageInType; so.ReceivingTypeName = MaterialOnLine.TempDataEdit.ReceivingTypeName; so.StorageInCode = MaterialOnLine.TempDataEdit.StorageInCode; so.BillCode = MaterialOnLine.TempDataEdit.BillCode; so.MaterialID = MaterialOnLine.TempDataEdit.MaterialID; so.MaterialCode = "N/A"; so.QuantityGentaojian = MaterialOnLine.TempDataEdit.OnlineTotal; so.QuantityMetre = MaterialOnLine.TempDataEdit.OnlineTotal; so.QuantityTon = MaterialOnLine.TempDataEdit.OnlineTotal; so.OfflineGentaojian -= MaterialOnLine.TempDataEdit.QuantityGentaojian; so.OfflineMetre -= MaterialOnLine.TempDataEdit.QuantityMetre; so.OfflineTon -= MaterialOnLine.TempDataEdit.QuantityTon; so.CurUnit = MaterialOnLine.TempDataEdit.CurUnit; so.UnitPrice = MaterialOnLine.TempDataEdit.UnitPrice; so.Amount = MaterialOnLine.TempDataEdit.Amount; so.ExpectedProject = MaterialOnLine.TempDataEdit.ExpectedProject; so.Remark = MaterialOnLine.TempDataEdit.Remark; so.BatchIndex = MaterialOnLine.TempDataEdit.BatchIndex; so.ManufacturerID = MaterialOnLine.TempDataEdit.ManufacturerID; so.SupplierID = MaterialOnLine.TempDataEdit.SupplierID; so.StorageID = MaterialOnLine.TempDataEdit.StorageID; so.PileID = MaterialOnLine.TempDataEdit.PileID; so.MaterialsManager = MaterialOnLine.TempDataEdit.MaterialsManager; so.AssetsManager = MaterialOnLine.TempDataEdit.AssetsManager; so.StorageTime = MaterialOnLine.TempDataEdit.StorageTime; so.OnlineUnitPrice = MaterialOnLine.TempDataEdit.OnlineUnitPrice; so.Creator = MaterialOnLine.TempDataEdit.Creator; var SaveTime = db.ExecuteQuery <DateTime>("select getdate()", new object[] { }); so.CreateTime = SaveTime.First(); db.StockOnline.InsertOnSubmit(so); //修改库存表线上状态 TableOfStocks to = db.TableOfStocks.SingleOrDefault(u => u.StocksID == MaterialOnLine.TempDataEdit.iSocksID); //转线上后,库存剩余数量 switch (so.OnlineUnit) { case "根/台/套/件": to.QuantityGentaojian -= so.CurQuantity; break; case "米": to.QuantityMetre -= so.CurQuantity; break; case "吨": to.QuantityTon -= so.CurQuantity; break; } //so.QuantityGentaojian = to. //修改库存表对应单位数量 to.QuantityGentaojian -= so.QuantityGentaojian; to.QuantityMetre -= so.QuantityMetre; to.QuantityTon -= so.QuantityTon; #endregion for (int i = 0; i < this.gv.Rows.Count; i++) { FlowDetailsOffline fdo = new FlowDetailsOffline(); fdo.TableOfStocksID = Convert.ToInt32(this.gv.Rows[i].Cells[this.gv.Columns.Count - 1].Text.Trim()); fdo.StorageType = this.gv.Rows[i].Cells[7].Text.Trim(); fdo.StorageOutCode = this.gv.Rows[i].Cells[0].Text.Trim(); fdo.StorageOutProject = Convert.ToInt32(this.gv.Rows[i].Cells[this.gv.Columns.Count - 2].Text.Trim()); //fdo.CurUnit = this.gv.Rows[i].Cells[6].Text.Trim(); TextBox tboxCurQuantity = (TextBox)this.gv.Rows[i].Cells[5].Controls[0]; fdo.CurQuantity = Convert.ToDecimal(tboxCurQuantity.Text.Trim()); TextBox Curunit = (TextBox)this.gv.Rows[i].Cells[6].Controls[0]; fdo.CurUnit = Curunit.Text.Trim(); fdo.RealGentaojian = Convert.ToDecimal(this.gv.Rows[i].Cells[2].Text.Trim()); fdo.RealMetre = Convert.ToDecimal(this.gv.Rows[i].Cells[3].Text.Trim()); fdo.RealTon = Convert.ToDecimal(this.gv.Rows[i].Cells[4].Text.Trim()); fdo.Creator = db.EmpInfo.SingleOrDefault(u => u.Account == SPContext.Current.Web.CurrentUser.LoginName).EmpID; var SevTime = db.ExecuteQuery <DateTime>("select getdate()", new object[] { }); fdo.CreateTime = SevTime.First(); db.FlowDetailsOffline.InsertOnSubmit(fdo); db.SubmitChanges(); } //解开静态类锁 MaterialOnLine.TempDataEdit.locked = false; } Response.Redirect("MaterialOnLineManage.aspx", false); } 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)); } //写入物资追踪表 }
void btnOK_Click(object sender, EventArgs e) { try { //将确认结果保存到数据库 using (MMSProDBDataContext db = new MMSProDBDataContext(ConfigurationManager.ConnectionStrings["mmsConString"].ConnectionString)) { int empid = db.EmpInfo.SingleOrDefault(u => u.Account == SPContext.Current.Web.CurrentUser.LoginName).EmpID; foreach (GridViewRow gvr in spgvMaterial.Rows) { if (bWriteOff) { switch (gvr.Cells[16].Text) { case "线上": StockOnline sol = StorageToOnLine(gvr); sol.CreateTime = db.ExecuteQuery <DateTime>("select getdate()", new object[] { }).First(); sol.Creator = empid; db.StockOnline.InsertOnSubmit(sol); break; case "线下": TableOfStocks tos = StorageToOffLine(gvr); tos.CreateTime = db.ExecuteQuery <DateTime>("select getdate()", new object[] { }).First(); tos.Creator = empid; db.TableOfStocks.InsertOnSubmit(tos); break; case "回收合格": QualifiedStocks qfs = StorageToQualified(gvr); qfs.CreateTime = db.ExecuteQuery <DateTime>("select getdate()", new object[] { }).First(); qfs.Creator = empid; db.QualifiedStocks.InsertOnSubmit(qfs); break; } } else { QualifiedStocks qs = new QualifiedStocks(); qs.Gentaojian = Convert.ToDecimal(gvr.Cells[4].Text); qs.Metre = Convert.ToDecimal(gvr.Cells[5].Text); qs.Ton = Convert.ToDecimal(gvr.Cells[6].Text); qs.UnitPrice = Convert.ToDecimal(gvr.Cells[7].Text); qs.CurUnit = gvr.Cells[8].Text; qs.Amount = qs.UnitPrice * Convert.ToDecimal(gvr.Cells[GetPricingIndex(qs.CurUnit)].Text); qs.StorageTime = Convert.ToDateTime(gvr.Cells[9].Text); qs.RetrieveTime = Convert.ToDateTime(gvr.Cells[10].Text); qs.Remark = (gvr.Cells[11].Controls[0] as TextBox).Text.Trim(); qs.StorageID = Convert.ToInt32(gvr.Cells[13].Text); qs.PileID = Convert.ToInt32(gvr.Cells[14].Text); qs.ManufactureID = Convert.ToInt32(gvr.Cells[15].Text); qs.MaterialID = Convert.ToInt32(gvr.Cells[16].Text); qs.RetrieveProjectID = projectid; qs.CreateTime = db.ExecuteQuery <DateTime>("select getdate()", new object[] { }).First(); qs.Creator = db.EmpInfo.SingleOrDefault(u => u.Account == SPContext.Current.Web.CurrentUser.LoginName).EmpID; db.QualifiedStocks.InsertOnSubmit(qs); } } //结束当前任务 db.TaskStorageIn.SingleOrDefault(u => u.TaskStorageID.Equals(_taskid)).TaskState = "已完成"; db.SubmitChanges(); } Response.Redirect("../../default-old.aspx", false); } 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)); } }
void btnOK_Click(object sender, EventArgs e) { try { //将审核结果保存到数据库 using (MMSProDBDataContext db = new MMSProDBDataContext(ConfigurationManager.ConnectionStrings["mmsConString"].ConnectionString)) { _taskid = Convert.ToInt32(Request.QueryString["StockTransferTaskID"]); StockTransferTask st1 = db.StockTransferTask.SingleOrDefault(a => a.StockTransferTaskID == _taskid); //页面已处理完毕就直接跳转到发送任务界面 if (((Panel)GetControltByMaster("PanelDone")).Visible == true) { Response.Redirect("StockTransferCreateTask.aspx?StockTransferID=" + st1.StockTransferID + "&&TaskType=生产组长审核信息&&BackUrl=" + HttpContext.Current.Request.Url.PathAndQuery); } if (this.chbAgree.Checked) { //通過 //验证是否都有内容 _taskid = Convert.ToInt32(Request.QueryString["StockTransferTaskID"]); StockTransferTask st = db.StockTransferTask.SingleOrDefault(a => a.StockTransferTaskID == _taskid); st.AcceptTime = db.ExecuteQuery <DateTime>("select getdate()", new object[] { }).First(); st.AuditOpinion = this.txtOpinion.Text.Trim(); st.AuditStatus = "审核通过"; st.TaskState = "已完成"; //db.SubmitChanges(); var all = from a in db.StockTransferDetail where a.StockTransferID == st.StockTransferID select a; bool done = true; foreach (var single in all) { switch (single.StocksStatus) { case "线上": #region 改线上 var ul = db.StockOnline.SingleOrDefault(a => a.StockOnlineID == single.StocksID); decimal gen, meter, ton; gen = decimal.Parse((ul.QuantityGentaojian - single.QuantityGentaojian).ToString()); meter = decimal.Parse((ul.QuantityMetre - single.QuantityMetre).ToString()); ton = decimal.Parse((ul.QuantityTon - single.QuantityTon).ToString()); if (gen < 0 || meter < 0 || ton < 0) { done = false; } //创建新纪录//修改原纪录 StockOnline so = new StockOnline(); so.Amount = ul.Amount; so.AssetsManager = ul.AssetsManager; so.BatchIndex = ul.BatchIndex; so.BillCode = ul.BillCode; so.CurUnit = ul.CurUnit; so.ExpectedProject = ul.ExpectedProject; so.ManufacturerID = ul.ManufacturerID; so.MaterialCode = ul.MaterialCode; so.MaterialID = ul.MaterialID; so.MaterialsManager = ul.MaterialsManager; so.OfflineGentaojian = ul.OfflineGentaojian; so.OfflineMetre = ul.OfflineMetre; so.OfflineTon = ul.OfflineTon; so.ReceivingTypeName = ul.ReceivingTypeName; so.Remark = ul.Remark; so.StorageInCode = ul.StorageInCode; so.StorageInID = ul.StorageInID; so.StorageInType = ul.StorageInType; so.StorageTime = ul.StorageTime; so.SupplierID = ul.SupplierID; so.UnitPrice = ul.UnitPrice; so.CertificateNum = ul.CertificateNum; so.CreateTime = DateTime.Now; so.Creator = ul.Creator; switch (ul.OnlineUnit) { case "根/台/套/件": so.CurQuantity = single.QuantityGentaojian; ul.CurQuantity = gen; // so.OnlineTotal = gen * ul.OnlineUnitPrice; break; case "米": so.CurQuantity = single.QuantityMetre; ul.CurQuantity = meter; break; case "吨": so.CurQuantity = single.QuantityTon; ul.CurQuantity = ton; break; } so.OnlineCode = ul.OnlineCode; so.OnlineDate = ul.OnlineDate; so.OnlineTotal = so.CurQuantity * ul.OnlineUnitPrice; ul.OnlineTotal = ul.CurQuantity * ul.OnlineUnitPrice; so.OnlineUnit = ul.OnlineUnit; so.OnlineUnitPrice = ul.OnlineUnitPrice; so.OrderNum = ul.OrderNum; so.QuantityGentaojian = single.QuantityGentaojian; ul.QuantityGentaojian = gen; so.QuantityMetre = single.QuantityMetre; ul.QuantityMetre = meter; so.QuantityTon = single.QuantityTon; ul.QuantityTon = ton; // so.TableOfStocksID = ul.TableOfStocksID; so.PileID = single.TargetPile; db.StockOnline.InsertOnSubmit(so); #endregion break; case "线下": #region 改线下 var un = db.TableOfStocks.SingleOrDefault(a => a.StocksID == single.StocksID); gen = decimal.Parse((un.QuantityGentaojian - single.QuantityGentaojian).ToString()); meter = decimal.Parse((un.QuantityMetre - single.QuantityMetre).ToString()); ton = decimal.Parse((un.QuantityTon - single.QuantityTon).ToString()); if (gen < 0 || meter < 0 || ton < 0) { done = false; } //创建新纪录//修改原纪录 TableOfStocks tos = new TableOfStocks(); tos.AssetsManager = un.AssetsManager; tos.BatchIndex = un.BatchIndex; tos.BillCode = un.BillCode; tos.CreateTime = DateTime.Now; tos.Creator = un.Creator; tos.CurUnit = un.CurUnit; tos.ExpectedProject = un.ExpectedProject; tos.ManufacturerID = un.ManufacturerID; tos.MaterialCode = un.MaterialCode; tos.MaterialID = un.MaterialID; tos.MaterialsManager = un.MaterialsManager; tos.PileID = single.TargetPile; tos.QuantityGentaojian = single.QuantityGentaojian; un.QuantityGentaojian = gen; tos.QuantityMetre = single.QuantityMetre; un.QuantityMetre = meter; tos.QuantityTon = single.QuantityTon; un.QuantityTon = ton; tos.ReceivingTypeName = un.ReceivingTypeName; tos.Remark = un.Remark; tos.StorageID = single.PileInfo.StorageInfo.StorageID; tos.StorageInCode = un.StorageInCode; tos.StorageInID = un.StorageInID; tos.StorageInType = un.StorageInType; tos.StorageTime = un.StorageTime; tos.SupplierID = un.SupplierID; tos.UnitPrice = un.UnitPrice; switch (tos.CurUnit) { case "根/台/套/件": tos.Amount = decimal.Parse(tos.QuantityGentaojian.ToString()) * tos.UnitPrice; un.Amount = gen * un.UnitPrice; // so.OnlineTotal = gen * ul.OnlineUnitPrice; break; case "米": tos.Amount = decimal.Parse(tos.QuantityMetre.ToString()) * tos.UnitPrice; un.Amount = meter * un.UnitPrice; break; case "吨": tos.Amount = decimal.Parse(tos.QuantityTon.ToString()) * tos.UnitPrice; un.Amount = ton * un.UnitPrice; break; } db.TableOfStocks.InsertOnSubmit(tos); #endregion break; case "回收合格": #region 回收 var ur = db.QualifiedStocks.SingleOrDefault(a => a.StocksID == single.StocksID); gen = decimal.Parse((ur.Gentaojian - single.QuantityGentaojian).ToString()); meter = decimal.Parse((ur.Metre - single.QuantityMetre).ToString()); ton = decimal.Parse((ur.Ton - single.QuantityTon).ToString()); if (gen < 0 || meter < 0 || ton < 0) { done = false; } //创建新纪录//修改原纪录 QualifiedStocks qs = new QualifiedStocks(); qs.CurUnit = ur.CurUnit; qs.ManufactureID = ur.ManufactureID; qs.MaterialID = ur.MaterialID; qs.PileID = single.TargetPile; qs.Remark = ur.Remark; qs.RetrieveProjectID = ur.RetrieveProjectID; qs.RetrieveTime = ur.RetrieveTime; qs.StorageID = single.PileInfo.StorageInfo.StorageID; qs.StorageTime = ur.StorageTime; qs.UnitPrice = ur.UnitPrice; qs.Gentaojian = decimal.Parse(single.QuantityGentaojian.ToString()); ur.Gentaojian = gen; qs.Metre = decimal.Parse(single.QuantityMetre.ToString()); ur.Metre = meter; qs.Ton = decimal.Parse(single.QuantityTon.ToString()); ur.Ton = ton; switch (qs.CurUnit) { case "根/台/套/件": qs.Amount = decimal.Parse(qs.Gentaojian.ToString()) * qs.UnitPrice; ur.Amount = gen * ur.UnitPrice; // so.OnlineTotal = gen * ul.OnlineUnitPrice; break; case "米": qs.Amount = decimal.Parse(qs.Metre.ToString()) * qs.UnitPrice; ur.Amount = meter * ur.UnitPrice; break; case "吨": qs.Amount = decimal.Parse(qs.Ton.ToString()) * qs.UnitPrice; ur.Amount = ton * ur.UnitPrice; break; } db.QualifiedStocks.InsertOnSubmit(qs); #endregion break; } if (!done) { break; } } if (done) { db.SubmitChanges(); } else { ClientScript.RegisterClientScriptBlock(typeof(string), "提示", string.Format("<script>alert('{0}')</script>", "移动数目超过库存数,请检查数据!")); } //Response.Redirect("StockTransferCreateTask.aspx?StockTransferID=" + st.StockTransferID + "&&TaskType=生产组长审核信息&&BackUrl=" + HttpContext.Current.Request.Url.PathAndQuery); } else { //未通過 //通過 //验证是否都有内容 _taskid = Convert.ToInt32(Request.QueryString["StockTransferTaskID"]); StockTransferTask st = db.StockTransferTask.SingleOrDefault(a => a.StockTransferTaskID == _taskid); st.AcceptTime = db.ExecuteQuery <DateTime>("select getdate()", new object[] { }).First(); st.AuditOpinion = this.txtOpinion.Text.Trim(); st.AuditStatus = "审核未通过"; st.TaskState = "已完成"; //写入新的内容 StockTransferTask stt = new StockTransferTask(); stt.Remark = this.txtOpinion.Text.Trim(); stt.StockTransferID = st.StockTransferID; stt.TaskCreaterID = st.TaskTargetID; stt.TaskInType = "移库任务"; stt.TaskState = "未完成"; stt.TaskTargetID = st.TaskCreaterID; stt.TaskTitle = st.TaskTitle + "[审核未通过]"; stt.TaskType = "发起人修改"; stt.CreateTime = db.ExecuteQuery <DateTime>("select getdate()", new object[] { }).First(); db.StockTransferTask.InsertOnSubmit(stt); db.SubmitChanges(); } } Response.Redirect("../../default-old.aspx", false); } 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)); } }