| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using CoreFS.CA06;using Pur.Entity;
- using Infragistics.Win.UltraWinGrid;
- using System.Collections;
- using Pur.Entity.require_planEntiy;
- using Core.Mes.Client.Comm.Control;
- using Pur.Entity.ck;
- using com.hnshituo.pur.vo;
- using Core.Mes.Client.Comm.Tool;
- namespace Pur.ck
- {
- public partial class FrmPurOutBill : FrmPmsBase
- {
- private ArrayList checkList;
- public ArrayList CheckList
- {
- get { return checkList; }
- set { checkList = value; }
- }
- public FrmPurOutBill()
- {
- InitializeComponent();
- }
- public FrmPurOutBill(OpeBase ob)
- {
- this.ob = ob;
- InitializeComponent();
- }
-
- private void FrmPurOutBill_Load(object sender, EventArgs e)
- {
- Init();
- }
- #region toolbar
- private void barsManagerButon_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
- {
- switch (e.Tool.Key)
- {
- case "createBill": // ButtonTool
- createBill();
- break;
- case "clear": // ButtonTool
- clear();
- break;
- case "关闭": // ButtonTool
- this.Close();
- break;
- }
- }
- #endregion
- #region toolbar事件
- private void clear()
- {
- String strItemCode = ultraGrid1.ActiveRow.Cells["itemCode"].Value.ToString().Trim();
- String strItemAttrCode = ultraGrid1.ActiveRow.Cells["itemAttrId"].Value.ToString().Trim();
- if (String.IsNullOrEmpty(strItemCode))
- {
- MessageBox.Show("查询库存信息失败:没有获取到物料编码", "提示");
- return;
- }
- foreach (UltraGridRow row in ultraGrid2.Rows)
- {
- if (row.Cells["itemCode"].Value.ToString().Trim().Equals(strItemCode) && row.Cells["itemAttrId"].Value.ToString().Trim().Equals(strItemAttrCode))
- {
- row.Cells["isSelect"].Value = false;
- row.Cells["createQty"].Value = 0;
- }
- }
- }
- private void createBill()
- {
- try
- {
- ultraGrid1.UpdateData();
- ultraGrid2.UpdateData();
- foreach (UltraGridRow rowm in ultraGrid1.Rows)
- {
- String stritemcode=rowm.Cells["itemCode"].Value.ToString().Trim();
- String strItemAttrCode = ultraGrid1.ActiveRow.Cells["itemAttrId"].Value.ToString().Trim();
- int j = 0;
- foreach (UltraGridRow row in ultraGrid2.Rows)
- {
- if (row.Cells["itemCode"].Value.ToString().Trim().Equals(stritemcode) && row.Cells["itemAttrId"].Value.ToString().Trim().Equals(strItemAttrCode) && Convert.ToBoolean(row.Cells["isSelect"].Value) == true)
- {
- j = j + 1;
- if (Convert.ToDouble(row.Cells["createQty"].Value) <= 0)
- {
- String strinvno = row.Cells["invId"].Value.ToString().Trim();
- MessageBox.Show(strinvno+"未编制有效数量","提示");
- return;
- }
- Double inStock;//在库
- if(row.Cells["invQty"].Value==null)
- {
- inStock=0;
- }
- else
- {
- inStock=Convert.ToDouble(row.Cells["invOrigQty"].Value);
- }
-
- Double onTrip;//在途
- if(row.Cells["invQty"].Value==null)
- {
- onTrip=0;
- }
- else{
- onTrip=Convert.ToDouble(row.Cells["invQty"].Value);
- }
-
- Double orQty;//已预约
- if(row.Cells["invOrQty"].Value==null)
- {
- orQty=0;
- }
- else
- {
- orQty=Convert.ToDouble(row.Cells["invOrQty"].Value);
- }
- //校验输入量:不能大于原始量+在途量-已经预约的量
- Double canUsed = inStock + onTrip - orQty;
- if(Convert.ToDouble(row.Cells["createQty"].Value)>canUsed)
- {
- String strinvno = row.Cells["invId"].Value.ToString().Trim();
- MessageBox.Show("库存行【"+ strinvno + "】的编制数量不能大于可编制的最大量:" + canUsed + "(即在库库存+在途库存-已预约量)", "提示");
- return;
- }
- }
- }
- if (j == 0)
- {
- MessageBox.Show("物料【"+stritemcode+"】的领用计划未编制库存数据", "提示");
- return;
- }
- }
- ultraGrid1.UpdateData();
- if (MessageUtil.ShowYesNoAndQuestion("确定进行出库操作?") != DialogResult.Yes)
- {
- return;
- }
- foreach (UltraGridRow rowm in ultraGrid1.Rows)
- {
- String stritemcode = rowm.Cells["itemCode"].Value.ToString().Trim();
- String strItemAttrCode = rowm.Cells["itemAttrId"].Value.ToString().Trim();
- //获取领用明细的信息,用于生成送货单主记录
- String strMrLineId = rowm.Cells["mrLineId"].Value.ToString().Trim();
- String strMrId = rowm.Cells["mrId"].Value.ToString().Trim();
- UsePlanD Upd = this.execute<UsePlanD>("com.hnshituo.pur.requireplan.service.UsePlanDService", "findById", new object[] { strMrLineId });
- UsePlanM UpM = this.execute<UsePlanM>("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { strMrId });
- //获取库存记录信息用于生成出库单详细信息
- //CkOutBill cb = EntityHelper.CopyEntity<CkOutBill>(Upd);
- CkOutBill cb = new CkOutBill();
- cb.OutstockType="1";
- cb.Status="1";
- cb.MrLineId = Upd.MrLineId;
- cb.ItemCode = Upd.ItemCode;
- cb.ItemDesc = Upd.ItemDesc;
- cb.ItemDescE = Upd.ItemDescE;
- cb.ItemModel = Upd.ItemModel;
- cb.ItemName = Upd.ItemName;
- cb.ItemSpec = Upd.ItemSpec;
- cb.ItemUom = Upd.ItemUom;
- cb.ItemUomConefficient = Upd.ItemUomConefficient;
- cb.ItemUseUom = Upd.ItemUseUom;
- cb.WeightUnit = Upd.WeightUnit;
- cb.ItemAttr = Upd.ItemAttr;//物料属性
- cb.ItemAttrId = Upd.ItemAttrId;//物料属性Id
- cb.CostCenter = Upd.CostCenter;
- cb.ExpenseType = Upd.ExpenseType;
- cb.ApplyDate = UpM.ApplyTime;
- cb.ApplyUserid = UpM.ApplyReqOrgId;
- cb.ApplyUsername = UpM.ApplyReqOrgName;
- cb.CreateName = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName();
- cb.CreateTime = DateTime.Now;
- cb.CreateUserid = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID();
- //System.Guid outStockNo = System.Guid.NewGuid().ToString();
- // String outStockNo = System.Guid.NewGuid().ToString();
- CoreResult reid = this.execute<CoreResult>("com.hnshituo.pur.ck.service.CkOutBillService", "createId", new object[] { });
- if (reid.Resultcode == 0)
- {
- cb.OutStockNo = reid.Resultmsg;
- }
- else
- {
- MessageBox.Show("操作失败:生成主表ID失败," + reid.Resultmsg, "提示");
- return;
- }
-
- cb.Validflag = "1";
- //生成出库单号
- //插入出库表 和 更新领用计划主表
- CoreResult re = this.execute<CoreResult>("com.hnshituo.pur.ck.service.CkOutBillService", "doInsert_Update", new object[] { cb });
- if (re.Resultcode != 0)
- {
- MessageBox.Show("操作失败:"+re.Resultmsg, "提示");
- return;
- }
- //循环库存明细,生成出库库位明细从表
- ultraGrid2.UpdateData();
- int i = 0;
- foreach (UltraGridRow row in ultraGrid2.Rows)
- {
- if (row.Cells["itemCode"].Value.ToString().Trim().Equals(stritemcode) && row.Cells["itemAttrId"].Value.ToString().Trim().Equals(strItemAttrCode) && Convert.ToBoolean(row.Cells["isSelect"].Value) == true && Convert.ToDouble(row.Cells["createQty"].Value) > 0)
- {
- i = i + 1;
- //收集数据进行插入
- CkOutbillPosition cp = new CkOutbillPosition();
- cp.OutStockNo = cb.OutStockNo;
- cp.SeqId = i + "";
- //cp.Id = Guid.NewGuid().ToString();
- CoreResult reid1 = this.execute<CoreResult>("com.hnshituo.pur.ck.service.CkOutbillPositionService", "createId", new object[] { cb.OutStockNo });
- if (reid1.Resultcode == 0)
- {
- cp.Id = reid1.Resultmsg;
- }
- else
- {
- MessageBox.Show("操作失败:生成明细ID失败," + reid1.Resultmsg, "提示");
- return;
- }
- cp.InvId = row.Cells["invid"].Value.ToString().Trim();
- cp.OutNum = Convert.ToDouble(row.Cells["createQty"].Value);
- cp.Validflag = "1";
- cp.CreateName = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName();
- cp.CreateTime = DateTime.Now;
- cp.CreateUserid = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID();
- cp.OrderId = row.Cells["orderId"].Value.ToString().Trim();
- cp.OrderLineSqe = row.Cells["orderLineSqe"].Value.ToString().Trim();
- cp.SuppCode = row.Cells["suppCode"].Value.ToString().Trim();
- cp.SuppName = row.Cells["suppName"].Value.ToString().Trim();
- cp.InvLogic = row.Cells["invLogic"].Value.ToString().Trim();
- cp.InvPhysic = row.Cells["invPhysic"].Value.ToString().Trim();
- cp.InvPos = row.Cells["invBin"].Value.ToString().Trim();
- //cp.BatchNo = row.Cells["batchno"].Value.ToString().Trim();
- cp.BatchNo = "";
- cp.WeightUnit = row.Cells["weightUnit"].Value.ToString().Trim();
- CoreResult re1 = this.execute<CoreResult>("com.hnshituo.pur.ck.service.CkOutbillPositionService", "doInsert_Update", new object[] { cp });
- if (re1.Resultcode == 1)
- {
- MessageBox.Show("操作失败:" + re1.Resultmsg, "");
- return;
- }
- //更新库存记录+领用计划表详细表
- }
- }
- ////删除已生成的记录
- ////DataRow roww= dataTable2.Select("mrLineId=strMrLineId");
- // //DataTable.Rows.Remove(roww);
- //for (int k = dataTable2.Rows.Count - 1; k >= 0; k--)
- //{
- // if (dataTable2.Rows[k]["mrLineId"].ToString().Equals(strMrLineId))
- // dataTable2.Rows.RemoveAt(k);
- //}
- //if (dataTable2.Rows.Count == 0)
- //{
- // MessageBox.Show("已经编制完成,请确定","提示");
- // this.Close();
- //}
- }
- MessageBox.Show("已经编制完成,请确定", "提示");
- this.Close();
- }
- catch(Exception ex)
- {
- MessageBox.Show("生成失败:"+ex.Message,"提示");
- }
- }
- #endregion
- #region 界面事件
- private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
- {
- String strItemCode = ultraGrid1.ActiveRow.Cells["itemCode"].Value.ToString().Trim();
- String strItemAttrCode = ultraGrid1.ActiveRow.Cells["itemAttrId"].Value.ToString().Trim();
- if (String.IsNullOrEmpty(strItemCode))
- {
- MessageBox.Show("查询库存信息失败:没有获取到物料编码","提示");
- return;
- }
- //ultraGrid2.UpdateData();
- foreach (UltraGridRow rowd in ultraGrid2.Rows)
- {
- if (rowd.Cells["itemCode"].Value.ToString().Trim().Equals(strItemCode) && rowd.Cells["itemAttrId"].Value.ToString().Trim().Equals(strItemAttrCode))
- {
- rowd.Hidden = false;
- }
- else
- {
- rowd.Hidden=true;
- }
-
- }
- }
- #endregion
- #region 初始化
- private void Init()
- {
- try
- {
- dataTable2.Clear();
- dataTable1.Clear();
- foreach (object o in checkList)
- {
- //加载领用计划明细
- UsePlanD Upd = new UsePlanD();
- Upd.Validflag = "1";
- Upd.MrLineId = o.ToString().Trim();
- DataTable dt = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.UsePlanDService", "find_UsePlanD", new object[] { Upd });
- dataTable2.ImportRow(dt.Rows[0]);
- //加载库存信息
- String strItemCode = dt.Rows[0]["itemCode"].ToString().Trim();
- String strItemAttrCode = dt.Rows[0]["itemAttrId"].ToString().Trim();
- if (String.IsNullOrEmpty(strItemCode))
- {
- MessageBox.Show("查询库存信息失败:没有获取到物料编码", "提示");
- return;
- }
- CkStorage CkSto = new CkStorage();
- CkSto.ItemCode = strItemCode;
- CkSto.ItemAttrId = strItemAttrCode;
- DataTable dt1 = this.execute<DataTable>("com.hnshituo.pur.ck.service.CkStorageService", "find_Storage", new object[] { CkSto });
- //dataTable1.ImportRow(dt1.Rows[0]);
- foreach (DataRow rowf in dt1.Rows)
- {
- dataTable1.ImportRow(rowf);
- }
- }
- //GridHelper.CopyDataToDatatable(dtall, dataTable1, true);
- ultraGrid1.UpdateData();
- ultraGrid2.UpdateData();
- foreach (UltraGridRow rowd in ultraGrid2.Rows)
- {
- rowd.Hidden = true;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("界面初始化加载数据失败:" + ex.Message, "提示");
- }
- }
- #endregion
- }
- }
|