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 Infragistics.Win.UltraWinGrid;
using Infragistics.Win;
using CoreFS.CA06;
using Pur.Entity;
using Core.Mes.Client.Comm.Control;
using Core.Mes.Client.Comm;
using Core.Mes.Client.Comm.Tool;
using Pur.Entity.configureEntity;
using Infragistics.Win.UltraWinTree;
using Core.Mes.Client.Comm.Server;
using Pur.Pop_upWindow;
using com.hnshituo.pur.vo;
using Pur.configure;
using System.Collections;
using Infragistics.Win.UltraWinToolTip;
using Pur.require_plan;
using Infragistics.Win.UltraWinEditors;
namespace Pur.Pop_upWindow
{
public partial class frmPopMatSelect : FrmPmsBase
{
String selectType = "0";//0:全选,1:单个选
private void frmPopMatSelect_Load(object sender, EventArgs e)
{
//初始化
cmbNum.SelectedIndex = 0;
GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], new string[] { "Check" });
if (selectType == "1")
{
GridHelper.HidenColumns(ultraGrid1.DisplayLayout.Bands[0], new string[] { "Check" });
}
//查询物料分类树
GetPUR_MAT_Class();
}
public frmPopMatSelect(OpeBase ob)
{
this.ob = ob;
InitializeComponent();
}
public frmPopMatSelect(OpeBase ob,String strType)
{
this.selectType = strType;
this.ob = ob;
InitializeComponent();
}
Boolean QClickCellOrQuery = false;//是否点击查询按钮或grid数据单元格,控制是否刷新右侧物料数据,true为不刷新
DataTable dt_Purmatclass = null;
private string QstrItemUnique = "";
UltraTreeNode qUltraNode = null;
public ArrayList List_item=new ArrayList();
public String selectedItemCode="";
public String SelectedItemName="";
public string tips="0";
///
/// 查询物料分类和物料
///
public void GetPUR_MAT_Class()
{
//查询物料分类
PurmatclassEntity matclassEntity = new PurmatclassEntity();
matclassEntity.Validflag="1";
DataTable dt = this.execute("com.hnshituo.pur.configure.service.MatClassService", "getMatClass", new object[] { matclassEntity });
dt_Purmatclass = dt;
getultree(dt);//绑定物料分类表
//查询物料
MatEntity mat = new MatEntity();
mat.Validflag = "1";
//物料分类
if (checkBox1.Checked)
{
mat.UpdateName = txt_ARC_CODE.Text;
}
mat.ItemCode = txt_wlbm.Text;
mat.DeleteName = txt_wlmc.Text;
getMat(mat);
}
///
/// 获取物料分类树形结构
///
public void getultree(DataTable dt)
{
ulTreeMat.Nodes.Clear();
if (dt == null || dt.Rows.Count < 1)
{
return;
}
dt_Purmatclass = dt;//保存物料分类全局变量
DataTable dt_A = new DataTable();//物料分类
//筛选出根节点
DataRow[] rows = dt.Select("PARENTCODE='' or PARENTCODE is null");
dt_A = dt.Clone(); //克隆A的结构
foreach (DataRow row in rows)
{
dt_A.ImportRow(row);//复制行数据
}
//添加物料大类
for (int j = 0; j < dt_A.Rows.Count; j++)
{
UltraTreeNode Ultnode = ulTreeMat.Nodes.Add(dt_A.Rows[j]["BASECODE"].ToString(), dt_A.Rows[j]["BASENAME"].ToString());
getChildNodes(Ultnode);
}
}
///
/// 查询物料
///
private void getMat(MatEntity mat)
{
if (mat != null)
{
if (cmbNum.Value != null && cmbNum.Value.ToString() != "")
{
mat.ItemUomConefficient = double.Parse(cmbNum.Value.ToString());
}
}
DataTable dt_mat = this.execute("com.hnshituo.pur.configure.service.MatService", "getMat", new object[] { mat });
dataTable1.Rows.Clear();
GridHelper.CopyDataToDatatable(ref dt_mat, ref dataTable2, true);//绑定物料分类表
}
///
/// 递归查询父节点下的所有子节点
///
///
public void getChildNodes(UltraTreeNode Tnode)
{
DataTable dt_A = dt_Purmatclass.Clone();//物料分类
DataRow[] rows = dt_Purmatclass.Select("PARENTCODE='" + Tnode.Key + "'");
foreach (DataRow row in rows)
{
dt_A.ImportRow(row);//复制行数据
}
//添加物料分类
for (int j = 0; j < dt_A.Rows.Count; j++)
{
UltraTreeNode Ultnode = Tnode.Nodes.Add(dt_A.Rows[j]["BASECODE"].ToString(), dt_A.Rows[j]["BASENAME"].ToString());
getChildNodes(Ultnode);//利用递归将当前节点的子节点添加进去
}
}
private void ulTreeMat_AfterActivate(object sender, NodeEventArgs e)
{
if (!QClickCellOrQuery)//如果不是点击查询按钮或单击grig行数据,刷新右侧数据
{
MatEntity eMat = new MatEntity();
ulTreeMat.ActiveNode.Expanded = true;
qUltraNode = ulTreeMat.ActiveNode;
eMat.ArcCode = qUltraNode.Key;
eMat.Validflag = "1";
getMat(eMat);
}
txt_ARC_CODE.Text = ulTreeMat.ActiveNode.Key;
txt_ARC_ITEM.Text = ulTreeMat.ActiveNode.Text;
}
private void barsManagerButon_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
{
switch (e.Tool.Key.ToString())
{
case "Query":
{
QClickCellOrQuery = true;
GetPUR_MAT_Class();
if (ultraGrid1.Rows.Count > 0)
{
ulTreeMat.CollapseAll();
UltraTreeNode uttNode = ulTreeMat.GetNodeByKey(ultraGrid1.Rows[0].Cells["ARCCODE"].Value.ToString());
ulTreeMat.ActiveNode = uttNode;
if (uttNode == null)
{
MessageUtil.ShowTips("物料名称:" + ultraGrid1.Rows[0].Cells["ITEMNAME"].Value.ToString() + " 未找到相应的分类:" + ultraGrid1.Rows[0].Cells["ARCCODE"].Value.ToString());
}
else
{
while (ulTreeMat.ActiveNode != uttNode)
{
ulTreeMat.ActiveNode = uttNode;
}
uttNode.Expanded = true;
//展开分类
while (uttNode.Parent != null)
{
uttNode = uttNode.Parent;
uttNode.Expanded = true;
}
}
QClickCellOrQuery = false;//设置未点击
}
}
break;
case "conFirmation":
{
if (selectType == "1")
{
selectedItemCode = ultraGrid1.ActiveRow.GetCellValue("itemCode").ToString().Trim();
SelectedItemName = ultraGrid1.ActiveRow.GetCellValue("itemName").ToString().Trim();
tips = "1";
this.Close();
return;
}
else
{
ultraGrid1.UpdateData();
IQueryable checkRows = ultraGrid1.Rows.AsQueryable().Where("Check = 'True' ");
if (checkRows.Count() <= 0)
{
MessageUtil.ShowTips("请选择物料!");
return;
}
else
{
foreach (UltraGridRow row in checkRows)
{
MatEntity mat = new MatEntity();
String itemCode = row.GetCellValue("itemCode").ToString().Trim();
mat.ItemCode = itemCode;
String itemName = row.GetCellValue("itemName").ToString().Trim();
mat.ItemName = itemName;
List_item.Add(mat);
}
}
if (List_item.Count <= 0)
{
MessageUtil.ShowTips("请选择物料!");
return;
}
tips = "1";
this.Close();
return;
}
}
case "ESC":
{
this.Close();
}
break;
}
}
///
/// 激活物料
///
///
///
private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
{
//激活之前选中项
string[] strItemUniques = QstrItemUnique.Split('@');
if (QstrItemUnique != "")
{
QClickCellOrQuery = true;//不刷新右侧物料数据
if (strItemUniques.Length == 4)
{
//选中属性
if (strItemUniques[1].Trim() != "")
{
//显示所选属性
strItemUniques[1] += ";";
strItemUniques[1] = ";" + strItemUniques[1];
}
}
QstrItemUnique = "";
QClickCellOrQuery = false;
}
}
///
/// 单击物料单元格
///
///
///
private void ultraGrid1_ClickCell(object sender, ClickCellEventArgs e)
{
UltraTreeNode uttNode = ulTreeMat.GetNodeByKey(e.Cell.Row.Cells["ARCCODE"].Value.ToString());
if (ulTreeMat.ActiveNode == uttNode)
{
return;
}
ulTreeMat.CollapseAll();
QClickCellOrQuery = true;
ulTreeMat.ActiveNode = uttNode;
if (uttNode == null)
{
MessageUtil.ShowTips("物料名称:" + e.Cell.Row.Cells["ITEMNAME"].Value.ToString() + " 未找到相应的分类:" + e.Cell.Row.Cells["ARCCODE"].Value.ToString());
}
else
{
while (ulTreeMat.ActiveNode != uttNode)
{
ulTreeMat.ActiveNode = uttNode;
}
uttNode.Expanded = true;
//展开分类
while (uttNode.Parent != null)
{
uttNode = uttNode.Parent;
uttNode.Expanded = true;
}
}
QClickCellOrQuery = false;//设置未点击
}
}
}