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 com.hnshituo.pur.vo;
using Core.Mes.Client.Comm.Control;
using Core.Mes.Client.Comm.Tool;
using CoreFS.CA06;using Pur.Entity;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using Pur.Entity.configureEntity;
using Pur.Entity.require_planEntiy;
using Pur.Pop_upWindow;
namespace Pur.require_plan
{
public partial class FrmRePlanChange : FrmPmsBase
{
//变量
public ArrayList list;//变更的需求行信息
public DataTable dtOld;//变更前数据备份
public DataTable dtNew;//变更后的数据备份
public FrmRePlanChange()
{
InitializeComponent();
}
public FrmRePlanChange(ArrayList List, OpeBase Ob)
{
InitializeComponent();
this.ob = Ob;
this.list = List;
}
private void FrmRePlanChange_Load(object sender, EventArgs e)
{
init();
}
///
/// 加载需要变更的数据
///
private void init()
{
//加载待编辑数据
if (list.Count > 0)
{
dtOld = this.execute("com.hnshituo.pur.requireplan.service.RequirePlanDService", "getJoinedByIds", new object[] { list });
GridHelper.CopyDataToDatatable(dtOld, dataTable1, true);
ultraGrid1.DisplayLayout.Bands[0].Override.AllowUpdate = DefaultableBoolean.False;
ultraGrid2.DisplayLayout.Bands[0].Override.AllowUpdate = DefaultableBoolean.False;
}
else
{
MessageUtil.ShowTips("无待修改数据");
}
}
///
/// 加载物料信息
///
///
///
private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
{
clearTab();
if (ultraGrid1.ActiveRow != null)
{
UltraGridRow uge = ultraGrid1.ActiveRow;
String strmatCode = uge.GetCellValue("itemCode").ToString();
txt_matCode.Text = strmatCode;
String strmatName = uge.GetCellValue("itemName").ToString();
txt_matName.Text = strmatName;
getItemAttr();//获取物料属性
getMatStandard();// 获取物料标准编号
getMatUOM();// 获取单位转换
string stritemUomId = uge.GetCellValue("itemUomId").ToString();
string stritemStandardsId = uge.GetCellValue("itemStandardsId").ToString();
string stritemAttrId = uge.GetCellValue("itemAttrId").ToString();
setGridCheck(ultraGrid5, "itemUomId", stritemUomId);
setGridCheck(ultraGrid3, "itemAttrId", stritemAttrId);
setGridCheck(ultraGrid4, "itemStandardsId", stritemStandardsId);
}
}
///
/// 清楚编辑区信息
///
private void clearTab()
{
txt_matCode.Text = "";
txt_matName.Text = "";
dataTable5.Clear();
dataTable6.Clear();
dataTable7.Clear();
}
///
/// 获取物料属性
///
///
private void getItemAttr()
{
dataTable5.Rows.Clear();
Dictionary param = new Dictionary();
param.Add("ItemCode", ultraGrid1.ActiveRow.Cells["ITEMCODE"].Value.ToString());
param.Add("Validflag", "1");
DataTable dt_mat = this.execute("com.hnshituo.pur.configure.service.MatAttrsService", "find", new object[] { param, 0, 0 });
GridHelper.CopyDataToDatatable(ref dt_mat, ref dataTable5, true);//获取物料属性
}
///
/// 获取物料标准编号
///
private void getMatStandard()
{
dataTable6.Rows.Clear();
if (ultraGrid1.ActiveRow != null)
{
PurMatStandardsEntity PurMatStandards_Entity = new PurMatStandardsEntity();
PurMatStandards_Entity.Validflag = "1";
PurMatStandards_Entity.ItemCode = ultraGrid1.ActiveRow.Cells["ITEMCODE"].Value.ToString();
DataTable dt_matStandards = this.execute("com.hnshituo.pur.configure.service.MatStandardsService", "find", new object[] { PurMatStandards_Entity, 0, 0 });
GridHelper.CopyDataToDatatable(ref dt_matStandards, ref dataTable6, true);//绑定物料规格
}
}
///
/// 获取单位转换
///
private void getMatUOM()
{
dataTable7.Rows.Clear();
if (ultraGrid1.ActiveRow != null)
{
PurMatUomsEntity MatUomsEntity = new PurMatUomsEntity();
MatUomsEntity.ItemCode = ultraGrid1.ActiveRow.Cells["ITEMCODE"].Value.ToString();
MatUomsEntity.Validflag = "1";
DataTable dt_matUOM = this.execute("com.hnshituo.pur.configure.service.MatUomsService", "find", new object[] { MatUomsEntity, 0, 0 });
GridHelper.CopyDataToDatatable(ref dt_matUOM, ref dataTable7, true);//绑定物料规格
}
}
///
/// 设置Check点击
///
///
///
///
private void setGridCheck(UltraGrid ultraGrid, string p, string stritemUomId)
{
foreach (UltraGridRow row in ultraGrid.Rows)
{
if (row.GetCellValue(p).ToString() == stritemUomId)
{
row.Cells["Check"].Value = true;
row.Activated = true;
}
else
{
row.Cells["Check"].Value = false;
row.Activated = false;
}
}
}
///
/// ultraGrid3的Check选择事件1
///
///
///
private void ultraGrid3_CellChange(object sender, CellEventArgs e)
{
foreach (UltraGridRow row in ultraGrid3.Rows)
{
if (row == e.Cell.Row)
{
row.Cells["Check"].Value = true;
}
else
{
row.Cells["Check"].Value = false;
}
}
ultraGrid3.UpdateData();
}
///
/// ultraGrid4的Check选择事件1
///
///
///
private void ultraGrid4_CellChange(object sender, CellEventArgs e)
{
foreach (UltraGridRow row in ultraGrid4.Rows)
{
if (row == e.Cell.Row)
{
row.Cells["Check"].Value = true;
}
else
{
row.Cells["Check"].Value = false;
}
}
ultraGrid4.UpdateData();
}
///
/// ultraGrid5的Check选择事件1
///
///
///
private void ultraGrid5_CellChange(object sender, CellEventArgs e)
{
foreach (UltraGridRow row in ultraGrid5.Rows)
{
if (row == e.Cell.Row)
{
row.Cells["Check"].Value = true;
}
else
{
row.Cells["Check"].Value = false;
}
}
ultraGrid5.UpdateData();
}
private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
{
switch (e.Tool.Key)
{
case "doSure": // ButtonTool
doSure();
break;
case "doCancel": // ButtonTool
this.Close();
break;
case "doChage": // ButtonTool
doChange();
break;
}
}
///
///
///
private void doSure()
{
if (ultraGrid2.Rows.Count >= 1)
{
UltraGridRow uge=ultraGrid2.Rows[0];
RequirePlanD rd = new RequirePlanD();
rd.MrLineId = uge.GetCellValue("mrLineId").ToString().Trim();
rd.NewItemUnique=uge.GetCellValue("newItemUnique").ToString().Trim();
rd.NewItemUomId=uge.GetCellValue("newItemUomId").ToString().Trim();
rd.NewItemStandardsId=uge.GetCellValue("newItemStandardsId").ToString().Trim();
rd.NewItemStandardsCode=uge.GetCellValue("newItemStandardsCode").ToString().Trim();
rd.NewItemAttrId=uge.GetCellValue("newItemAttrId").ToString().Trim();
rd.ItemAttr=uge.GetCellValue("itemAttr").ToString().Trim();
rd.WeightUnit=uge.GetCellValue("weightUnit").ToString().Trim();
rd.ItemUomConefficient=Convert.ToDouble(uge.GetCellValue("itemUomConefficient"));
rd.ItemUom=uge.GetCellValue("itemUom").ToString().Trim();
rd.UpdateName = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName();
rd.UpdateUserid = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID();
rd.UpdateTime = DateTime.Now;
if (MessageUtil.ShowYesNoAndQuestion("是否确定要修改?") == DialogResult.No)
{
return;
}
CoreResult rt = this.execute("com.hnshituo.pur.requireplan.service.RequirePlanDService", "doUpdate", new object[] { rd });
if (rt.Resultcode != 0)
{
MessageUtil.ShowTips("修改失败!" + rt.Resultmsg);
return;
}
else
{
MessageUtil.ShowTips("修改成功!" + rt.Resultmsg);
this.Close();
return;
}
}
else
{
MessageUtil.ShowTips("无待提交的修改数据");
return;
}
}
///
///
///
private void doChange()
{
if (ultraGrid1.ActiveRow == null)
{
MessageUtil.ShowTips("请选择需要修改的行");
return;
}
ultraGrid3.UpdateData();
ultraGrid4.UpdateData();
ultraGrid5.UpdateData();
UltraGridRow uge3 = ultraGrid3.ActiveRow;//属性
UltraGridRow uge4 = ultraGrid4.ActiveRow;//标准编号
UltraGridRow uge5 = ultraGrid5.ActiveRow;//单位
String itemCode = ultraGrid1.ActiveRow.Cells["itemCode"].Value.ToString().Trim();
String itemUniqueOld = ultraGrid1.ActiveRow.Cells["itemUnique"].Value.ToString().Trim();
String newitemUniqueOld = ultraGrid1.ActiveRow.Cells["newItemUnique"].Value.ToString().Trim();
String itemAttrId="";
String itemStandardsId="";
String itemUomId="";
String itemAttr = "";
String itemAttrCode = "";
String standardsId = "";
String standardsCode = "";
String weightUnit="";
String weightUnitCode ="";
String itemUomConefficient = "";
String uomCode = "";
String uomName = "";
if (uge3 != null)//属性
{
itemAttr = uge3.Cells["itemAttr"].Value.ToString().Trim();
itemAttrCode = uge3.Cells["ITEMATTRCODE"].Value.ToString().Trim();
itemAttrId = uge3.Cells["itemAttrId"].Value.ToString().Trim();
}
if (uge4 != null)//标准编号
{
itemStandardsId = uge4.Cells["itemStandardsId"].Value.ToString().Trim();
standardsId = uge4.Cells["standardsId"].Value.ToString().Trim();
standardsCode = uge4.Cells["standardsCode"].Value.ToString().Trim();
}
if (uge5 != null)//采购单位
{
itemUomId = uge5.Cells["itemUomId"].Value.ToString().Trim();
weightUnit = uge5.Cells["weightUnit"].Value.ToString().Trim();
weightUnitCode = uge5.Cells["weightUnitCode"].Value.ToString().Trim();
itemUomConefficient = uge5.Cells["itemUomConefficient"].Value.ToString();
uomCode = uge5.Cells["uomCode"].Value.ToString().Trim();
uomName = uge5.Cells["uomName"].Value.ToString().Trim();
}
//所选物料唯一标识值
String ItemUnique = itemCode + itemAttrId + itemStandardsId + itemUomId;
if (itemUniqueOld == ItemUnique || newitemUniqueOld == ItemUnique)
{
MessageUtil.ShowTips("未发现有修改,请确定");
return;
}
DataTable dtOld1 = dtOld.Copy();
DataRow myDr = dtOld1.Rows[0];
myDr["newItemUnique"] = ItemUnique;
myDr["newItemUomId"] = itemUomId;
myDr["newItemStandardsId"] = itemStandardsId;
myDr["newItemStandardsCode"] = standardsCode;
myDr["newItemAttrId"] = itemAttrId;
myDr["itemAttr"] = itemAttr;
myDr["weightUnit"] = weightUnit;
myDr["itemUomConefficient"] = itemUomConefficient;
myDr["itemUom"] = uomName;
//删除重复行
if (dtNew == null)
{
dtNew = dtOld.Clone();
dtNew.Rows.Add(myDr.ItemArray);
}
else
{
if (dtNew.Rows.Count > 0)
{
for (int i = dtNew.Rows.Count - 1; i >= 0; i--)
{
if (dtNew.Rows[i]["itemUnique"] == myDr["itemUnique"])
{
dtNew.Rows.RemoveAt(i);
}
}
}
//加行
dtNew.Rows.Add(myDr.ItemArray);
}
GridHelper.CopyDataToDatatable(dtNew, dataTable2, true);
}
}
}