RuleGroupSelector.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. using DevExpress.XtraDiagram.Bars;
  2. using NPOI.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. namespace OTSIncAReportApp._1_UI.OTSReportExport
  14. {
  15. /// <summary>
  16. /// 规则分组选择器
  17. /// </summary>
  18. public partial class RuleGroupSelector: Form
  19. {
  20. private ContextMenuStrip contextMenuStrip1;
  21. public DataTable dt;
  22. public List<DataTable> List_RuleTable;
  23. //private DataTable RuleData = new DataTable();
  24. int listIndex = -1;
  25. DataTable BF_dataTable;
  26. List<DataTable> BF_List_RuleTable = new List<DataTable>();
  27. public RuleGroupSelector(DataTable a_dataTable, List<DataTable> a_List_RuleTable)
  28. {
  29. InitializeComponent();
  30. dt = a_dataTable.Copy();
  31. List_RuleTable = a_List_RuleTable.Copy();
  32. BF_dataTable = a_dataTable.Copy();
  33. for (int i = 0; i < a_List_RuleTable.Count; i++)
  34. {
  35. DataTable dta = a_List_RuleTable[i].Copy();
  36. BF_List_RuleTable.Add(dta);
  37. }
  38. }
  39. private void RuleGroupSelector_Load(object sender, EventArgs e)
  40. {
  41. checkedListBox1.Items.Clear();
  42. checkedListBox1.MouseDown += checkedListBox1_MouseDown;
  43. for (int i = 0; i < dt.Rows.Count; i++)
  44. {
  45. checkedListBox1.Items.Add(dt.Rows[i]["GroupName"]);
  46. }
  47. for (int i = 0; i < dt.Rows.Count; i++)
  48. {
  49. if (dt.Rows[i]["display"].ToString() == "0")
  50. {
  51. checkedListBox1.SetItemChecked(i, false);
  52. }
  53. else
  54. {
  55. checkedListBox1.SetItemChecked(i, true);
  56. }
  57. }
  58. }
  59. private void checkedListBox1_MouseDown(object sender, MouseEventArgs e)
  60. {
  61. if (e.Button == MouseButtons.Left)
  62. {
  63. for (int i = 0; i < checkedListBox2.Items.Count; i++)
  64. {
  65. if (checkedListBox2.GetItemChecked(i))
  66. {
  67. List_RuleTable[listIndex].Rows[i]["display"] = "1";
  68. }
  69. else
  70. {
  71. List_RuleTable[listIndex].Rows[i]["display"] = "0";
  72. }
  73. }
  74. // 获取点击位置的项索引
  75. int index = checkedListBox1.IndexFromPoint(e.Location);
  76. if (index == -1)
  77. { return; }
  78. listIndex = index;
  79. for (int i = 0; i < List_RuleTable.Count; i++)
  80. {
  81. if (dt.Rows[i]["GroupId"].ToString() == List_RuleTable[listIndex].TableName.ToString())
  82. {
  83. checkedListBox2.Items.Clear();
  84. for (int a = 0; a < List_RuleTable[listIndex].Rows.Count; a++)
  85. {
  86. checkedListBox2.Items.Add(List_RuleTable[listIndex].Rows[a]["StrName"]);
  87. }
  88. for (int a = 0; a < List_RuleTable[listIndex].Rows.Count; a++)
  89. {
  90. if (List_RuleTable[listIndex].Rows[a]["display"].ToString() == "0")
  91. {
  92. checkedListBox2.SetItemChecked(a, false);
  93. }
  94. else
  95. {
  96. checkedListBox2.SetItemChecked(a, true);
  97. }
  98. }
  99. }
  100. }
  101. }
  102. }
  103. private void button2_Click(object sender, EventArgs e)
  104. {
  105. dt.Clear();
  106. dt = BF_dataTable.Copy();
  107. List_RuleTable.Clear();
  108. for (int i = 0; i < BF_List_RuleTable.Count; i++)
  109. {
  110. DataTable table = BF_List_RuleTable[i].Copy();
  111. List_RuleTable.Add(table);
  112. }
  113. this.Close();
  114. }
  115. private void button1_Click(object sender, EventArgs e)
  116. {
  117. for (int i = 0; i < checkedListBox2.Items.Count; i++)
  118. {
  119. if (checkedListBox2.GetItemChecked(i))
  120. {
  121. List_RuleTable[listIndex].Rows[i]["display"] = "1";
  122. }
  123. else
  124. {
  125. List_RuleTable[listIndex].Rows[i]["display"] = "0";
  126. }
  127. }
  128. for (int i = 0; i < dt.Rows.Count; i++)
  129. {
  130. if (!checkedListBox1.GetItemChecked(i))
  131. {
  132. dt.Rows[i]["display"] = "0";
  133. }
  134. else
  135. {
  136. dt.Rows[i]["display"] = "1";
  137. }
  138. }
  139. this.Close();
  140. }
  141. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  142. {
  143. //CheckBox checkBox = sender as CheckBox;
  144. //// 根据CheckBox的状态设置CheckedListBox的所有项
  145. //for (int i = 0; i < checkedListBox1.Items.Count; i++)
  146. //{
  147. // checkedListBox1.SetItemChecked(i, checkBox.Checked);
  148. //}
  149. if (checkBox1.Checked)
  150. {
  151. for (int i = 0; i < List_RuleTable.Count; i++)
  152. {
  153. for (int a = 0; a < List_RuleTable[i].Rows.Count; a++)
  154. {
  155. List_RuleTable[i].Rows[a]["display"] = "1";
  156. }
  157. }
  158. for (int i = 0; i < checkedListBox1.Items.Count; i++)
  159. {
  160. checkedListBox1.SetItemChecked(i, true);
  161. }
  162. for (int i = 0; i < checkedListBox2.Items.Count; i++)
  163. {
  164. checkedListBox2.SetItemChecked(i, true);
  165. }
  166. }
  167. else
  168. {
  169. for (int i = 0; i < List_RuleTable.Count; i++)
  170. {
  171. for (int a = 0; a < List_RuleTable[i].Rows.Count; a++)
  172. {
  173. List_RuleTable[i].Rows[a]["display"] = "0";
  174. }
  175. }
  176. for (int i = 0; i < checkedListBox1.Items.Count; i++)
  177. {
  178. checkedListBox1.SetItemChecked(i, false);
  179. }
  180. for (int i = 0; i < checkedListBox2.Items.Count; i++)
  181. {
  182. checkedListBox2.SetItemChecked(i, false);
  183. }
  184. }
  185. }
  186. private void checkedListBox1_MouseClick(object sender, MouseEventArgs e)
  187. {
  188. }
  189. private void checkedListBox2_MouseDown(object sender, MouseEventArgs e)
  190. {
  191. if (e.Button == MouseButtons.Left)
  192. {
  193. // 获取点击位置的项索引
  194. int index = checkedListBox2.IndexFromPoint(e.Location);
  195. if (index == -1)
  196. return;
  197. //for (int i = 0; i < List_RuleTable[listIndex].Rows.Count; i++)
  198. //{
  199. if (checkedListBox2.GetItemChecked(index))
  200. {
  201. List_RuleTable[listIndex].Rows[index]["display"] = "0";
  202. }
  203. else
  204. {
  205. List_RuleTable[listIndex].Rows[index]["display"] = "1";
  206. }
  207. //}
  208. }
  209. }
  210. private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
  211. {
  212. // 获取当前操作的条目索引
  213. int index = e.Index;
  214. if(index==-1)
  215. return;
  216. if (listIndex == -1)
  217. return;
  218. if (!checkedListBox1.GetItemChecked(index))
  219. {
  220. for (int i = 0; i < List_RuleTable[listIndex].Rows.Count; i++)
  221. {
  222. checkedListBox2.Items.Clear();
  223. for (int a = 0; a < List_RuleTable[listIndex].Rows.Count; a++)
  224. {
  225. checkedListBox2.Items.Add(List_RuleTable[listIndex].Rows[a]["StrName"]);
  226. }
  227. for (int a = 0; a < List_RuleTable[listIndex].Rows.Count; a++)
  228. {
  229. List_RuleTable[listIndex].Rows[a]["display"] = "1";
  230. checkedListBox2.SetItemChecked(a, true);
  231. }
  232. }
  233. }
  234. else
  235. {
  236. for (int i = 0; i < List_RuleTable[listIndex].Rows.Count; i++)
  237. {
  238. checkedListBox2.Items.Clear();
  239. for (int a = 0; a < List_RuleTable[listIndex].Rows.Count; a++)
  240. {
  241. checkedListBox2.Items.Add(List_RuleTable[listIndex].Rows[a]["StrName"]);
  242. }
  243. for (int a = 0; a < List_RuleTable[listIndex].Rows.Count; a++)
  244. {
  245. List_RuleTable[listIndex].Rows[a]["display"] = "0";
  246. checkedListBox2.SetItemChecked(a, false);
  247. }
  248. }
  249. }
  250. }
  251. }
  252. }