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 Pur.Entity;
using Core.Mes.Client.Comm.Control;
using System.Collections;
using Core.Mes.Client.Comm.Tool;
using Infragistics.Win;
using Pur.Entity.ck;
using Pur.Entity.configureEntity;
using com.hnshituo.pur.vo;
namespace Pur.Pop_upWindow
{
public partial class frm_PlanBenefit : FrmPmsBase
{
public frm_PlanBenefit(OpeBase ob, string strMrId)
{
InitializeComponent();
this.ob = ob;
get_PUR_PLAN_D(strMrId);
GridHelper.SetExcludeColumnsActive(ultraGrid3.DisplayLayout.Bands[0], "QTYLJHTemp");
GridHelper.SetExcludeColumnsActive(ultraGrid2.DisplayLayout.Bands[0]);
}
///
/// 按钮控件
///
///
///
private void barsManagerButon_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
{
switch (e.Tool.Key.ToString())
{
case "Query":
{
}
break;
case "conFirmation":
{
conFirmation();
}
break;
case "ESC":
{
this.Close();
}
break;
}
}
///
/// 查询采购计划详表
///
///
public void get_PUR_PLAN_D(string strMrId)
{
EntityPurPlanD PurPlanDEntity = new EntityPurPlanD();
PurPlanDEntity.Validflag = "1";
PurPlanDEntity.MrId = strMrId;
DataTable dt = this.execute("com.hnshituo.pur.purplan.service.PurPlanDService", "find", new object[] { PurPlanDEntity, 0, 0 });
GridHelper.CopyDataToDatatable(ref dt, ref dataTable5, true);//绑定目标采购计划行表
//查询源采购计划行
EntityPurPlanD PurPlanDEntitys = new EntityPurPlanD();
PurPlanDEntitys.Validflag = "1";
PurPlanDEntitys.MrId = strMrId;
DataTable dt1 = this.execute("com.hnshituo.pur.purplan.service.PurPlanDService", "getPlanBenefit", new object[] { PurPlanDEntitys });
GridHelper.CopyDataToDatatable(ref dt1, ref dataTable2, true);//绑定源采购计划行表
}
///
/// 激活采购计划行
///
///
///
private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
{
showItemUgridRow();
}
///
/// 显示采购计划激活行的物料
///
private void showItemUgridRow()
{
for (int i = 0; i < ultraGrid3.Rows.Count; i++)
{
if (ultraGrid3.Rows[i].Cells["ITEMCODE"].Value.ToString() != ultraGrid2.ActiveRow.Cells["ITEMCODE"].Value.ToString() || ultraGrid3.Rows[i].Cells["ITEMUOM"].Value.ToString().Trim() != ultraGrid2.ActiveRow.Cells["ITEMUOM"].Value.ToString().Trim())
{
ultraGrid3.Rows[i].Hidden = true;
}
else
{
ultraGrid3.Rows[i].Hidden = false;
}
}
}
///
/// 确认操作
///
///
public void conFirmation()
{
ultraGrid2.UpdateData();
ultraGrid3.UpdateData();
ArrayList alpbd = new ArrayList();//目标采购计划行
ArrayList alpbds = new ArrayList();//源采购计划行
ArrayList alpbdsu = new ArrayList();//采购计划占用表
//循环采购计划行表
for (int i = 0; i < ultraGrid2.Rows.Count; i++)
{
//更新采购计划行表
EntityPurPlanD pbd = new EntityPurPlanD();//采购计划行
pbd.MrLineId = ultraGrid2.Rows[i].Cells["MrLineId"].Value.ToString();//采购单行号
double bPurQTYLJH = 0;//采购行利计划量
if (ultraGrid2.Rows[i].Cells["QTYLJH"].Value != null && ultraGrid2.Rows[i].Cells["QTYLJH"].Value.ToString() != "")
{
double.TryParse(ultraGrid2.Rows[i].Cells["QTYLJH"].Value.ToString(), out bPurQTYLJH);
}
double bQty = 0;//采购数量
if (ultraGrid2.Rows[i].Cells["QTY"].Value != null && ultraGrid2.Rows[i].Cells["QTY"].Value.ToString() != "")
{
double.TryParse(ultraGrid2.Rows[i].Cells["QTY"].Value.ToString(), out bQty);
}
pbd.Qty = bQty;//采购数量
pbd.QtyLjh = bPurQTYLJH;//利计划
pbd.UpdateTime = System.DateTime.Now;
pbd.UpdateName = UserInfo.GetUserName();
pbd.UpdateUserid = UserInfo.GetUserID();
alpbd.Add(pbd);
for (int j = 0; j < ultraGrid3.Rows.Count; j++)
{
//if (ultraGrid3.Rows[j].Cells["ITEMUOMCONEFFICIENT"].Value.ToString() != "" && double.Parse(ultraGrid3.Rows[j].Cells["ITEMUOMCONEFFICIENT"].Value.ToString()) != 0)
//{
if (ultraGrid3.Rows[j].Cells["ITEMCODE"].Value.ToString() != ultraGrid2.Rows[i].Cells["ITEMCODE"].Value.ToString() || ultraGrid3.Rows[j].Cells["ITEMUOM"].Value.ToString().Trim() != ultraGrid2.Rows[i].Cells["ITEMUOM"].Value.ToString().Trim())
{ continue; }
EntityPurPlanD pbds = new EntityPurPlanD();
pbds.MrLineId = ultraGrid3.Rows[j].Cells["MrLineId"].Value.ToString();//采购单行号
double bQTYYCUSEABLE = 0;//预采可分配量
if (ultraGrid3.Rows[j].Cells["QTYYCUSEABLE"].Value != null && ultraGrid3.Rows[j].Cells["QTYYCUSEABLE"].Value.ToString() != "")
{
double.TryParse(ultraGrid3.Rows[j].Cells["QTYYCUSEABLE"].Value.ToString(), out bQTYYCUSEABLE);
}
double bQTYYCUSED = 0;//预采已分配量
if (ultraGrid3.Rows[j].Cells["QTYYCUSED"].Value != null && ultraGrid3.Rows[j].Cells["QTYYCUSED"].Value.ToString() != "")
{
double.TryParse(ultraGrid3.Rows[j].Cells["QTYYCUSED"].Value.ToString(), out bQTYYCUSED);
}
double bQTYLJHTemp = 0;//本次利计划量
if (ultraGrid3.Rows[j].Cells["QTYLJHTemp"].Value != null && ultraGrid3.Rows[j].Cells["QTYLJHTemp"].Value.ToString() != "")
{
double.TryParse(ultraGrid3.Rows[j].Cells["QTYLJHTemp"].Value.ToString(), out bQTYLJHTemp);
}
double bQTYLJHLast = 0;//上次利计划量
if (ultraGrid3.Rows[j].Cells["QTYLJHLast"].Value != null && ultraGrid3.Rows[j].Cells["QTYLJHLast"].Value.ToString() != "")
{
double.TryParse(ultraGrid3.Rows[j].Cells["QTYLJHLast"].Value.ToString(), out bQTYLJHLast);
}
pbds.QtyYcUseable = bQTYYCUSEABLE +bQTYLJHLast-bQTYLJHTemp;//预采可分配量
pbds.QtyYcUsed = bQTYYCUSED + bQTYLJHTemp - bQTYLJHLast;//预采已分配量
pbds.UpdateTime = System.DateTime.Now;
pbds.UpdateName = UserInfo.GetUserName();
pbds.UpdateUserid = UserInfo.GetUserID();
alpbds.Add(pbds);
//库存占用量
PurPurPlanUseEntity PlanUseEntity = new PurPurPlanUseEntity();
PlanUseEntity.PurLineIdObject = pbd.MrLineId;//目标采购计划行
PlanUseEntity.PurLineIdSource = ultraGrid3.Rows[j].Cells["MrLineId"].Value.ToString();//源采购计划行
PlanUseEntity.Status = "1";//状态1:领用中2:已领用9:已取消
PlanUseEntity.InvOrQty = bQTYLJHTemp;//占用量
PlanUseEntity.Validflag = "1";
PlanUseEntity.UpdateTime = System.DateTime.Now;
PlanUseEntity.UpdateName = UserInfo.GetUserName();
PlanUseEntity.UpdateUserid = UserInfo.GetUserID();
alpbdsu.Add(PlanUseEntity);
//}
}
//}
}
if (alpbd.Count < 1)
{
MessageUtil.ShowTips("利计划条件不符,未进行利库操作");
return;
}
CoreResult crt = this.execute("com.hnshituo.pur.purplan.service.PurPlanMService", "PlanBenefit", new object[] { alpbd, alpbds, alpbdsu });
if (crt.Resultcode != 0)
{
MessageUtil.ShowTips("利计划失败 " + crt.Resultmsg);
return;
}
MessageUtil.ShowTips("利计划成功");
}
///
/// 输入利库量
///
///
///
private void ultraGrid3_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
{
validate_New(sender, e);
//validate(sender, e);
}
///
/// 验证利库数量,当每次修改输入的利库量时使用
///
///
///
private void validate_New(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
{
//输入的利计划量不能>预采可分配量
if (e.Cell.Column.Key == "QTYLJHTemp")
{
//---------------------计算源采购计划
double num = 0; //利计划量
if (e.Cell.Value != null && e.Cell.Value.ToString() != "")
{
double.TryParse(e.Cell.Value.ToString(), out num);
}
ultraGrid3.UpdateData();//更新输入的利计划量
double numNew = 0; //利计划量
if (e.Cell.Value != null && e.Cell.Value.ToString() != "")
{
double.TryParse(e.Cell.Value.ToString(), out numNew);
}
double bQTYYCUSEABLE = 0;//预采可分配量
if (e.Cell.Row.Cells["QTYYCUSEABLE"].Value != null && e.Cell.Row.Cells["QTYYCUSEABLE"].Value.ToString() != "")
{
double.TryParse(e.Cell.Row.Cells["QTYYCUSEABLE"].Value.ToString(), out bQTYYCUSEABLE);
}
double bQTYLJHLast = 0;//上次利计划量
if (e.Cell.Row.Cells["QTYLJHLast"].Value != null && e.Cell.Row.Cells["QTYLJHLast"].Value.ToString() != "")
{
double.TryParse(e.Cell.Row.Cells["QTYLJHLast"].Value.ToString(), out bQTYLJHLast);
}
//-----------------计算目标采购计划
double Purnum = 0; //采购行新利计划量
for (int i = 0; i < ultraGrid3.Rows.Count; i++)
{
if (ultraGrid3.Rows[i].Hidden == false)
{
if (ultraGrid3.Rows[i].Cells["QTYLJHTemp"].Value != null && ultraGrid3.Rows[i].Cells["QTYLJHTemp"].Value.ToString() != "")
{
Purnum += double.Parse(ultraGrid3.Rows[i].Cells["QTYLJHTemp"].Value.ToString());
}
}
}
double bQTYLJH = 0;//采购行原利库量
if (ultraGrid2.ActiveRow.Cells["QTYLJH"].Value != null && ultraGrid2.ActiveRow.Cells["QTYLJH"].Value.ToString() != "")
{
double.TryParse(ultraGrid2.ActiveRow.Cells["QTYLJH"].Value.ToString(), out bQTYLJH);
}
double bQTYLK = 0;//采购行利库量
if (ultraGrid2.ActiveRow.Cells["QTYLK"].Value != null && ultraGrid2.ActiveRow.Cells["QTYLK"].Value.ToString() != "")
{
double.TryParse(ultraGrid2.ActiveRow.Cells["QTYLK"].Value.ToString(), out bQTYLK);
}
double bQTY = 0;//采购数量
if (ultraGrid2.ActiveRow.Cells["QTY"].Value != null && ultraGrid2.ActiveRow.Cells["QTY"].Value.ToString() != "")
{
double.TryParse(ultraGrid2.ActiveRow.Cells["QTY"].Value.ToString(), out bQTY);
}
if (numNew > bQTYYCUSEABLE + bQTYLJHLast || Purnum > bQTY + bQTYLJH)
{
//MessageUtil.ShowTips("已结算量必须小于入库量才能选择结算");
e.Cell.Value = num;
return;
}
else
{
ultraGrid2.ActiveRow.Cells["QTYLJH"].Value = Purnum;//利计划
ultraGrid2.ActiveRow.Cells["QTY"].Value = bQTY + bQTYLJH - Purnum;//采购数量=采购数量+(新利计划量-原来利计划量)
ultraGrid3.UpdateData();
ultraGrid2.UpdateData();
}
}
}
}
}