private void dgBOM_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { //更新 string strCount = ((TextBox)e.Item.Cells[2].Controls[1]).Text; if (strCount == "") { Popup("请输入用量"); return; } if (!Regex.IsMatch(strCount, @"^[+|-]{0,1}(\d*)\.{0,1}\d{0,}$")) { Popup("请输入数字"); return; } string strCode = e.Item.Cells[5].Text; DataTable dtbom = null; if (Session["bom"] != null) { dtbom = (DataTable)Session["bom"]; } else { Entity.BillOfMaterials bom = new BillOfMaterials(); dtbom = bom.ToTable().Clone(); } DataRow[] drboms = dtbom.Select("cnvcComponentInvCode='" + strCode + "'"); if (drboms.Length > 0) { drboms[0]["cnnBaseQtyN"] = ((TextBox)e.Item.Cells[2].Controls[1]).Text; } else { DataRow drbom = dtbom.NewRow(); drbom["cnvcComponentInvCode"] = strCode; drbom["cnnBaseQtyN"] = ((TextBox)e.Item.Cells[2].Controls[1]).Text; dtbom.Rows.Add(drbom); } Session["bom"] = dtbom; DataTable dtchild = Session["child"] as DataTable; DataRow[] drchildren = dtchild.Select("cnvcInvCode='" + strCode + "'"); if (drchildren.Length > 0) { drchildren[0]["cnnbaseQtyN"] = ((TextBox)e.Item.Cells[2].Controls[1]).Text; } Session["child"] = dtchild; this.dgBOM.EditItemIndex = -1; BindChild(); }
private void Button1_Click(object sender, System.EventArgs e) { //选择 if (this.DataGrid2.SelectedIndex >= 0) { string strinvcode = this.DataGrid2.SelectedItem.Cells[1].Text; if (strinvcode == "nbsp;") { return; } string strinvname = this.DataGrid2.SelectedItem.Cells[2].Text; string strinvccode = this.DataGrid2.SelectedItem.Cells[3].Text; string strgroupcode = this.DataGrid2.SelectedItem.Cells[20].Text; string stProduceUnitCode = this.DataGrid2.SelectedItem.Cells[25].Text; Entity.Inventory inv = new AMSApp.zhenghua.Entity.Inventory(); inv.cnvcInvCode = strinvcode; inv.cnvcInvName = strinvname; inv.cnvcInvCCode = strinvccode; inv.cnvcGroupCode = strgroupcode; inv.cnvcProduceUnitCode = stProduceUnitCode; if (hidflag.Value == "part") { Session["part"] = inv; string strsql = "select * from tbinventory where cnvcinvcode in (select cnvcComponentInvCode from tbBillOfMaterials where cnvcPartInvcode='" + strinvcode + "')"; DataTable dtchild = Helper.Query(strsql); Session["child"] = dtchild; strsql = "select * from tbBillOfMaterials where cnvcPartInvcode='" + strinvcode + "'"; DataTable dtBOM = Helper.Query(strsql); Entity.BillOfMaterials bom = new BillOfMaterials(dtBOM); Session["BaseQtyD"] = bom.cnnBaseQtyD; Session["bom"] = dtBOM; } if (hidflag.Value == "child") { //子件 if (Session["child"] == null) { Session["child"] = inv.ToTable(); } else { if (Session["part"] != null) { Entity.Inventory invpart = Session["part"] as Entity.Inventory; if (invpart.cnvcInvCode == inv.cnvcInvCode) { this.Popup("母件已选!"); return; } } DataTable dt = Session["child"] as DataTable; DataRow[] drs = dt.Select("cnvcinvcode='" + inv.cnvcInvCode + "'"); if (drs.Length > 0) { this.Popup("子件已选!"); return; } int iColloms = dt.Columns.Count; object[] oArray = new object[iColloms]; inv.ToRow().ItemArray.CopyTo(oArray, 0); dt.Rows.Add(oArray); //dt.Rows.Add(inv.ToRow()); Entity.BillOfMaterials bom = new BillOfMaterials(); bom.cnvcComponentInvCode = inv.cnvcInvCode; if (Session["bom"] == null) { Session["bom"] = bom.ToTable(); } DataTable dtbom = Session["bom"] as DataTable; object[] bomarray = new object[dtbom.Columns.Count]; bom.ToRow().ItemArray.CopyTo(bomarray, 0); dtbom.Rows.Add(bomarray); Session["bom"] = dtbom; Session["child"] = dt; } } } this.Response.Write("<script type=\"text/javascript\">window.close()</script>"); }
public static void UpdateBOM(BillOfMaterials bom, BusiLog bl) { using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(IsolationLevel.ReadCommitted); try { string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); Dept dept = new Dept(); dept.cnvcDeptID = bom.cnvcDeptID; dept = EntityMapping.Get(dept, trans) as Dept; OilStorage os = new OilStorage(); os.cnvcGoodsName = bom.cnvcGoodsName; os.cnvcGoodsType = bom.cnvcGoodsType; os.cnvcDeptID = bom.cnvcDeptID; os = EntityMapping.Get(os, trans) as OilStorage; if (null == os) { throw new BusinessException(bexType.noobject, "库存获取错误"); } Guid gd = Guid.NewGuid(); //判断修改操作类型 改多为出库 改少为入库 //专供油出库 BillOfMaterials oldbom = new BillOfMaterials(); oldbom.cnvcBillNo = bom.cnvcBillNo; oldbom.cnvcDeptID = bom.cnvcDeptID; oldbom = EntityMapping.Get(oldbom, trans) as BillOfMaterials; string strOperType = ""; if (oldbom.cnnCount > bom.cnnCount) { strOperType = InType.BOMModIn; } else { strOperType = InType.BOMModOut; } //验收单 //bom.cnvcInType = strOperType; if (bom.cnnCount != oldbom.cnnCount) { //库存日志 OilStorageLog ol = new OilStorageLog(bom.ToTable()); ol.cndOperDate = dtSysTime; ol.cnvcDeptName = dept.cnvcDeptName; ol.cnvcOperType = strOperType; ol.cnnSerial = gd; ol.cnnLastCount = oldbom.cnnCount; //os.cnnStorageCount; ol.cnnInOutCount = oldbom.cnnCount - bom.cnnCount; //bom.cnnCount-oldbom.cnnCount; ol.cnnCurCount = bom.cnnCount; //os.cnnStorageCount + oldbom.cnnCount - bom.cnnCount; EntityMapping.Create(ol, trans); OilStorageLogHis olhis = new OilStorageLogHis(ol.ToTable()); EntityMapping.Create(olhis, trans); oldbom.SynchronizeModifyValue(bom); oldbom.cnnCount = bom.cnnCount; oldbom.cnnReceiveCount = bom.cnnReceiveCount; oldbom.cnnSpecialFee = bom.cnnSpecialFee; EntityMapping.Update(oldbom, trans); //库存 os.cnnStorageCount = os.cnnStorageCount + ol.cnnInOutCount; //ol.cnnCurCount; EntityMapping.Update(os, trans); } //日志 bl.cnnSerial = gd; bl.cnvcComments = "领料单修改,出入库量:" + (oldbom.cnnCount - bom.cnnCount); bl.cnvcOperType = OperType.OP203; bl.cndOperDate = dtSysTime; bl.cnvcSource = InSource.bs; EntityMapping.Create(bl, trans); trans.Commit(); } catch (BusinessException bex) { trans.Rollback(); LogAdapter.WriteBusinessException(bex); throw bex; } catch (SqlException sex) { trans.Rollback(); LogAdapter.WriteDatabaseException(sex); throw sex; } catch (Exception ex) { trans.Rollback(); LogAdapter.WriteFeaturesException(ex); throw ex; } finally { ConnectionPool.ReturnConnection(conn); } } }