frmSetEleCols.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. using System;
  2. using System.Collections;
  3. using System.Windows.Forms;
  4. using Core.StlMes.Client.LgCommon;
  5. using CoreFS.CA06;
  6. namespace Core.StlMes.Client.LgIntegrationQuery
  7. {
  8. public enum Direction
  9. {
  10. Up,
  11. Down,
  12. Left,
  13. Right
  14. }
  15. public partial class frmSetEleCols : Core.StlMes.Client.LgCommon.frmStyleBase
  16. {
  17. //密钥
  18. string encryptKey = "HNSTXGLG";
  19. //默认密钥向量
  20. byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
  21. public Hashtable htbl;
  22. public ArrayList alist;
  23. public frmSetEleCols()
  24. {
  25. InitializeComponent();
  26. }
  27. private void frmSetEleCols_Load(object sender, EventArgs e)
  28. {
  29. initCols();
  30. }
  31. private void initCols()
  32. {
  33. try
  34. {
  35. listBoxAll.Items.Clear();
  36. listBoxUse.Items.Clear();
  37. string strElementsRow = ElementsConfig.GetElementsRow(); //调用函数获取要显示的列名
  38. string[] strERow = strElementsRow.Split(new string[] { "*" }, StringSplitOptions.RemoveEmptyEntries);
  39. if (htbl == null)
  40. {
  41. htbl = new Hashtable();
  42. }
  43. if (alist == null)
  44. {
  45. alist = new ArrayList();
  46. }
  47. for (int i = 0; i < strERow.Length; i++)
  48. {
  49. try
  50. {
  51. listBoxUse.Items.Add(strERow[i].Trim());
  52. }
  53. catch { }
  54. try
  55. {
  56. if (!htbl.Contains(strERow[i].Trim()))
  57. {
  58. alist.Add(strERow[i].Trim());
  59. htbl.Add(strERow[i].Trim(), "1");
  60. }
  61. else
  62. {
  63. htbl[strERow[i].Trim()] = "1";
  64. }
  65. }
  66. catch { }
  67. }
  68. for (int i = 0; i < alist.Count; i++)
  69. {
  70. try
  71. {
  72. if (Convert.ToString(htbl[alist[i].ToString()]).Equals("0"))
  73. {
  74. listBoxAll.Items.Add(alist[i].ToString());
  75. }
  76. }
  77. catch { }
  78. }
  79. try
  80. {
  81. listBoxAll.SelectedIndex = (listBoxAll.Items.Count > 0 ? 0 : -1);
  82. listBoxUse.SelectedIndex = (listBoxUse.Items.Count > 0 ? 0 : -1);
  83. }
  84. catch { }
  85. proc_SetButtonEnabled();
  86. }
  87. catch { }
  88. }
  89. private bool SaveSettings(out string strMsg)
  90. {
  91. strMsg = "";
  92. string strElements = "";
  93. try
  94. {
  95. for (int i = 0; i < listBoxUse.Items.Count; i++)
  96. {
  97. try
  98. {
  99. strElements += (strElements.Length > 0 ? "*" : "") + listBoxUse.Items[i].ToString();
  100. }
  101. catch { }
  102. }
  103. ElementsConfig.SetElementsRow(strElements);
  104. }
  105. catch (Exception ex)
  106. {
  107. Console.WriteLine(ex.Message);
  108. strMsg = ex.Message;
  109. return false;
  110. }
  111. return true;
  112. }
  113. private void frmSetEleCols_KeyPress(object sender, KeyPressEventArgs e)
  114. {
  115. if (e.KeyChar == (char)System.Windows.Forms.Keys.Escape)
  116. {
  117. this.Close();
  118. e.Handled = true;
  119. }
  120. }
  121. private void proc_SetButtonEnabled()
  122. {
  123. try
  124. {
  125. //btnL2RSingle.Enabled = (listBoxAll.Items.Count > 0 && listBoxAll.SelectedIndex >= 0);
  126. //btnL2RAll.Enabled = listBoxAll.Items.Count > 0;
  127. //btnR2LSingle.Enabled = (listBoxUse.Items.Count > 0 && listBoxUse.SelectedIndex >= 0);
  128. //btnR2LAll.Enabled = listBoxUse.Items.Count > 0;
  129. //btnUp.Enabled = (listBoxUse.Items.Count > 0 && listBoxUse.SelectedIndex > 0);
  130. //btnDown.Enabled = (listBoxUse.Items.Count > 0 && listBoxUse.SelectedIndex < listBoxUse.Items.Count - 1);
  131. ulblChoice.Enabled = (listBoxAll.Items.Count > 0 && listBoxAll.SelectedIndex >= 0);
  132. ulblAllChoice.Enabled = listBoxAll.Items.Count > 0;
  133. ulblCancel.Enabled = (listBoxUse.Items.Count > 0 && listBoxUse.SelectedIndex >= 0);
  134. ulblAllCancel.Enabled = listBoxUse.Items.Count > 0;
  135. ulblUp.Enabled = (listBoxUse.Items.Count > 0 && listBoxUse.SelectedIndex > 0);
  136. ulblDown.Enabled = (listBoxUse.Items.Count > 0 && listBoxUse.SelectedIndex < listBoxUse.Items.Count - 1);
  137. }
  138. catch { }
  139. }
  140. private void MoveListBoxItem(ListBox lstBx, int index, Direction direct)
  141. {
  142. try
  143. {
  144. object obj;
  145. if (index > 0 && index <= lstBx.Items.Count - 1 && direct == Direction.Up)
  146. {
  147. obj = lstBx.Items[index];
  148. lstBx.Items[index] = lstBx.Items[index - 1];
  149. lstBx.Items[index - 1] = obj;
  150. lstBx.SelectedIndex = index - 1;
  151. }
  152. else if (index >= 0 && index < lstBx.Items.Count - 1 && direct == Direction.Down)
  153. {
  154. obj = lstBx.Items[index];
  155. lstBx.Items[index] = lstBx.Items[index + 1];
  156. lstBx.Items[index + 1] = obj;
  157. lstBx.SelectedIndex = index + 1;
  158. }
  159. }
  160. catch { }
  161. }
  162. private void ultraLabel_Click(object sender, EventArgs e)
  163. {
  164. try
  165. {
  166. Infragistics.Win.Misc.UltraLabel ulabel = (Infragistics.Win.Misc.UltraLabel)sender;
  167. if (ulabel == null)
  168. {
  169. return;
  170. }
  171. if (ulabel.Name == ulblChoice.Name)
  172. {
  173. if (listBoxAll.Items.Count > 0 && listBoxAll.SelectedIndex >= 0)
  174. {
  175. int index = listBoxAll.SelectedIndex;
  176. object obj = listBoxAll.Items[index];
  177. listBoxUse.Items.Add(obj);
  178. listBoxAll.Items.RemoveAt(index);
  179. listBoxUse.SelectedIndex = listBoxUse.Items.Count - 1;
  180. listBoxAll.SelectedIndex = ((index >= 0 && index < listBoxAll.Items.Count) ? index : (listBoxAll.Items.Count > 0 ? 0 : -1));
  181. }
  182. }
  183. else if (ulabel.Name == ulblAllChoice.Name)
  184. {
  185. if (listBoxAll.Items.Count > 0)
  186. {
  187. for (int i = 0; i < listBoxAll.Items.Count; i++)
  188. {
  189. object obj = listBoxAll.Items[i];
  190. listBoxUse.Items.Add(obj);
  191. }
  192. listBoxAll.Items.Clear();
  193. listBoxUse.SelectedIndex = listBoxUse.Items.Count - 1;
  194. listBoxAll.SelectedIndex = -1;
  195. }
  196. }
  197. else if (ulabel.Name == ulblCancel.Name)
  198. {
  199. if (listBoxUse.Items.Count > 0 && listBoxUse.SelectedIndex >= 0)
  200. {
  201. int index = listBoxUse.SelectedIndex;
  202. object obj = listBoxUse.Items[index];
  203. listBoxAll.Items.Add(obj);
  204. listBoxUse.Items.RemoveAt(index);
  205. listBoxAll.SelectedIndex = listBoxAll.Items.Count - 1;
  206. listBoxUse.SelectedIndex = ((index >= 0 && index < listBoxUse.Items.Count) ? index : (listBoxUse.Items.Count > 0 ? 0 : -1));
  207. }
  208. }
  209. else if (ulabel.Name == ulblAllCancel.Name)
  210. {
  211. if (listBoxUse.Items.Count > 0)
  212. {
  213. for (int i = 0; i < listBoxUse.Items.Count; i++)
  214. {
  215. object obj = listBoxUse.Items[i];
  216. listBoxAll.Items.Add(obj);
  217. }
  218. listBoxUse.Items.Clear();
  219. listBoxAll.SelectedIndex = listBoxAll.Items.Count - 1;
  220. listBoxUse.SelectedIndex = -1;
  221. }
  222. }
  223. else if (ulabel.Name == ulblUp.Name)
  224. {
  225. MoveListBoxItem(listBoxUse, listBoxUse.SelectedIndex, Direction.Up);
  226. }
  227. else if (ulabel.Name == ulblDown.Name)
  228. {
  229. MoveListBoxItem(listBoxUse, listBoxUse.SelectedIndex, Direction.Down);
  230. }
  231. }
  232. catch { }
  233. }
  234. private void ucButton_Click(object sender, EventArgs e)
  235. {
  236. ucButton ucBtn = (ucButton)sender;
  237. if (ucBtn == null)
  238. {
  239. return;
  240. }
  241. try
  242. {
  243. if (ucBtn.Name == btnL2RSingle.Name)
  244. {
  245. if (listBoxAll.Items.Count > 0 && listBoxAll.SelectedIndex >= 0)
  246. {
  247. int index = listBoxAll.SelectedIndex;
  248. object obj = listBoxAll.Items[index];
  249. listBoxUse.Items.Add(obj);
  250. listBoxAll.Items.RemoveAt(index);
  251. listBoxUse.SelectedIndex = listBoxUse.Items.Count - 1;
  252. listBoxAll.SelectedIndex = ((index >= 0 && index < listBoxAll.Items.Count) ? index : (listBoxAll.Items.Count > 0 ? 0 : -1));
  253. }
  254. }
  255. else if (ucBtn.Name == btnL2RAll.Name)
  256. {
  257. if (listBoxAll.Items.Count > 0)
  258. {
  259. for (int i = 0; i < listBoxAll.Items.Count; i++)
  260. {
  261. object obj = listBoxAll.Items[i];
  262. listBoxUse.Items.Add(obj);
  263. }
  264. listBoxAll.Items.Clear();
  265. listBoxUse.SelectedIndex = listBoxUse.Items.Count - 1;
  266. listBoxAll.SelectedIndex = -1;
  267. }
  268. }
  269. else if (ucBtn.Name == btnR2LSingle.Name)
  270. {
  271. if (listBoxUse.Items.Count > 0 && listBoxUse.SelectedIndex >= 0)
  272. {
  273. int index = listBoxUse.SelectedIndex;
  274. object obj = listBoxUse.Items[index];
  275. listBoxAll.Items.Add(obj);
  276. listBoxUse.Items.RemoveAt(index);
  277. listBoxAll.SelectedIndex = listBoxAll.Items.Count - 1;
  278. listBoxUse.SelectedIndex = ((index >= 0 && index < listBoxUse.Items.Count) ? index : (listBoxUse.Items.Count > 0 ? 0 : -1));
  279. }
  280. }
  281. else if (ucBtn.Name == btnR2LAll.Name)
  282. {
  283. if (listBoxUse.Items.Count > 0)
  284. {
  285. for (int i = 0; i < listBoxUse.Items.Count; i++)
  286. {
  287. object obj = listBoxUse.Items[i];
  288. listBoxAll.Items.Add(obj);
  289. }
  290. listBoxUse.Items.Clear();
  291. listBoxAll.SelectedIndex = listBoxAll.Items.Count - 1;
  292. listBoxUse.SelectedIndex = -1;
  293. }
  294. }
  295. else if (ucBtn.Name == btnUp.Name)
  296. {
  297. MoveListBoxItem(listBoxUse, listBoxUse.SelectedIndex, Direction.Up);
  298. }
  299. else if (ucBtn.Name == btnDown.Name)
  300. {
  301. MoveListBoxItem(listBoxUse, listBoxUse.SelectedIndex, Direction.Down);
  302. }
  303. else if (ucBtn.Name == btnRestore.Name)
  304. {
  305. initCols();
  306. }
  307. else if (ucBtn.Name == btnSave.Name)
  308. {
  309. string strMsg = "";
  310. if (!SaveSettings(out strMsg))
  311. {
  312. MessageBox.Show("设置保存失败!\r\n" + strMsg, "提示");
  313. return;
  314. }
  315. else
  316. {
  317. this.DialogResult = DialogResult.OK;
  318. this.Close();
  319. }
  320. }
  321. else if (ucBtn.Name == btnCancel.Name)
  322. {
  323. }
  324. proc_SetButtonEnabled();
  325. }
  326. catch { }
  327. }
  328. private void listBox_SelectedIndexChanged(object sender, EventArgs e)
  329. {
  330. proc_SetButtonEnabled();
  331. }
  332. private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
  333. {
  334. switch (e.Tool.Key)
  335. {
  336. case "Restore":
  337. {
  338. initCols();
  339. break;
  340. }
  341. case "Save":
  342. {
  343. string strMsg = "";
  344. if (!SaveSettings(out strMsg))
  345. {
  346. MessageBox.Show("设置保存失败!\r\n" + strMsg, "提示");
  347. return;
  348. }
  349. else
  350. {
  351. this.DialogResult = DialogResult.OK;
  352. this.Close();
  353. }
  354. break;
  355. }
  356. case "Close":
  357. {
  358. this.DialogResult = DialogResult.Cancel;
  359. this.Close();
  360. break;
  361. }
  362. default:
  363. break;
  364. }
  365. }
  366. }
  367. }