frmPurMat.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using Core.Mes.Client.Comm.Server;
  2. using Core.Mes.Client.Comm.Tool;
  3. using Core.StlMes.Client.PnCost.Models;
  4. using CoreFS.CA06;
  5. using Infragistics.Win.UltraWinTree;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Windows.Forms;
  14. namespace Core.StlMes.Client.PnCost
  15. {
  16. public partial class frmPurMat : FrmBase
  17. {
  18. #region 定义变量
  19. public frmPurMat(OpeBase ob)
  20. {
  21. InitializeComponent();
  22. this.ob = ob;
  23. }
  24. private string matCode = "";
  25. public string MatCode
  26. {
  27. get { return matCode; }
  28. set { matCode = value; }
  29. }
  30. private string matName = "";
  31. public string MatName
  32. {
  33. get { return matName; }
  34. set { matName = value; }
  35. }
  36. #endregion
  37. #region 初始化
  38. private void frmPurMat_Load(object sender, EventArgs e)
  39. {
  40. ultraCheckEditor1.Checked = false;
  41. ultraTextEditor1.Enabled = false;
  42. Query("first");
  43. EntityHelper.ShowGridCaption<PurMatEntity>(ultraGrid1.DisplayLayout.Bands[0]);
  44. }
  45. #endregion
  46. #region 方法
  47. private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
  48. {
  49. switch (e.Tool.Key)
  50. {
  51. case "确定":
  52. Right();
  53. break;
  54. case "query":
  55. Query("again");
  56. break;
  57. case "关闭":
  58. this.Close();
  59. break;
  60. }
  61. }
  62. /// 查询方法
  63. /// <summary>
  64. /// 查询方法
  65. /// </summary>
  66. private void Query(string flag)
  67. {
  68. //物料描述
  69. string strPei = "";
  70. if (ultraCheckEditor1.Checked)//物料描述是否选择
  71. {
  72. if (ultraTextEditor1.Text == "")//物料描述是否输入
  73. {
  74. MessageUtil.ShowWarning("请输入物料描述!");
  75. return;
  76. }
  77. else
  78. {
  79. strPei = ultraTextEditor1.Text.Trim();//物料描述
  80. }
  81. }
  82. if (flag == "first")
  83. {
  84. DataTable dt = ServerHelper.GetData("com.steering.pss.pncost.base.ComBaseMetalGrade.queryHejin", new object[] { }, ob);
  85. Bind_Tv(dt, ultraTree1.Nodes, null, "BASECODE", "PARENTCODE", "BASENAME");
  86. }
  87. else
  88. {
  89. if (strPei=="")
  90. {
  91. if (MessageUtil.ShowYesNoAndQuestion("要查询的数据过大,是否先输入物料描述?") == System.Windows.Forms.DialogResult.Yes)
  92. {
  93. return;
  94. }
  95. }
  96. List<PurMatEntity> data = EntityHelper.GetData<PurMatEntity>(
  97. "com.steering.pss.pncost.base.ComBaseMetalGrade.queryPurNew", new object[] { strPei }, ob);
  98. purMatEntityBindingSource.DataSource = data;
  99. if (ultraGrid1.Rows.Count == 0)
  100. {
  101. return;
  102. }
  103. this.ultraGrid1.Rows[0].Activate();
  104. }
  105. }
  106. /// 确定方法
  107. /// <summary>
  108. /// 确定方法
  109. /// </summary>
  110. private void Right()
  111. {
  112. if (ultraGrid1.Rows.Count == 0)
  113. {
  114. return;
  115. }
  116. if (ultraGrid1.ActiveRow == null)
  117. {
  118. MessageUtil.ShowWarning("请选择物料!");
  119. return;
  120. }
  121. if (ultraGrid1.ActiveRow != null)
  122. {
  123. matCode = ultraGrid1.ActiveRow.Cells["ITEMCODE"].Value.ToString();
  124. matName = ultraGrid1.ActiveRow.Cells["ITEMNAME"].Value.ToString();
  125. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  126. }
  127. }
  128. /// 绑定TreeView(利用TreeNodeCollection)
  129. /// <summary>
  130. /// 绑定TreeView(利用TreeNodeCollection)
  131. /// </summary>
  132. /// <param name="tnc">TreeNodeCollection(TreeView的节点集合)</param>
  133. /// <param name="pid_val">父id的值</param>
  134. /// <param name="id">数据库 id 字段名</param>
  135. /// <param name="pid">数据库 父id 字段名</param>
  136. /// <param name="text">数据库 文本 字段值</param>
  137. private void Bind_Tv(DataTable dt, TreeNodesCollection tnc, string pid_val, string id, string pid, string text)
  138. {
  139. DataView dv = new DataView(dt);//将DataTable存到DataView中,以便于筛选数据
  140. UltraTreeNode tn;//建立TreeView的节点(TreeNode),以便将取出的数据添加到节点中
  141. //以下为三元运算符,如果父id为空,则为构建“父id字段 is null”的查询条件,否则构建“父id字段=父id字段值”的查询条件
  142. string filter = string.IsNullOrEmpty(pid_val) ? pid + " is null" : string.Format(pid + "='{0}'", pid_val);
  143. dv.RowFilter = filter;//利用DataView将数据进行筛选,选出相同 父id值 的数据
  144. foreach (DataRowView drv in dv)
  145. {
  146. tn = new UltraTreeNode();//建立一个新节点(学名叫:一个实例)
  147. tn.Tag = drv[id].ToString();//节点的Value值,一般为数据库的id值
  148. tn.Text = drv[text].ToString();//节点的Text,节点的文本显示
  149. tnc.Add(tn);//将该节点加入到TreeNodeCollection(节点集合)中
  150. Bind_Tv(dt, tn.Nodes, tn.Tag.ToString(), id, pid, text);//递归(反复调用这个方法,直到把数据取完为止)
  151. }
  152. }
  153. #endregion
  154. #region 事件
  155. /// 标记事件
  156. /// <summary>
  157. /// 标记事件
  158. /// </summary>
  159. private void ultraTree1_AfterActivate(object sender, NodeEventArgs e)
  160. {
  161. string strChan = e.TreeNode.Tag.ToString2();
  162. List<PurMatEntity> data = EntityHelper.GetData<PurMatEntity>(
  163. "com.steering.pss.pncost.base.ComBaseMetalGrade.queryPur", new object[] { strChan }, ob);
  164. purMatEntityBindingSource.DataSource = data;
  165. if (ultraGrid1.Rows.Count == 0)
  166. {
  167. return;
  168. }
  169. this.ultraGrid1.Rows[0].Activate();
  170. }
  171. #endregion
  172. private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e)
  173. {
  174. ultraTextEditor1.Enabled = this.ultraCheckEditor1.Checked;
  175. }
  176. }
  177. }