private void Button2_Click(object sender, System.EventArgs e) { //生产产品入库 DataTable dtProductSerial = GetProduct(); ArrayList alProductSerial = new ArrayList(); if (dtProductSerial.Rows.Count > 0) { foreach (DataRow dr in dtProductSerial.Rows) { ProductSerial ps = new ProductSerial(dr); ps.cndCreateDate = Convert.ToDateTime(TextBox1.Text); ps.cnvcOperID = oper.strLoginID; ps.cnvcDeptID = ddlDept.SelectedValue; alProductSerial.Add(ps); } OperLog ol = new OperLog(); ol.cnvcDeptID = oper.strDeptID; ol.cnvcOperID = oper.strLoginID; ol.cnvcOperType = "生产产品入库"; ProductFacade pf = new ProductFacade(); pf.AddProductSerial(alProductSerial, ol); this.Popup("生产产品入库成功!"); //清理数据 Session.Remove("tbProductSerial"); BindGrid(); } }
public void AddProductSerial(ArrayList alProductSerial, OperLog operLog) //,BusiLog busiLog) { using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); SerialNo serialNo = new SerialNo(); serialNo.cnvcFill = "0"; serialNo.cnnSerialNo = Convert.ToInt32(EntityMapping.Create(serialNo, trans)); for (int i = 0; i < alProductSerial.Count; i++) { ProductSerial productSerial = (ProductSerial)alProductSerial[i]; productSerial.cndOperDate = dtSysTime; productSerial.cnnSerialNo = serialNo.cnnSerialNo; EntityMapping.Create(productSerial, trans); ProductSerialLog productSerialLog = new ProductSerialLog(productSerial.ToTable()); //productSerialLog.cnnSerialNo = null; productSerialLog.cnnProductSerialNo = serialNo.cnnSerialNo; EntityMapping.Create(productSerialLog, trans); } operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "生产产品入库,生产流水:" + serialNo.cnnSerialNo.ToString(); EntityMapping.Create(operLog, trans); trans.Commit(); } catch (SqlException sex) { trans.Rollback(); LogAdapter.WriteDatabaseException(sex); throw sex; } catch (Exception ex) { trans.Rollback(); LogAdapter.WriteFeaturesException(ex); throw ex; } finally { ConnectionPool.ReturnConnection(conn); } } }
public void AdjustProductSerial_Add(ProductSerial productSerial, OperLog operLog) //,BusiLog busiLog) { using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); ProductSerial oldProductSerial = EntityMapping.Get(productSerial, trans) as ProductSerial; if (oldProductSerial == null) { throw new Exception("未找到对应生产流水的产品!"); } oldProductSerial.cnnAddCount = productSerial.cnnAddCount; oldProductSerial.cnvcOperID = operLog.cnvcOperID; oldProductSerial.cndOperDate = dtSysTime; EntityMapping.Update(oldProductSerial, trans); ProductSerialLog productSerialLog = new ProductSerialLog(oldProductSerial.ToTable()); productSerialLog.cnnProductSerialNo = oldProductSerial.cnnSerialNo; EntityMapping.Create(productSerialLog, trans); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "生产产品调增,生产流水:" + oldProductSerial.cnnSerialNo.ToString() + ",产品编码:" + productSerial.cnvcCode; EntityMapping.Create(operLog, trans); trans.Commit(); } catch (SqlException sex) { trans.Rollback(); LogAdapter.WriteDatabaseException(sex); throw sex; } catch (Exception ex) { trans.Rollback(); LogAdapter.WriteFeaturesException(ex); throw ex; } finally { ConnectionPool.ReturnConnection(conn); } } }
private void MyDataGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { string strSerialNo; // = e.Item.Cells[0].Text; string strGoodsID; // = e.Item.Cells[1].Text; string strCount; // = e.Item.Cells[4].Text; ProductSerial ps; OperLog ol; ProductFacade pf; DataRow[] drs; DataTable dtProduct = GetProduct(); switch (e.CommandName) { case "AdjustAdd": strSerialNo = e.Item.Cells[0].Text; strGoodsID = e.Item.Cells[1].Text; strCount = e.Item.Cells[4].Text; string strAddCount = ((TextBox)e.Item.Cells[5].Controls[1]).Text; if (strAddCount == "") { this.Popup("请输入调增量!"); return; } if (!this.JudgeIsNum(strAddCount)) { this.Popup("请输入数字!"); return; } if (Convert.ToInt32(strAddCount) <= 0) { this.Popup("调增量必须大于零!"); return; } drs = dtProduct.Select("cnvcCode='" + strGoodsID + "' and cnnSerialNo=" + strSerialNo); if (drs.Length > 0) { drs[0]["cnnAddCount"] = strAddCount; drs[0]["cnnSum"] = Convert.ToInt32(strCount) + Convert.ToInt32(strAddCount); } ps = new ProductSerial(); ps.cnnSerialNo = Convert.ToInt32(strSerialNo); ps.cnvcCode = strGoodsID; ps.cnnAddCount = Convert.ToInt32(strAddCount); ol = new OperLog(); ol.cnvcDeptID = oper.strDeptID; ol.cnvcOperID = oper.strLoginID; ol.cnvcOperType = "生产产品调增"; pf = new ProductFacade(); pf.AdjustProductSerial_Add(ps, ol); SetProduct(dtProduct); this.Popup("调增成功!"); BindGrid(); break; case "AdjustReduce": strSerialNo = e.Item.Cells[0].Text; strGoodsID = e.Item.Cells[1].Text; strCount = e.Item.Cells[4].Text; string strReduceCount = ((TextBox)e.Item.Cells[6].Controls[1]).Text; if (strReduceCount == "") { this.Popup("请输入调减量!"); return; } if (!this.JudgeIsNum(strReduceCount)) { this.Popup("请输入数字!"); return; } if (Convert.ToInt32(strReduceCount) <= 0) { this.Popup("调减量必须大于零!"); return; } if (Convert.ToInt32(strCount) - Convert.ToInt32(strReduceCount) <= 0) { this.Popup("调减量必须小于生产量!"); return; } drs = dtProduct.Select("cnvcCode='" + strGoodsID + "' and cnnSerialNo=" + strSerialNo); if (drs.Length > 0) { drs[0]["cnnReduceCount"] = strReduceCount; drs[0]["cnnSum"] = Convert.ToInt32(strCount) - Convert.ToInt32(strReduceCount); } ps = new ProductSerial(); ps.cnnSerialNo = Convert.ToInt32(strSerialNo); ps.cnvcCode = strGoodsID; ps.cnnReduceCount = Convert.ToInt32(strReduceCount); ol = new OperLog(); ol.cnvcDeptID = oper.strDeptID; ol.cnvcOperID = oper.strLoginID; ol.cnvcOperType = "生产产品调减"; pf = new ProductFacade(); pf.AdjustProductSerial_Reduce(ps, ol); SetProduct(dtProduct); this.Popup("调减成功!"); BindGrid(); break; case "Delete": strSerialNo = e.Item.Cells[0].Text; strGoodsID = e.Item.Cells[1].Text; //strCount = e.Item.Cells[4].Text; drs = dtProduct.Select("cnvcCode='" + strGoodsID + "' and cnnSerialNo=" + strSerialNo); if (drs.Length > 0) { dtProduct.Rows.Remove(drs[0]); //drs[0]["cnnCount"] = strCount; } ps = new ProductSerial(); ps.cnnSerialNo = Convert.ToInt32(strSerialNo); ps.cnvcCode = strGoodsID; ol = new OperLog(); ol.cnvcDeptID = oper.strDeptID; ol.cnvcOperID = oper.strLoginID; ol.cnvcOperType = "生产产品删除"; pf = new ProductFacade(); pf.AdjustProductSerial_Delete(ps, ol); SetProduct(dtProduct); this.Popup("生产产品删除成功!"); if ((this.MyDataGrid.CurrentPageIndex == MyDataGrid.PageCount - 1) && MyDataGrid.Items.Count == 1) { if (MyDataGrid.CurrentPageIndex - 1 > 1) { MyDataGrid.CurrentPageIndex = MyDataGrid.CurrentPageIndex - 1; } else { MyDataGrid.CurrentPageIndex = 0; } } BindGrid(); break; } }