FrmPopAttrs.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using CoreFS.CA06;
  10. using Pur.Entity;
  11. using Pur.Entity;
  12. using Pur.Entity.configureEntity;
  13. using Core.Mes.Client.Comm.Control;
  14. using com.hnshituo.pur.vo;
  15. using Core.Mes.Client.Comm.Tool;
  16. using Infragistics.Win.UltraWinGrid;
  17. using System.Collections;
  18. using Core.Mes.Client.Comm.Server;
  19. namespace Pur.Pop_upWindow
  20. {
  21. public partial class FrmPopAttrs : FrmPmsBase
  22. {
  23. public string QstrItemAttrCode = "";//属性编码
  24. public string QstrItemAttr = "";//属性名称
  25. public string QstrItemAttrClass = "";//属性分类编码
  26. public string QstrItemAttrClassName = "";//属性分类名称
  27. public string[,] QstrAttr = null;//保存所选属性
  28. public string[,] QstrAttrCode = null;//保存所选属性
  29. public FrmPopAttrs(OpeBase ob)
  30. {
  31. InitializeComponent();
  32. this.ob = ob;
  33. GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], "Check");
  34. }
  35. /// <summary>
  36. /// 刷新操作
  37. /// </summary>
  38. private void doQuery()
  39. {
  40. //查询按钮就当刷新功能。
  41. bandTreeView();
  42. }
  43. /// <summary>
  44. /// 树控件绑定数据源
  45. /// </summary>
  46. public void bandTreeView()
  47. {
  48. ArrayList parms = new ArrayList();
  49. //DataTable treeViewdt = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreAttrs.getTreeData", new Object[] { parms }, this.ob);
  50. //binUltraGrid("2001");
  51. treeView1.Nodes.Clear();
  52. DataTable dt = new DataTable();
  53. dt = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreAttrs.getTreeData", new Object[] { parms }, this.ob);
  54. //树控件递归绑定方法。
  55. Bind_Tv(dt, treeView1.Nodes, null, "BASECODE", "SORTCODE", "BASENAME");
  56. treeView1.Nodes[0].Expand();
  57. //初始化二位数组
  58. QstrAttr = new string[treeView1.Nodes[0].Nodes.Count, 2];
  59. QstrAttrCode = new string[treeView1.Nodes[0].Nodes.Count, 2];
  60. for (int i = 0; i < treeView1.Nodes[0].Nodes.Count; i++)
  61. {
  62. QstrAttr[i, 0] = treeView1.Nodes[0].Nodes[i].Text;
  63. QstrAttrCode[i, 0] = treeView1.Nodes[0].Nodes[i].Tag.ToString();
  64. }
  65. }
  66. /// <summary>
  67. /// 绑定TreeView(利用TreeNodeCollection)
  68. /// </summary>
  69. /// <param name="tnc">TreeNodeCollection(TreeView的节点集合)</param>
  70. /// <param name="pid_val">父id的值</param>
  71. /// <param name="id">数据库 id 字段名</param>
  72. /// <param name="pid">数据库 父id 字段名</param>
  73. /// <param name="text">数据库 文本 字段值</param>
  74. private void Bind_Tv(DataTable dt, TreeNodeCollection tnc, string pid_val, string id, string pid, string text)
  75. {
  76. DataView dv = new DataView(dt);//将DataTable存到DataView中,以便于筛选数据
  77. TreeNode tn;//建立TreeView的节点(TreeNode),以便将取出的数据添加到节点中
  78. //以下为三元运算符,如果父id为空,则为构建“父id字段 is null”的查询条件,否则构建“父id字段=父id字段值”的查询条件
  79. string filter = string.IsNullOrEmpty(pid_val) ? pid + " is null" : string.Format(pid + "='{0}'", pid_val);
  80. dv.RowFilter = filter;//利用DataView将数据进行筛选,选出相同 父id值 的数据
  81. foreach (DataRowView drv in dv)
  82. {
  83. tn = new TreeNode();//建立一个新节点(学名叫:一个实例)
  84. tn.Tag = drv[id].ToString();//节点的Value值,一般为数据库的id值
  85. tn.Text = drv[text].ToString();//节点的Text,节点的文本显示
  86. tnc.Add(tn);//将该节点加入到TreeNodeCollection(节点集合)中
  87. Bind_Tv(dt, tn.Nodes, tn.Tag.ToString(), id, pid, text);//递归(反复调用这个方法,直到把数据取完为止)
  88. }
  89. }
  90. /// <summary>
  91. /// 按钮控件
  92. /// </summary>
  93. /// <param name="sender"></param>
  94. /// <param name="e"></param>
  95. private void barsManagerButon_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
  96. {
  97. switch (e.Tool.Key.ToString())
  98. {
  99. case "conFirmation":
  100. {
  101. if (ultraGrid1.ActiveRow != null)
  102. {
  103. if (ultraGrid1.ActiveRow == null || ultraGrid1.ActiveRow.Hidden == true)
  104. {
  105. MessageUtil.ShowTips("请选择一条数据");
  106. return;
  107. }
  108. QstrItemAttr = ultraGrid1.ActiveRow.Cells["BASENAME"].Value.ToString();//lbAttrs.Text;
  109. QstrItemAttrCode = ultraGrid1.ActiveRow.Cells["BASECODE"].Value.ToString();//lbAttrCode.Text;
  110. QstrItemAttrClass = treeView1.SelectedNode.Tag.ToString();//属性分类编码
  111. QstrItemAttrClassName = treeView1.SelectedNode.Text.ToString(); ;//属性分类名称
  112. this.Close();
  113. }
  114. }
  115. break;
  116. case "ESC":
  117. {
  118. this.Close();
  119. }
  120. break;
  121. }
  122. }
  123. /// <summary>
  124. /// terrView1选择内容更改时触发。
  125. /// </summary>
  126. /// <param name="sender"></param>
  127. /// <param name="e"></param>
  128. private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
  129. {
  130. try
  131. {
  132. this.Cursor = Cursors.WaitCursor;
  133. //给编辑区域控件赋值。
  134. //基础分类编码
  135. //txtCodePart1.Text = e.Node.Tag.ToString();
  136. //快速检索码
  137. //txtSCode.Text = e.Node.Tag.ToString();
  138. //刷新Grid数据源,将父节点等于当前选中节点的数据全部取出来,构建数据源。
  139. //parentCode = e.Node.Tag.ToString();
  140. binUltraGrid(e.Node.Tag.ToString());
  141. }
  142. finally
  143. {
  144. this.Cursor = Cursors.Default;
  145. }
  146. }
  147. /// <summary>
  148. /// 刷新Grid数据源
  149. /// </summary>
  150. /// <param name="basecode"></param>
  151. private void binUltraGrid(string basecode)
  152. {
  153. this.dataTable1.Clear();
  154. DataTable dt = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreAttrs.doQuery", new Object[] { basecode }, this.ob);
  155. GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
  156. //不同颜色区分是否有效数据
  157. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  158. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  159. {
  160. row = ultraGrid1.Rows[i];
  161. if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1"))
  162. {
  163. row.Appearance.ForeColor = Color.Red;
  164. }
  165. else
  166. {
  167. row.Appearance.ForeColor = Color.Black;
  168. }
  169. }
  170. //内容自适应
  171. GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid1, new UltraGridColumn[] {
  172. ultraGrid1.DisplayLayout.Bands[0].Columns["MEMO"]
  173. });
  174. }
  175. /// <summary>
  176. /// 界面初始化
  177. /// </summary>
  178. /// <param name="sender"></param>
  179. /// <param name="e"></param>
  180. private void FrmPopAttrs_Load(object sender, EventArgs e)
  181. {
  182. doQuery();
  183. }
  184. /// <summary>
  185. /// 选择属性事件
  186. /// </summary>
  187. /// <param name="sender"></param>
  188. /// <param name="e"></param>
  189. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  190. {
  191. ultraGrid1.UpdateData();
  192. if ((bool)e.Cell.Value)
  193. {
  194. //设置单选
  195. foreach (UltraGridRow ugr in ultraGrid1.Rows)
  196. {
  197. if ((bool)ugr.Cells["Check"].Value)
  198. {
  199. if (ugr != e.Cell.Row)
  200. {
  201. ugr.Cells["Check"].Value = false;
  202. break;
  203. }
  204. }
  205. }
  206. //保存属性
  207. for (int i = 0; i < QstrAttr.GetLength(0); i++)
  208. {
  209. if (QstrAttr[i, 0] == treeView1.SelectedNode.Text)
  210. {
  211. QstrAttr[i, 1] = e.Cell.Row.Cells["BASENAME"].Value.ToString();
  212. QstrAttrCode[i, 1] = e.Cell.Row.Cells["BASECODE"].Value.ToString();
  213. break;
  214. }
  215. }
  216. }
  217. else//取消勾选
  218. {
  219. for (int i = 0; i < QstrAttr.GetLength(0); i++)
  220. {
  221. if (QstrAttr[i, 1] == e.Cell.Row.Cells["BASENAME"].Value.ToString())
  222. {
  223. QstrAttr[i, 1] = "";
  224. QstrAttrCode[i, 1] = "";
  225. break;
  226. }
  227. }
  228. }
  229. //显示所选属性
  230. lbAttrs.Text = "";
  231. lbAttrCode.Text = "";
  232. for (int i = 0; i < QstrAttr.GetLength(0); i++)
  233. {
  234. lbAttrs.Text+= QstrAttr[i, 1];
  235. lbAttrCode.Text += QstrAttrCode[i, 1];
  236. if (!string.IsNullOrEmpty(QstrAttr[i, 1]))
  237. {
  238. lbAttrs.Text += ";";
  239. lbAttrCode.Text += ";";
  240. }
  241. }
  242. if (!string.IsNullOrEmpty(lbAttrs.Text))
  243. {
  244. lbAttrs.Text = lbAttrs.Text.Remove(lbAttrs.Text.Length - 1);
  245. lbAttrCode.Text = lbAttrCode.Text.Remove(lbAttrCode.Text.Length - 1);
  246. }
  247. }
  248. }
  249. }