using com.hnshituo.pur.vo; using CoreFS.CA06; using Infragistics.Win.UltraWinEditors; using Infragistics.Win.UltraWinGrid; using Pur.Entity.configureEntity; using Pur.Entity.require_planEntiy; using Pur.require_plan; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Pur.PublicTools; using Pur.configure; using Pur.Pop_upWindow; using Pur.Entity; using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Tool; namespace Pur.ck { public partial class frmUsePlanYB : FrmPmsBase { DataTable Qdt = null;//库区 private string req_org_id = ""; public frmUsePlanYB() { InitializeComponent(); } private void frmUsePlanYB_Load(object sender, EventArgs e) { ck_attr.Checked = true; ck_Uom.Checked = true; ck_standard.Checked = true; txt_status.SelectedIndex = 1; ck_ctime.Checked = true; txtCreateTimeStart.Value = DateTime.Now.AddMonths(-1); txtCreateTimeEnd.Value = DateTime.Now.AddDays(2); GridHelper.SetColumnsActive(ultraGrid1.DisplayLayout.Bands[0]); GridHelper.SetColumnsActive(ultraGrid2.DisplayLayout.Bands[0]); GridHelper.SetExcludeColumnsActive(ultraGrid3.DisplayLayout.Bands[0], new String[] { "Check", "OUTNUM", "OUTNUM1" }); GridHelper.SetExcludeColumnsActive(ultraGrid4.DisplayLayout.Bands[0], new String[] { "Check" }); } #region toolbar工具栏 public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": getUserPlanM(""); break; case "doReceive": receiveUserPlanM(); break; case "dofinish": finishUserPlanM(); break; case "doReturn": returnUserPlanM(); break; case "doExcel": doExcel(); break; case "close": CloPUR_SUPP(); break; } } /// 导出Excel /// private void doExcel() { try { this.Cursor = Cursors.Default; if (ultraGrid1.ActiveRow == null) { MessageUtil.ShowTips("请选择需导出明细的领用单头!"); return; } //获取导出的采购计划行表 ArrayList alUltraGrid = new ArrayList(); alUltraGrid.Add(ultraGrid2); ArrayList alSheeft = new ArrayList(); alSheeft.Add("物料明细"); if (ultraGrid2.Rows.Count > 0) { GridHelper.ulGridToExcel(alUltraGrid, alSheeft, "领用单[" + ultraGrid1.ActiveRow.GetCellValue("mrId") + "]明细表");//导出excel } else { MessageUtil.ShowTips("领用单:" + ultraGrid1.ActiveRow.GetCellValue("mrId") + "无可导出明细!"); } } catch (Exception e) { MessageUtil.ShowTips("导出失败" + e.Message); } finally { this.Cursor = Cursors.Default; } } /// /// 退回 /// private void returnUserPlanM() { UltraGridRow uge = ultraGrid1.ActiveRow; if (uge == null) return; String strMrId = uge.Cells["MRID"].Value.ToString(); if (String.IsNullOrEmpty(strMrId)) { return; } String strReason = ""; frmPopReason frm = new frmPopReason(this.ob); frm.ShowDialog(); if (frm.Tips == "1") { strReason = frm.Reason; } UsePlanM um = new UsePlanM(); um.MrId = strMrId; um.Status = "9"; um.Quitreson = "[退回] "+strReason; um.UpdateName = UserInfo.GetUserName(); um.UpdateUserid = UserInfo.GetUserID(); um.UpdateTime = DateTime.Now; if (MessageUtil.ShowYesNoAndQuestion("确定退回领用单:" + strMrId + "?") != DialogResult.Yes) { return; } CoreResult crt = this.execute("com.hnshituo.pur.requireplan.service.UsePlanMService", "doHandleM", new object[] { um }); if (crt.Resultcode != 0) { MessageUtil.ShowTips("操作失败:" + crt.Resultmsg); return; } MessageUtil.ShowTips("操作成功"); getUserPlanM(strMrId); } /// /// 查询领用单主表 /// private void getUserPlanM(String strMrId) { LYM.Clear(); LYD.Clear(); stockPos.Clear(); outStockDt.Clear(); UsePlanM pupe = new UsePlanM(); pupe.DeleteUserid = txt_status.Value == null ? "" : txt_status.Value.ToString().Trim(); pupe.MrId = ultraTextEditor1.Text.Trim(); pupe.ReqOrgId = req_org_id; if (ck_ctime.Checked == true) { if (txtCreateTimeStart.Text != "") { pupe.CreateTime = Convert.ToDateTime(txtCreateTimeStart.Value); } if (txtCreateTimeEnd.Text != "") { pupe.DeleteTime = Convert.ToDateTime(txtCreateTimeEnd.Value); } } DataTable dt = this.execute("com.hnshituo.pur.requireplan.service.UsePlanMService", "find_UsePlanM", new object[] { pupe }); GridHelper.CopyDataToDatatable(dt, dataTable1, true); GridHelper.RefreshAndAutoSize(ultraGrid1); if (!String.IsNullOrEmpty(strMrId)) { publicPms.doActiveSelRow(ultraGrid1, "mrId", strMrId); } } /// /// 完成领用 /// private void finishUserPlanM() { UltraGridRow uge = ultraGrid1.ActiveRow; if (uge == null) return; String strMrId = uge.Cells["MRID"].Value.ToString(); if (String.IsNullOrEmpty(strMrId)) { return; } UsePlanM um = new UsePlanM(); um.MrId = strMrId; um.Status = "5"; um.UpdateName = UserInfo.GetUserName(); um.UpdateUserid = UserInfo.GetUserID(); um.UpdateTime = DateTime.Now; if (MessageUtil.ShowYesNoAndQuestion("确定完成该领用单出库:" + strMrId + "?") != DialogResult.Yes) { return; } CoreResult crt = this.execute("com.hnshituo.pur.requireplan.service.UsePlanMService", "doHandleM", new object[] { um }); if (crt.Resultcode != 0) { MessageUtil.ShowTips("操作失败:" + crt.Resultmsg); return; } MessageUtil.ShowTips("操作成功"); getUserPlanM(strMrId); } /// /// 确认领用单 /// private void receiveUserPlanM() { throw new NotImplementedException(); } /// /// 关闭 /// private void CloPUR_SUPP() { this.Close(); } #endregion #region 库存操作 /// /// 重新匹配 /// /// /// private void query_ckPos_Click(object sender, EventArgs e) { } /// /// 出库操作 /// /// /// private void do_outBill_Click(object sender, EventArgs e) { setOutCkBill(); } /// /// 生成出库单 /// private void setOutCkBill() { ultraGrid3.UpdateData(); if (ultraGrid2.ActiveRow == null) { MessageUtil.ShowTips("请选择领用单行进行操作"); return; } String strUseLineId = ultraGrid2.ActiveRow.Cells["MrLineId"].Value.ToString().Trim(); if (String.IsNullOrEmpty(strUseLineId)) { MessageUtil.ShowTips("请选择领用单行号为空"); return; } CkOutBill cob = new CkOutBill(); UsePlanD pupe = this.execute("com.hnshituo.pur.requireplan.service.UsePlanDService", "findById", new object[] { strUseLineId }); if (pupe == null) { MessageUtil.ShowTips("未发现领用单行:" + strUseLineId + " 信息记录"); return; } if (pupe.Validflag != "1") { MessageUtil.ShowTips("领用单行:" + strUseLineId + " 信息记录已经作废"); return; } UsePlanM pm = this.execute("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { pupe.MrId }); cob = EntityHelper.CopyEntity(pupe); cob.DeliverAddress = pm.DeliveryLocationCode; cob.Status = "1"; cob.OutstockType = "6";//非JIT cob.RefeId = strUseLineId; cob.CreateName = UserInfo.GetUserName(); cob.CreateUserid = UserInfo.GetUserID(); cob.CreateTime = DateTime.Now; cob.Validflag = "1"; cob.ReleaseQty = 0; double bQTYUSE = 0; ArrayList al = new ArrayList(); for (int i = 0; i < ultraGrid3.Rows.Count; i++) { UltraGridRow row = ultraGrid3.Rows[i]; if (Convert.ToBoolean(row.GetCellValue("Check")) == true) { double b_OutNum = 0;//出库量 if (row.GetCellValue("itemUom").ToString() == "基吨") { double.TryParse(ultraGrid3.Rows[i].Cells["OUTNUM1"].Value.ToString(), out b_OutNum);//铁合金出库存 if (b_OutNum <= 0) { MessageUtil.ShowTips("储位【" + row.Cells["INVPOS"].Value.ToString() + "】的出库量必须>0"); return; } } else { double.TryParse(ultraGrid3.Rows[i].Cells["OUTNUM"].Value.ToString(), out b_OutNum);//非铁合金出采购 if (b_OutNum <= 0) { MessageUtil.ShowTips("储位【" + row.Cells["INVPOS"].Value.ToString() + "】的出库量必须>0"); return; } } CkOutbillPosition cobp = new CkOutbillPosition(); bQTYUSE += Math.Round(b_OutNum, 4, MidpointRounding.AwayFromZero); cobp.OutNum = Math.Round(b_OutNum, 4, MidpointRounding.AwayFromZero);//出库量 //cob.ReleaseQty += b_OutNum; //cobp.Id = ultraGrid1.Rows[i].Cells["INVPOSID"].Value.ToString(); //cobp.InvId = ultraGrid5.Rows[i].Cells["InvId"].Value.ToString(); cobp.InvPhysic = ultraGrid3.Rows[i].Cells["INVPHYSIC"].Value.ToString(); if (cobp.InvPhysic != pm.InvPhysic) { MessageUtil.ShowTips("请选择仓库:" + pm.InvPhysic + " 物料进行出库"); return; } cobp.InvPosId = ultraGrid3.Rows[i].Cells["InvPosId"].Value.ToString(); cobp.InvId = ultraGrid3.Rows[i].Cells["InvId"].Value.ToString(); if (String.IsNullOrEmpty(cobp.InvId)) { MessageUtil.ShowTips("选择的出库信息的送货单行不能为空"); return; } al.Add(cobp); } } if (al.Count == 0) { MessageUtil.ShowTips("至少有一个库位出库量>0"); return; } cob.ReleaseQty = Math.Round(bQTYUSE, 4, MidpointRounding.AwayFromZero); double canUse1=Math.Round((double)pupe.Qty-(double)pupe.QtyPur,4); if (cob.ReleaseQty > canUse1) { MessageUtil.ShowTips("总出库数量:" + cob.ReleaseQty + "已经大于该领用单行可编制量:" + canUse1); return; } if (MessageUtil.ShowYesNoAndQuestion("确定对领用单行:" + strUseLineId + " 进行出库(备货)操作?") != DialogResult.Yes) { return; } CoreResult crt = this.execute("com.hnshituo.pur.ck.service.CkOutBillService", "doInsert_Update", new object[] {cob, al }); if (crt.Resultcode != 0) { MessageUtil.ShowTips("出库单生成失败!" + crt.Resultmsg); return; } Core.Mes.Client.Comm.Tool.MessageUtil.ShowTips("出库成功!单号:" + crt.Resultmsg); getUserPlanM(pupe.MrId); publicPms.doActiveSelRow(ultraGrid2, "MrLineId", strUseLineId); } /// /// 取消出库操作 /// /// /// private void cancel_outBill_Click(object sender, EventArgs e) { ultraGrid3.UpdateData(); if (ultraGrid2.ActiveRow == null) { MessageUtil.ShowTips("请选择领用单行进行操作"); return; } String strUseLineId = ultraGrid2.ActiveRow.Cells["MrLineId"].Value.ToString().Trim(); if (String.IsNullOrEmpty(strUseLineId)) { MessageUtil.ShowTips("请选择领用单行号为空"); return; } ArrayList al = new ArrayList(); for (int i = 0; i < ultraGrid4.Rows.Count; i++) { UltraGridRow row = ultraGrid4.Rows[i]; if (Convert.ToBoolean(row.GetCellValue("Check")) == true) { CkOutbillPosition cobp = new CkOutbillPosition(); cobp.OutStockNo = row.Cells["outStockno"].Value.ToString(); cobp.Id = row.Cells["id"].Value.ToString(); if (String.IsNullOrEmpty(cobp.Id)) { MessageUtil.ShowTips("选择的撤销的出库单行行号不能为空"); return; } cobp.DeleteName = UserInfo.GetUserName(); cobp.DeleteUserid = UserInfo.GetUserID(); cobp.DeleteTime= DateTime.Now; al.Add(cobp); } } if (al.Count == 0) { MessageUtil.ShowTips("至少有一个出库记录"); return; } if (MessageUtil.ShowYesNoAndQuestion("确定对领用单行:" + strUseLineId + " 进行撤销出库(备货)操作?") != DialogResult.Yes) { return; } CoreResult crt = this.execute("com.hnshituo.pur.ck.service.CkOutBillService", "doCancel_OutStock", new object[] { strUseLineId, al }); if (crt.Resultcode != 0) { MessageUtil.ShowTips("撤销出库!" + crt.Resultmsg); return; } getUserPlanM(strUseLineId); } #endregion #region 公共函数 /// /// 查询领用单行表 /// private void getUserPlanD() { LYD.Clear(); stockPos.Clear(); outStockDt.Clear(); UltraGridRow uge = ultraGrid1.ActiveRow; if (uge == null) return; UsePlanD pupe = new UsePlanD(); pupe.MrId = uge.Cells["MRID"].Value.ToString(); if (String.IsNullOrEmpty(pupe.MrId)) { return; } pupe.Validflag = "1"; DataTable dt = this.execute("com.hnshituo.pur.requireplan.service.UsePlanDService", "getUsePlanD", new object[] { pupe }); foreach (DataRow row in dt.Rows) { if (row["ITEMUOM"].ToString() == "基吨") { row["ITEMUOM"] = "吨"; } } GridHelper.CopyDataToDatatable(dt, dataTable2, true); GridHelper.RefreshAndAutoSize(ultraGrid2); } /// /// 查询出库库位 /// private void getInvPhysic() { stockPos.Clear(); UltraGridRow ugr = ultraGrid2.ActiveRow; if (ugr == null) { MessageUtil.ShowTips("请选择需出库的物料"); return; } String strMrLineId=ugr.Cells["MRLINEID"].Value.ToString().Trim(); if ( String.IsNullOrEmpty(strMrLineId)) { MessageUtil.ShowTips("该领用单行号为空"); return; } UsePlanD ud = this.execute("com.hnshituo.pur.requireplan.service.UsePlanDService", "findById", new object[] { strMrLineId }); UsePlanM um = this.execute("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { ud.MrId }); if (String.IsNullOrEmpty(ud.PurLineId)) { MessageUtil.ShowTips("领用单行:" + strMrLineId + "未关联采购计划号,无法查询库存信息"); return; } PurCkStoragePosEntity ckp = new PurCkStoragePosEntity(); ckp.UpdateName = ud.PurLineId; ckp.InvPhysic = um.InvPhysic; DataTable dt = this.execute("com.hnshituo.pur.ck.service.CkStoragePosService", "getCkStoragePos", new object[] { ckp }); GridHelper.CopyDataToDatatable(ref dt, ref dataTable3, true); double canOutNum = (double)ud.Qty - (ud.QtyPur == null ? 0 : (double)ud.QtyPur); double tempCanUseQty = canOutNum; foreach (UltraGridRow row in ultraGrid3.Rows) { if (row.GetCellValue("itemUom").ToString() == "基吨") { //row.Cells["itemUom"].Value = "吨"; double needQty = 0; double dbItemUomConefficient = 1; double.TryParse(row.GetCellValue("INVQTYWEIGHT").ToString(), out needQty);//库存需出库量 double.TryParse(row.GetCellValue("itemUomConefficient").ToString(), out dbItemUomConefficient); if (tempCanUseQty > 0 && needQty > 0) { if (needQty >= tempCanUseQty) { row.Cells["OUTNUM1"].Value = tempCanUseQty;//库存出库量 row.Cells["OUTNUM"].Value = Math.Round(tempCanUseQty*dbItemUomConefficient,4);//采购出库量 tempCanUseQty = 0; row.Cells["Check"].Value = true; } else { row.Cells["OUTNUM1"].Value = needQty;//库存出库量 row.Cells["OUTNUM"].Value = Math.Round(needQty*dbItemUomConefficient, 4);//采购出库量 tempCanUseQty = tempCanUseQty - needQty; row.Cells["Check"].Value = true; } } } else { double needQty = 0; double dbItemUomConefficient = 1; double.TryParse(row.GetCellValue("invqty").ToString(), out needQty);//采购需出库量 double.TryParse(row.GetCellValue("itemUomConefficient").ToString(), out dbItemUomConefficient); if (tempCanUseQty > 0 && needQty > 0) { if (needQty >= tempCanUseQty) { row.Cells["OUTNUM"].Value = tempCanUseQty; row.Cells["OUTNUM1"].Value = Math.Round(tempCanUseQty / dbItemUomConefficient, 4, MidpointRounding.AwayFromZero);//采购出库量 tempCanUseQty = 0; row.Cells["Check"].Value = true; } else { row.Cells["OUTNUM"].Value = needQty; row.Cells["OUTNUM1"].Value = Math.Round(needQty / dbItemUomConefficient, 4, MidpointRounding.AwayFromZero);//采购出库量 tempCanUseQty = tempCanUseQty - needQty; row.Cells["Check"].Value = true; } } } } GridHelper.RefreshAndAutoSize(ultraGrid3); } private void getOutBillPos() { try { outStockDt.Clear(); UltraGridRow ugr = ultraGrid2.ActiveRow; if (ugr == null) { MessageUtil.ShowTips("请选择需出库的物料"); return; } String strMrLineId = ugr.Cells["MRLINEID"].Value.ToString().Trim(); if (String.IsNullOrEmpty(strMrLineId)) { MessageUtil.ShowTips("该领用单行号为空"); return; } UsePlanD ud = this.execute("com.hnshituo.pur.requireplan.service.UsePlanDService", "findById", new object[] { strMrLineId }); UsePlanM um = this.execute("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { ud.MrId }); if (String.IsNullOrEmpty(ud.PurLineId)) { MessageUtil.ShowTips("领用单行:" + strMrLineId + "未关联采购计划号,无法查询库存信息"); return; } CkOutbillPosition cp = new CkOutbillPosition(); cp.UpdateName = strMrLineId; DataTable dt = this.execute("com.hnshituo.pur.ck.service.CkOutbillPositionService", "doQueryCkOutbillPosition", new object[] { cp }); if (dt != null && dt.Rows.Count >= 1) { GridHelper.CopyDataToDatatable(ref dt, ref dataTable4, true); GridHelper.RefreshAndAutoSize(ultraGrid4); } } catch (Exception ex) { MessageBox.Show("操作失败:" + ex.Message, "提示"); } } #endregion #region 界面事件 private void ultraGrid1_AfterRowActivate(object sender, EventArgs e) { getUserPlanD(); } /// /// 填写出库量 /// /// /// private void ultraGrid3_CellChange(object sender, CellEventArgs e) { object o = e.Cell.Value; ultraGrid3.UpdateData(); double canUse=0; double canUseUom = 0; double canUseWeight = 0; double conf = 0; if (ultraGrid2.ActiveRow != null) { double b_QTY = 0;//领用量 double.TryParse(ultraGrid2.ActiveRow.Cells["QTY"].Value.ToString(), out b_QTY); double b_QTY_pur = 0;//领用量 double.TryParse(ultraGrid2.ActiveRow.Cells["QTYPUR"].Value.ToString(), out b_QTY_pur); canUse = Math.Round((b_QTY - b_QTY_pur), 4, MidpointRounding.AwayFromZero); } else { MessageUtil.ShowTips("请选择待出库物料"); return; } double.TryParse(e.Cell.Row.GetCellValue("invqty").ToString(), out canUseUom); double.TryParse(e.Cell.Row.GetCellValue("INVQTYWEIGHT").ToString(), out canUseWeight); double.TryParse(e.Cell.Row.GetCellValue("itemUomConefficient").ToString(), out conf); if(e.Cell.Column.Key=="OUTNUM")//采购数量 { double b_OutNum_q = 0;//出库总量 double OutNum = 0;//出库量 double.TryParse(e.Cell.Row.GetCellValue("OUTNUM").ToString(), out OutNum); for(int i=0;i canUse) { MessageUtil.ShowTips("已大于领用单可编制量:"+canUse+""); e.Cell.Value = o; return; } if (OutNum > canUseUom) { MessageUtil.ShowTips("已大于在库量(采购单位):" + canUseUom + ""); e.Cell.Value = o; return; } if (e.Cell.Row.GetCellValue("itemUom").ToString() == "基吨") { e.Cell.Row.Cells["OUTNUM1"].Value = Math.Round(OutNum/conf , 4, MidpointRounding.AwayFromZero); } else { e.Cell.Row.Cells["OUTNUM1"].Value = Math.Round(conf * OutNum, 4, MidpointRounding.AwayFromZero); } } else if (e.Cell.Column.Key == "OUTNUM1")//库存数量 { double OutNum1 = 0;//库存单位出库量 double.TryParse(e.Cell.Row.GetCellValue("OUTNUM1").ToString(), out OutNum1); if (OutNum1 > canUseWeight) { MessageUtil.ShowTips("已大于在库量(库存单位):" + canUseWeight + ""); e.Cell.Value = o; return; } if (e.Cell.Row.GetCellValue("itemUom").ToString() == "基吨") { e.Cell.Row.Cells["OUTNUM"].Value = Math.Round(OutNum1*conf, 4, MidpointRounding.AwayFromZero); } else { e.Cell.Row.Cells["OUTNUM"].Value = Math.Round(OutNum1 / conf, 4, MidpointRounding.AwayFromZero); } } ultraGrid3.UpdateData(); } /// /// 激活领用单行 /// /// /// private void ultraGrid2_AfterRowActivate(object sender, EventArgs e) { getInvPhysic(); getOutBillPos(); } private void ultraGrid2_InitializeLayout(object sender, InitializeLayoutEventArgs e) { } private void ck_ctime_CheckedChanged(object sender, EventArgs e) { if (ck_ctime.Checked == false) { txtCreateTimeEnd.Enabled = false; txtCreateTimeStart.Enabled = false; } else { txtCreateTimeEnd.Enabled = true; txtCreateTimeStart.Enabled = true; } } private void txt_REQ_ORG_EditorButtonClick(object sender, EditorButtonEventArgs e) { frmdepartment frm = new frmdepartment(this.ob); frm.StartPosition = FormStartPosition.Manual; frm.Location = publicPms.getShowLocation(frm); frm.ShowDialog(); String strdeptId = frm.BuyerUnitCode; String strDeptName = frm.Fulltext; if (!String.IsNullOrEmpty(strdeptId) && !String.IsNullOrEmpty(strDeptName)) { txt_REQ_ORG.Text = strDeptName; req_org_id = strdeptId; } } #endregion } }