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 frmUsePlanYBNew: FrmPmsBase
{
DataTable Qdt = null;//库区
private string req_org_id = "";
public frmUsePlanYBNew()
{
InitializeComponent();
this.IsLoadUserView = true;
}
private void frmUsePlanYBNew_Load(object sender, EventArgs e)
{
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" });
do_outBill.Enabled = true;
cancel_outBill.Enabled = false;
}
#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;
}
if (testStatusM(strMrId, 2) == false)
{
return;
}
String strReason = "";
frmPopReason frm = new frmPopReason(this.ob);
frm.ShowDialog();
if (frm.Tips == "1")
{
strReason = frm.Reason;
}
else
{
return;
}
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;
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(testStatusM(strMrId,1)==false)
{
return;
}
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()
{
UltraGrid grid = new UltraGrid();
String isNor = "1";//是否为有主需求出库
if (ultraTabControl1.SelectedTab == ultraTabControl1.Tabs[0])
{
grid = ultraGrid3;
isNor = "1";
}
else if (ultraTabControl1.SelectedTab == ultraTabControl1.Tabs[1])
{
grid = ultraGrid5;
isNor = "0";
}
else
{
MessageUtil.ShowTips("请选择可出库数据");
return;
}
grid.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 });
if (pm == null)
{
MessageUtil.ShowTips("未发现领料单头:" + pupe.MrId + "信息记录");
return;
}
if (pm.Validflag != "1")
{
MessageUtil.ShowTips("领料单头:" + pupe.MrId + "信息记录可能已作废");
return;
}
if (pm.Status != "2" && pm.Status != "3")
{
MessageUtil.ShowTips("领料单头:" + pupe.MrId + "当前状态无法执行出库");
return;
}
cob = EntityHelper.CopyEntity(pupe);
cob.DeliverAddress = pm.DeliveryLocationCode;
cob.Status = "1";
if (isNor == "1")
{
cob.OutstockType = "4";//非JIT有主
}
else
{
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 < grid.Rows.Count; i++)
{
UltraGridRow row = grid.Rows[i];
if (Convert.ToBoolean(row.GetCellValue("Check")) == true)
{
double b_OutNum = 0;//出库量
if (row.GetCellValue("itemUom").ToString() == "基吨")
{
double.TryParse(grid.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(grid.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 = grid.Rows[i].Cells["INVPHYSIC"].Value.ToString();
if (cobp.InvPhysic != pm.InvPhysic)
{
MessageUtil.ShowTips("请选择仓库:" + pm.InvPhysic + " 物料进行出库");
return;
}
cobp.InvPosId = grid.Rows[i].Cells["InvPosId"].Value.ToString();
cobp.InvId = grid.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_UpdateNew", new object[] {cob, al,isNor});
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 getInvPhysicNor()
{
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;
}
if (String.IsNullOrEmpty(ud.PurRequireLineId))
{
MessageUtil.ShowTips("领用单行:" + strMrLineId + "未关联需求接收号,无法查询库存占用信息");
return;
}
PurCkStoragePosEntity ckp = new PurCkStoragePosEntity();
ckp.UpdateName = ud.PurLineId;
ckp.DeleteName = ud.ReceiveId;
ckp.InvPhysic = um.InvPhysic;
ckp.UpdateUserid = "nor";//查询有主需求
DataTable dt = this.execute("com.hnshituo.pur.ck.service.CkStoragePosService", "getCkStoragePosUse", new object[] { ckp });
if (dt == null || dt.Rows.Count <= 0)
{
ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[1];
}
else
{
ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[0];
}
GridHelper.CopyDataToDatatable(ref dt, ref dataTable3, true);
double canOutNum = (double)ud.Qty - (ud.QtyPur == null ? 0 : (double)ud.QtyPur);
double canOutNum1 = (ud.QtyUnnormal == null ? 0 : (double)ud.QtyUnnormal) - (ud.QtyUnnormalPur == null ? 0 : (double)ud.QtyUnnormalPur);
if (canOutNum1 > 0)
{
canOutNum = canOutNum - canOutNum1;
}
double tempCanUseQty = canOutNum;
Hashtable table = new Hashtable();
double norQtyNor = 0;
double norQtyNorWeight = 0;
foreach (UltraGridRow row in ultraGrid3.Rows)
{
String strInvId = row.GetCellValue("invId").ToString().Trim();
double.TryParse(row.GetCellValue("qtyNor").ToString(), out norQtyNor);
double.TryParse(row.GetCellValue("qtyNorWeight").ToString(), out norQtyNorWeight);
double UseQtyInInv = 0;
double createQty=0;
if (table.ContainsKey(strInvId))
{
UseQtyInInv = (double)table[strInvId];
}
if (String.IsNullOrEmpty(strInvId))
{
continue;
}
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)
{
if (tempCanUseQty <= norQtyNorWeight - UseQtyInInv)
{
createQty=tempCanUseQty;
row.Cells["OUTNUM1"].Value =createQty ;//库存出库量
row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
tempCanUseQty = 0;
row.Cells["Check"].Value = true;
}
else
{
createQty = (norQtyNorWeight - UseQtyInInv) < 0 ? 0 : (norQtyNorWeight - UseQtyInInv);
if(createQty>0)
{
row.Cells["OUTNUM1"].Value = createQty;//库存出库量
row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
tempCanUseQty = tempCanUseQty - createQty;
row.Cells["Check"].Value = true;
}
}
if (table.ContainsKey(strInvId))
{
table[strInvId] = UseQtyInInv + createQty;
}
}
else//需要的小
{
if (needQty <= norQtyNorWeight - UseQtyInInv)
{
createQty = needQty;
row.Cells["OUTNUM1"].Value = createQty;//库存出库量
row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
tempCanUseQty = tempCanUseQty - createQty;
row.Cells["Check"].Value = true;
}
else
{
createQty = (norQtyNorWeight - UseQtyInInv) < 0 ? 0 : (norQtyNorWeight - UseQtyInInv);
if (createQty > 0)
{
row.Cells["OUTNUM1"].Value = createQty;//库存出库量
row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
tempCanUseQty = tempCanUseQty - createQty;
row.Cells["Check"].Value = true;
}
}
if (table.ContainsKey(strInvId))
{
table[strInvId] = UseQtyInInv + createQty;
}
}
}
}
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)
{
if (tempCanUseQty <= norQtyNor - UseQtyInInv)
{
createQty = tempCanUseQty;
row.Cells["OUTNUM"].Value = createQty;
row.Cells["OUTNUM1"].Value = Math.Round(createQty / dbItemUomConefficient, 4, MidpointRounding.AwayFromZero);//采购出库量
tempCanUseQty = 0;
row.Cells["Check"].Value = true;
}
else
{
createQty = (norQtyNor - UseQtyInInv) < 0 ? 0 : (norQtyNor - UseQtyInInv);
if (createQty > 0)
{
row.Cells["OUTNUM"].Value = createQty;//库存出库量
row.Cells["OUTNUM1"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
tempCanUseQty = tempCanUseQty - createQty;
row.Cells["Check"].Value = true;
}
}
if (table.ContainsKey(strInvId))
{
table[strInvId] = UseQtyInInv + createQty;
}
}
else
{
if (needQty <= norQtyNor - UseQtyInInv)
{
createQty = needQty;
row.Cells["OUTNUM"].Value = needQty;
row.Cells["OUTNUM1"].Value = Math.Round(createQty / dbItemUomConefficient, 4, MidpointRounding.AwayFromZero);//采购出库量
tempCanUseQty = tempCanUseQty - createQty;
row.Cells["Check"].Value = true;
}
else
{
createQty = (norQtyNor - UseQtyInInv) < 0 ? 0 : (norQtyNor - UseQtyInInv);
if (createQty > 0)
{
row.Cells["OUTNUM1"].Value = createQty;//库存出库量
row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
tempCanUseQty = tempCanUseQty - createQty;
row.Cells["Check"].Value = true;
}
}
if (table.ContainsKey(strInvId))
{
table[strInvId] = UseQtyInInv + createQty;
}
}
}
}
}
GridHelper.RefreshAndAutoSize(ultraGrid3);
}
///
/// 查询无主出库库位
///
private void getInvPhysicUnnor()
{
stockPosUnnor.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;
}
if (String.IsNullOrEmpty(ud.PurRequireLineId))
{
MessageUtil.ShowTips("领用单行:" + strMrLineId + "未关联需求接收号,无法查询库存占用信息");
return;
}
PurCkStoragePosEntity ckp = new PurCkStoragePosEntity();
ckp.UpdateName = ud.PurLineId;
ckp.DeleteName = ud.ReceiveId;
ckp.InvPhysic = um.InvPhysic;
ckp.UpdateUserid = "unNor";//查询有主需求
DataTable dt = this.execute("com.hnshituo.pur.ck.service.CkStoragePosService", "getCkStoragePosUse", new object[] { ckp });
GridHelper.CopyDataToDatatable(ref dt, ref dataTable5, true);
double canOutNum = (ud.QtyUnnormal == null ? 0 : (double)ud.QtyUnnormal) - (ud.QtyUnnormalPur == null ? 0 : (double)ud.QtyUnnormalPur);
canOutNum = canOutNum < 0 ? 0 : canOutNum;
double tempCanUseQty = canOutNum;
Hashtable table = new Hashtable();
double unnorQtyNor = 0;
double unnorQtyNorWeight = 0;
foreach (UltraGridRow row in ultraGrid5.Rows)
{
String strInvId = row.GetCellValue("invId").ToString().Trim();
double.TryParse(row.GetCellValue("qtyUnnor").ToString(), out unnorQtyNor);
double.TryParse(row.GetCellValue("qtyUnnorWeight").ToString(), out unnorQtyNorWeight);
double UseQtyInInv = 0;
double createQty = 0;
if (table.ContainsKey(strInvId))
{
UseQtyInInv = (double)table[strInvId];
}
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)
{
if (tempCanUseQty <= unnorQtyNorWeight - UseQtyInInv)
{
createQty = tempCanUseQty;
row.Cells["OUTNUM1"].Value = createQty;//库存出库量
row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
tempCanUseQty = 0;
row.Cells["Check"].Value = true;
}
else
{
createQty = (unnorQtyNorWeight - UseQtyInInv) < 0 ? 0 : (unnorQtyNorWeight - UseQtyInInv);
if (createQty > 0)
{
row.Cells["OUTNUM1"].Value = createQty;//库存出库量
row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
tempCanUseQty = tempCanUseQty - createQty;
row.Cells["Check"].Value = true;
}
}
if (table.ContainsKey(strInvId))
{
table[strInvId] = UseQtyInInv + createQty;
}
}
else
{
if (needQty <= unnorQtyNorWeight - UseQtyInInv)
{
createQty = needQty;
row.Cells["OUTNUM1"].Value = createQty;//库存出库量
row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
tempCanUseQty = tempCanUseQty - createQty;
row.Cells["Check"].Value = true;
}
else
{
createQty = (unnorQtyNorWeight - UseQtyInInv) < 0 ? 0 : (unnorQtyNorWeight - UseQtyInInv);
if (createQty > 0)
{
row.Cells["OUTNUM1"].Value = createQty;//库存出库量
row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
tempCanUseQty = tempCanUseQty - createQty;
row.Cells["Check"].Value = true;
}
}
if (table.ContainsKey(strInvId))
{
table[strInvId] = UseQtyInInv + createQty;
}
}
}
}
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)
{
if (tempCanUseQty <= unnorQtyNor - UseQtyInInv)
{
createQty = tempCanUseQty;
row.Cells["OUTNUM"].Value = createQty;
row.Cells["OUTNUM1"].Value = Math.Round(createQty / dbItemUomConefficient, 4, MidpointRounding.AwayFromZero);//采购出库量
tempCanUseQty = 0;
row.Cells["Check"].Value = true;
}
else
{
createQty = (unnorQtyNor - UseQtyInInv) < 0 ? 0 : (unnorQtyNor - UseQtyInInv);
if (createQty > 0)
{
row.Cells["OUTNUM"].Value = createQty;
row.Cells["OUTNUM1"].Value = Math.Round(createQty / dbItemUomConefficient, 4, MidpointRounding.AwayFromZero);//采购出库量
tempCanUseQty = tempCanUseQty - createQty;
row.Cells["Check"].Value = true;
}
}
if (table.ContainsKey(strInvId))
{
table[strInvId] = UseQtyInInv + createQty;
}
}
else
{
if (needQty <= unnorQtyNor - UseQtyInInv)
{
createQty = needQty;
row.Cells["OUTNUM"].Value = createQty;
row.Cells["OUTNUM1"].Value = Math.Round(createQty / dbItemUomConefficient, 4, MidpointRounding.AwayFromZero);//采购出库量
tempCanUseQty = tempCanUseQty - createQty;
row.Cells["Check"].Value = true;
}
else
{
createQty = (unnorQtyNor - UseQtyInInv) < 0 ? 0 : (unnorQtyNor - UseQtyInInv);
if (createQty > 0)
{
row.Cells["OUTNUM"].Value = createQty;
row.Cells["OUTNUM1"].Value = Math.Round(createQty / dbItemUomConefficient, 4, MidpointRounding.AwayFromZero);//采购出库量
tempCanUseQty = tempCanUseQty - createQty;
row.Cells["Check"].Value = true;
}
}
if (table.ContainsKey(strInvId))
{
table[strInvId] = UseQtyInInv + createQty;
}
}
}
}
}
GridHelper.RefreshAndAutoSize(ultraGrid5);
}
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, "提示");
}
}
///
/// 校验状态
///
///
///
private bool testStatusM(string strMrId, int i)
{
UsePlanM up = this.execute("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { strMrId });
if (up == null)
{
MessageUtil.ShowTips("未发现领料单头:" + strMrId + "信息记录");
return false;
}
if (up.Validflag != "1")
{
MessageUtil.ShowTips("领料单头:" + strMrId + "信息记录可能已作废");
return false;
}
//完成领用
if (i == 1)
{
if (up.Status == "2" || up.Status == "1" || up.Status=="9")
{
MessageUtil.ShowTips("还未备货,无法确认出库");
return false;
}
else if (up.Status == "5" || up.Status == "6")
{
MessageUtil.ShowTips("已出库,无需重复操作");
return false;
}
else if (up.Status == "3")
{
if (MessageUtil.ShowYesNoAndQuestion("还未全部备货,确定执行出库?") != DialogResult.Yes)
{
return false;
}
}
}
else if (i == 2)
{
if (up.Status!= "2")
{
MessageUtil.ShowTips("不在待确认状态,无法退回!若有出库(备货),请先取消出库(备货)!");
return false;
}
}
else
{
MessageUtil.ShowTips("参数异常");
}
return true;
}
#endregion
#region 界面事件
private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
{
getUserPlanD();
}
///
/// 填写出库量
///
///
///
private void ultraGrid5_CellChange(object sender, CellEventArgs e)
{
object o = e.Cell.Value;
ultraGrid5.UpdateData();
double canUse = 0;
double canUseUom = 0;
double canUseWeight = 0;
double conf = 0;
double norQtyNor = 0;
double norQtyNorWeight = 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("请选择待出库物料");
e.Cell.Value = o;
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);
double.TryParse(e.Cell.Row.GetCellValue("qtyUnnor").ToString(), out norQtyNor);
double.TryParse(e.Cell.Row.GetCellValue("qtyUnnorWeight").ToString(), out norQtyNorWeight);
String strInvId = e.Cell.Row.GetCellValue("invId").ToString().Trim();
if (String.IsNullOrEmpty(strInvId))
{
MessageUtil.ShowTips("请选择待出库库存的库存记录号不能为空");
e.Cell.Value = o;
return;
}
if (e.Cell.Column.Key == "OUTNUM")//采购数量
{
double b_OutNum_nor_q = 0;//库存有主需求出库量总
double b_OutNum_q = 0;//出库总量
double OutNum = 0;//出库量
double.TryParse(e.Cell.Row.GetCellValue("OUTNUM").ToString(), out OutNum);
for (int i = 0; i < ultraGrid5.Rows.Count; i++)
{
double b_OutNum = 0;//出库量
double.TryParse(ultraGrid5.Rows[i].Cells["OUTNUM"].Value.ToString(), out b_OutNum);
b_OutNum_q += Math.Round(b_OutNum, 4, MidpointRounding.AwayFromZero);
if (ultraGrid5.Rows[i].Cells["invId"].Value.ToString().Trim() == strInvId)
{
b_OutNum_nor_q = b_OutNum_nor_q + b_OutNum;
}
}
if (b_OutNum_q > canUse)
{
MessageUtil.ShowTips("已大于领用单可编制量:" + canUse + "");
e.Cell.Value = o;
return;
}
if (b_OutNum_nor_q > norQtyNor)
{
MessageUtil.ShowTips("库存记录总编制量已大于该单位在该库存记录下的无主库存量(采购单位)");
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);
double b_OutNum_nor_q = 0;//库存有主需求出库量总
for (int i = 0; i < ultraGrid5.Rows.Count; i++)
{
double b_OutNum = 0;//出库量
double.TryParse(ultraGrid5.Rows[i].Cells["OUTNUM1"].Value.ToString(), out b_OutNum);
if (ultraGrid5.Rows[i].Cells["invId"].Value.ToString().Trim() == strInvId)
{
b_OutNum_nor_q = b_OutNum_nor_q + b_OutNum;
}
}
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);
}
}
ultraGrid5.UpdateData();
}
///
/// 填写出库量
///
///
///
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;
double norQtyNor = 0;
double norQtyNorWeight = 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("请选择待出库物料");
e.Cell.Value = o;
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);
double.TryParse(e.Cell.Row.GetCellValue("qtyNor").ToString(), out norQtyNor);
double.TryParse(e.Cell.Row.GetCellValue("qtyNorWeight").ToString(), out norQtyNorWeight);
String strInvId = e.Cell.Row.GetCellValue("invId").ToString().Trim();
if (String.IsNullOrEmpty(strInvId))
{
MessageUtil.ShowTips("请选择待出库库存的库存记录号不能为空");
e.Cell.Value = o;
return;
}
if(e.Cell.Column.Key=="OUTNUM")//采购数量
{
double b_OutNum_nor_q = 0;//库存有主需求出库量总
double b_OutNum_q = 0;//出库总量
double OutNum = 0;//出库量
double.TryParse(e.Cell.Row.GetCellValue("OUTNUM").ToString(), out OutNum);
for(int i=0;i norQtyNor)
{
MessageUtil.ShowTips("库存记录总编制量已大于该单位在该库存记录下的占用量(计量单位)");
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 {
if (b_OutNum_q > canUse)
{
MessageUtil.ShowTips("已大于领用单可编制量:" + canUse + "");
e.Cell.Value = o;
return;
}
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);
double b_OutNum_nor_q = 0;//库存有主需求出库量总(库存)
double b_OutNum_q = 0;//出库总量(库存)
for (int i = 0; i < ultraGrid3.Rows.Count; i++)
{
double b_OutNum = 0;//出库量
double.TryParse(ultraGrid3.Rows[i].Cells["OUTNUM1"].Value.ToString(), out b_OutNum);
b_OutNum_q += Math.Round(b_OutNum, 4, MidpointRounding.AwayFromZero);
if (ultraGrid3.Rows[i].Cells["invId"].Value.ToString().Trim() == strInvId)
{
b_OutNum_nor_q = b_OutNum_nor_q + b_OutNum_q;
}
}
if (b_OutNum_nor_q > norQtyNorWeight)
{
MessageUtil.ShowTips("库存记录总编制量已大于该单位在该库存记录下的占用量(库存单位)");
e.Cell.Value = o;
return;
}
//校验编制量不能大于库存量
if (OutNum1 > canUseWeight)
{
MessageUtil.ShowTips("已大于在库量(库存单位):" + canUseWeight + "");
e.Cell.Value = o;
return;
}
if (e.Cell.Row.GetCellValue("itemUom").ToString() == "基吨")
{
if (b_OutNum_q > canUse)
{
MessageUtil.ShowTips("已大于领用单可编制量:" + canUse + "");
e.Cell.Value = o;
return;
}
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)
{
getInvPhysicNor();
getInvPhysicUnnor();
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
private void ultraTabControl1_SelectedTabChanged(object sender, Infragistics.Win.UltraWinTabControl.SelectedTabChangedEventArgs e)
{
if (ultraTabControl1.SelectedTab == ultraTabControl1.Tabs[2])
{
do_outBill.Enabled = false;
cancel_outBill.Enabled = true;
}
else
{
do_outBill.Enabled = true;
cancel_outBill.Enabled = false;
}
}
}
}