| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- 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 Pur.Entity.configureEntity;
- using Core.Mes.Client.Comm.Control;
- using com.hnshituo.pur.vo;
- using Core.Mes.Client.Comm.Tool;
- using Infragistics.Win.UltraWinGrid;
- using System.Collections;
- using Core.Mes.Client.Comm.Server;
- namespace Pur.Pop_upWindow
- {
- public partial class FrmPopAttrs : FrmPmsBase
- {
- public string QstrItemAttrCode = "";//属性编码
- public string QstrItemAttr = "";//属性名称
- public string QstrItemAttrClass = "";//属性分类编码
- public string QstrItemAttrClassName = "";//属性分类名称
-
- public string[,] QstrAttr = null;//保存所选属性
- public string[,] QstrAttrCode = null;//保存所选属性
- public FrmPopAttrs(OpeBase ob)
- {
- InitializeComponent();
- this.ob = ob;
- GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], "Check");
- }
- /// <summary>
- /// 刷新操作
- /// </summary>
- private void doQuery()
- {
- //查询按钮就当刷新功能。
- bandTreeView();
- }
- /// <summary>
- /// 树控件绑定数据源
- /// </summary>
- public void bandTreeView()
- {
- ArrayList parms = new ArrayList();
- //DataTable treeViewdt = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreAttrs.getTreeData", new Object[] { parms }, this.ob);
- //binUltraGrid("2001");
- treeView1.Nodes.Clear();
- DataTable dt = new DataTable();
- dt = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreAttrs.getTreeData", new Object[] { parms }, this.ob);
- //树控件递归绑定方法。
- Bind_Tv(dt, treeView1.Nodes, null, "BASECODE", "SORTCODE", "BASENAME");
- treeView1.Nodes[0].Expand();
- //初始化二位数组
- QstrAttr = new string[treeView1.Nodes[0].Nodes.Count, 2];
- QstrAttrCode = new string[treeView1.Nodes[0].Nodes.Count, 2];
- for (int i = 0; i < treeView1.Nodes[0].Nodes.Count; i++)
- {
- QstrAttr[i, 0] = treeView1.Nodes[0].Nodes[i].Text;
- QstrAttrCode[i, 0] = treeView1.Nodes[0].Nodes[i].Tag.ToString();
- }
- }
- /// <summary>
- /// 绑定TreeView(利用TreeNodeCollection)
- /// </summary>
- /// <param name="tnc">TreeNodeCollection(TreeView的节点集合)</param>
- /// <param name="pid_val">父id的值</param>
- /// <param name="id">数据库 id 字段名</param>
- /// <param name="pid">数据库 父id 字段名</param>
- /// <param name="text">数据库 文本 字段值</param>
- private void Bind_Tv(DataTable dt, TreeNodeCollection tnc, string pid_val, string id, string pid, string text)
- {
- DataView dv = new DataView(dt);//将DataTable存到DataView中,以便于筛选数据
- TreeNode tn;//建立TreeView的节点(TreeNode),以便将取出的数据添加到节点中
- //以下为三元运算符,如果父id为空,则为构建“父id字段 is null”的查询条件,否则构建“父id字段=父id字段值”的查询条件
- string filter = string.IsNullOrEmpty(pid_val) ? pid + " is null" : string.Format(pid + "='{0}'", pid_val);
- dv.RowFilter = filter;//利用DataView将数据进行筛选,选出相同 父id值 的数据
- foreach (DataRowView drv in dv)
- {
- tn = new TreeNode();//建立一个新节点(学名叫:一个实例)
- tn.Tag = drv[id].ToString();//节点的Value值,一般为数据库的id值
- tn.Text = drv[text].ToString();//节点的Text,节点的文本显示
- tnc.Add(tn);//将该节点加入到TreeNodeCollection(节点集合)中
- Bind_Tv(dt, tn.Nodes, tn.Tag.ToString(), id, pid, text);//递归(反复调用这个方法,直到把数据取完为止)
- }
- }
- /// <summary>
- /// 按钮控件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void barsManagerButon_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
- {
- switch (e.Tool.Key.ToString())
- {
- case "conFirmation":
- {
- if (ultraGrid1.ActiveRow != null)
- {
- if (ultraGrid1.ActiveRow == null || ultraGrid1.ActiveRow.Hidden == true)
- {
- MessageUtil.ShowTips("请选择一条数据");
- return;
- }
- QstrItemAttr = ultraGrid1.ActiveRow.Cells["BASENAME"].Value.ToString();//lbAttrs.Text;
- QstrItemAttrCode = ultraGrid1.ActiveRow.Cells["BASECODE"].Value.ToString();//lbAttrCode.Text;
- QstrItemAttrClass = treeView1.SelectedNode.Tag.ToString();//属性分类编码
- QstrItemAttrClassName = treeView1.SelectedNode.Text.ToString(); ;//属性分类名称
- this.Close();
- }
- }
- break;
- case "ESC":
- {
- this.Close();
- }
- break;
- }
- }
- /// <summary>
- /// terrView1选择内容更改时触发。
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
- {
- try
- {
- this.Cursor = Cursors.WaitCursor;
- //给编辑区域控件赋值。
- //基础分类编码
- //txtCodePart1.Text = e.Node.Tag.ToString();
- //快速检索码
- //txtSCode.Text = e.Node.Tag.ToString();
- //刷新Grid数据源,将父节点等于当前选中节点的数据全部取出来,构建数据源。
- //parentCode = e.Node.Tag.ToString();
- binUltraGrid(e.Node.Tag.ToString());
- }
- finally
- {
- this.Cursor = Cursors.Default;
- }
- }
- /// <summary>
- /// 刷新Grid数据源
- /// </summary>
- /// <param name="basecode"></param>
- private void binUltraGrid(string basecode)
- {
- this.dataTable1.Clear();
- DataTable dt = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreAttrs.doQuery", new Object[] { basecode }, this.ob);
-
- GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
- //不同颜色区分是否有效数据
- Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
- for (int i = 0; i < ultraGrid1.Rows.Count; i++)
- {
- row = ultraGrid1.Rows[i];
- if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1"))
- {
- row.Appearance.ForeColor = Color.Red;
- }
- else
- {
- row.Appearance.ForeColor = Color.Black;
- }
- }
- //内容自适应
- GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid1, new UltraGridColumn[] {
- ultraGrid1.DisplayLayout.Bands[0].Columns["MEMO"]
- });
- }
- /// <summary>
- /// 界面初始化
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void FrmPopAttrs_Load(object sender, EventArgs e)
- {
- doQuery();
- }
- /// <summary>
- /// 选择属性事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ultraGrid1_CellChange(object sender, CellEventArgs e)
- {
- ultraGrid1.UpdateData();
- if ((bool)e.Cell.Value)
- {
- //设置单选
- foreach (UltraGridRow ugr in ultraGrid1.Rows)
- {
- if ((bool)ugr.Cells["Check"].Value)
- {
- if (ugr != e.Cell.Row)
- {
- ugr.Cells["Check"].Value = false;
- break;
- }
- }
- }
- //保存属性
- for (int i = 0; i < QstrAttr.GetLength(0); i++)
- {
- if (QstrAttr[i, 0] == treeView1.SelectedNode.Text)
- {
- QstrAttr[i, 1] = e.Cell.Row.Cells["BASENAME"].Value.ToString();
- QstrAttrCode[i, 1] = e.Cell.Row.Cells["BASECODE"].Value.ToString();
- break;
- }
- }
- }
- else//取消勾选
- {
- for (int i = 0; i < QstrAttr.GetLength(0); i++)
- {
- if (QstrAttr[i, 1] == e.Cell.Row.Cells["BASENAME"].Value.ToString())
- {
- QstrAttr[i, 1] = "";
- QstrAttrCode[i, 1] = "";
- break;
- }
- }
- }
- //显示所选属性
- lbAttrs.Text = "";
- lbAttrCode.Text = "";
- for (int i = 0; i < QstrAttr.GetLength(0); i++)
- {
- lbAttrs.Text+= QstrAttr[i, 1];
- lbAttrCode.Text += QstrAttrCode[i, 1];
- if (!string.IsNullOrEmpty(QstrAttr[i, 1]))
- {
- lbAttrs.Text += ";";
- lbAttrCode.Text += ";";
- }
- }
- if (!string.IsNullOrEmpty(lbAttrs.Text))
- {
- lbAttrs.Text = lbAttrs.Text.Remove(lbAttrs.Text.Length - 1);
- lbAttrCode.Text = lbAttrCode.Text.Remove(lbAttrCode.Text.Length - 1);
- }
- }
- }
- }
|