CommonMethod.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Windows.Forms;
  5. using System.Text;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Diagnostics;
  9. using System.IO;
  10. using Infragistics.Win;
  11. using Infragistics.Win.UltraWinGrid;
  12. using Infragistics.Win.UltraWinEditors;
  13. using Infragistics.Win.UltraWinGrid.ExcelExport;
  14. using Core.Mes.Client.Comm;
  15. using CoreFS.CA06;
  16. using Core.Mes.Client.Comm.Server;
  17. using System.Text.RegularExpressions;
  18. using Infragistics.Win.UltraWinMaskedEdit;
  19. namespace Core.StlMes.Client.ZGMil
  20. {
  21. public enum CodeName
  22. {
  23. Code,
  24. Name
  25. }
  26. public class CheckedListBoxItems
  27. {
  28. private string _strKey = "";
  29. private string _strText = "";
  30. private object _tag = null;
  31. private bool _checked = false;
  32. public string strKey
  33. {
  34. get
  35. {
  36. return _strKey;
  37. }
  38. set
  39. {
  40. if (_strKey != value)
  41. _strKey = value;
  42. }
  43. }
  44. public string strText
  45. {
  46. get
  47. {
  48. return _strText;
  49. }
  50. set
  51. {
  52. if (_strText != value)
  53. _strText = value;
  54. }
  55. }
  56. public object Tag
  57. {
  58. get
  59. {
  60. return _tag;
  61. }
  62. set
  63. {
  64. _tag = value;
  65. }
  66. }
  67. public bool Checked
  68. {
  69. get
  70. {
  71. return _checked;
  72. }
  73. set
  74. {
  75. if (_checked != value)
  76. _checked = value;
  77. }
  78. }
  79. public void Check()
  80. {
  81. if (!_checked)
  82. {
  83. this._checked = true;
  84. }
  85. }
  86. public CheckedListBoxItems(string strKey, string strText)
  87. {
  88. this._strKey = strKey;
  89. this._strText = strText;
  90. }
  91. public CheckedListBoxItems(string strKey, string strText, bool Checked)
  92. {
  93. this._strKey = strKey;
  94. this._strText = strText;
  95. this._checked = Checked;
  96. }
  97. public override string ToString()
  98. {
  99. return this._strText;
  100. }
  101. }
  102. public class CommonMethod
  103. {
  104. public static ValueList InitValueListComparisonOperator()
  105. {
  106. ValueList vlist_ComparisonOperator = new ValueList();
  107. vlist_ComparisonOperator.ValueListItems.Add(" = ", "等于");
  108. vlist_ComparisonOperator.ValueListItems.Add(" > ", "大于");
  109. vlist_ComparisonOperator.ValueListItems.Add(" >= ", "大于等于");
  110. vlist_ComparisonOperator.ValueListItems.Add(" < ", "小于");
  111. vlist_ComparisonOperator.ValueListItems.Add(" <= ", "小于等于");
  112. vlist_ComparisonOperator.ValueListItems.Add(" <> ", "不等于");
  113. return vlist_ComparisonOperator;
  114. }
  115. public static ValueList InitValueListLgic()
  116. {
  117. ValueList vlist_Logic = new ValueList();
  118. vlist_Logic.ValueListItems.Add("1", "是");
  119. vlist_Logic.ValueListItems.Add("0", "否");
  120. return vlist_Logic;
  121. }
  122. public static ValueList InitValueListBanCi()
  123. {
  124. ValueList vlist_BanCi = new ValueList();
  125. vlist_BanCi.ValueListItems.Add("1", "夜班");
  126. vlist_BanCi.ValueListItems.Add("2", "日班");
  127. return vlist_BanCi;
  128. }
  129. public static ValueList InitValueListBanZu()
  130. {
  131. ValueList vlist_BanZu = new ValueList();
  132. vlist_BanZu.ValueListItems.Add("1", "甲班");
  133. vlist_BanZu.ValueListItems.Add("2", "乙班");
  134. vlist_BanZu.ValueListItems.Add("3", "丙班");
  135. vlist_BanZu.ValueListItems.Add("4", "丁班");
  136. return vlist_BanZu;
  137. }
  138. public static void GetMonthPeriod(DateTime dtToday, out DateTime dtFrom, out DateTime dtTo)
  139. {
  140. try
  141. {
  142. dtTo = dtToday;
  143. if (dtToday.Month == 1)
  144. {
  145. if (dtToday.Day >= 26)
  146. {
  147. dtFrom = dtToday.AddDays(-dtToday.Day).AddDays(26);
  148. }
  149. else
  150. {
  151. dtFrom = new DateTime(dtToday.Year, dtToday.Month, 1);
  152. }
  153. }
  154. else if (dtToday.Month == 12)
  155. {
  156. dtFrom = dtToday.AddDays(-dtToday.Day).AddDays(26).AddMonths(-1);
  157. }
  158. else
  159. {
  160. if (dtToday.Day >= 26)
  161. {
  162. dtFrom = dtToday.AddDays(-dtToday.Day).AddDays(26);
  163. }
  164. else
  165. {
  166. dtFrom = dtToday.AddDays(-dtToday.Day).AddDays(26).AddMonths(-1);
  167. }
  168. }
  169. }
  170. catch
  171. {
  172. dtFrom = dtTo = dtToday;
  173. }
  174. }
  175. public static void SetColumnsVisible(ref UltraGrid ultraGrid1, ArrayList alistColumns)
  176. {
  177. try
  178. {
  179. if (ultraGrid1 == null || alistColumns == null || alistColumns.Count == 0)
  180. {
  181. return;
  182. }
  183. for (int i = 0; i < alistColumns.Count; i++)
  184. {
  185. for (int j = 0; j < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; j++)
  186. {
  187. try
  188. {
  189. if (alistColumns[i].ToString().Equals(ultraGrid1.DisplayLayout.Bands[0].Columns[j].Key) && ultraGrid1.DisplayLayout.Bands[0].Columns[j].Hidden)
  190. {
  191. ultraGrid1.DisplayLayout.Bands[0].Columns[j].Hidden = false;
  192. break;
  193. }
  194. }
  195. catch { }
  196. }
  197. }
  198. }
  199. catch { }
  200. }
  201. public static void SetColumnsHidden(ref UltraGrid ultraGrid1, ArrayList alistColumns)
  202. {
  203. try
  204. {
  205. if (ultraGrid1 == null || alistColumns == null || alistColumns.Count == 0)
  206. {
  207. return;
  208. }
  209. for (int i = 0; i < alistColumns.Count; i++)
  210. {
  211. for (int j = 0; j < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; j++)
  212. {
  213. try
  214. {
  215. if (alistColumns[i].ToString().Equals(ultraGrid1.DisplayLayout.Bands[0].Columns[j].Key) && !ultraGrid1.DisplayLayout.Bands[0].Columns[j].Hidden)
  216. {
  217. ultraGrid1.DisplayLayout.Bands[0].Columns[j].Hidden = true;
  218. break;
  219. }
  220. }
  221. catch { }
  222. }
  223. }
  224. }
  225. catch { }
  226. }
  227. public static string GetProduceLine(string strManagementno, string strStorageattr)
  228. {
  229. string strProduceLine = "";
  230. if ((strManagementno.Equals("500101") || strManagementno.Equals("500103")) && strStorageattr.Equals("500205"))
  231. {
  232. strProduceLine = "1011BC1";
  233. }
  234. else if ((strManagementno.Equals("500101") || strManagementno.Equals("500104")) && strStorageattr.Equals("500206"))
  235. {
  236. strProduceLine = "1011XC1";
  237. }
  238. return strProduceLine;
  239. }
  240. public static DataRow[] GetRows(ref DataTable table, string strFilter, string strSort)
  241. {
  242. if (table == null)
  243. {
  244. return null;
  245. }
  246. try
  247. {
  248. return table.Select(strFilter, strSort);
  249. }
  250. catch { }
  251. return null;
  252. }
  253. public static void AddItems(ref ArrayList alist, ref Hashtable hs, ref DataRow[] rows, string strKey, string strValue)
  254. {
  255. if (alist == null)
  256. {
  257. alist = new ArrayList();
  258. }
  259. else
  260. {
  261. alist.Clear();
  262. }
  263. if (hs == null)
  264. {
  265. hs = new Hashtable();
  266. }
  267. else
  268. {
  269. hs.Clear();
  270. }
  271. if (rows.Length > 0)
  272. {
  273. DataTable table = rows[0].Table;
  274. if (table == null || !table.Columns.Contains(strKey) || !table.Columns.Contains(strValue))
  275. return;
  276. for (int i = 0; i < rows.Length; i++)
  277. {
  278. try
  279. {
  280. if (!hs.Contains(Convert.ToString(rows[i][strKey])))
  281. {
  282. alist.Add(Convert.ToString(rows[i][strKey]));
  283. hs.Add(Convert.ToString(rows[i][strKey]), Convert.ToString(rows[i][strValue]));
  284. }
  285. }
  286. catch { }
  287. }
  288. }
  289. }
  290. public static ValueList GeneralValuelist(ref DataTable table, string strKey, string strText)
  291. {
  292. if (table == null || !table.Columns.Contains(strKey) || !table.Columns.Contains(strText))
  293. {
  294. return null;
  295. }
  296. ArrayList alist = new ArrayList();
  297. ValueList vlist = new ValueList();
  298. for (int i = 0; i < table.Rows.Count; i++)
  299. {
  300. try
  301. {
  302. if (!alist.Contains(table.Rows[i][strKey]))
  303. {
  304. alist.Add(table.Rows[i][strKey]);
  305. vlist.ValueListItems.Add(table.Rows[i][strKey], Convert.ToString(table.Rows[i][strText]));
  306. }
  307. }
  308. catch { }
  309. }
  310. return vlist;
  311. }
  312. public static ValueList GeneralValuelist(ref ArrayList alist, ref Hashtable hs)
  313. {
  314. if (alist == null || hs == null)
  315. {
  316. return null;
  317. }
  318. ValueList vlist = new ValueList();
  319. for (int i = 0; i < alist.Count; i++)
  320. {
  321. try
  322. {
  323. if (hs.Contains(alist[i]))
  324. {
  325. vlist.ValueListItems.Add(alist[i], Convert.ToString(hs[alist[i]]));
  326. }
  327. }
  328. catch { }
  329. }
  330. return vlist;
  331. }
  332. public static void CopyDataToDatatable(ref DataTable table, DataRow row, bool ClearExists)
  333. {
  334. if (table == null || row == null)
  335. {
  336. return;
  337. }
  338. if (ClearExists)
  339. {
  340. table.Rows.Clear();
  341. }
  342. try
  343. {
  344. DataRow NewRow = table.NewRow();
  345. for (int i = 0; i < row.Table.Columns.Count; i++)
  346. {
  347. try
  348. {
  349. if (table.Columns.Contains(row.Table.Columns[i].ColumnName))
  350. {
  351. NewRow[row.Table.Columns[i].ColumnName] = row[i];
  352. }
  353. }
  354. catch { }
  355. }
  356. table.Rows.Add(NewRow);
  357. }
  358. catch { }
  359. }
  360. public static void CopyDataToDatatable(ref DataTable src, ref DataTable dest, bool ClearExists, ArrayList alistColumns, ArrayList alistValue)
  361. {
  362. if (src == null || dest == null)
  363. {
  364. return;
  365. }
  366. if (ClearExists)
  367. {
  368. dest.Rows.Clear();
  369. }
  370. DataRow CurRow, NewRow;
  371. for (int i = 0; i < src.Rows.Count; i++)
  372. {
  373. CurRow = src.Rows[i];
  374. NewRow = dest.NewRow();
  375. for (int j = 0; j < src.Columns.Count; j++)
  376. {
  377. try
  378. {
  379. if (dest.Columns.Contains(src.Columns[j].ColumnName))
  380. {
  381. NewRow[src.Columns[j].ColumnName] = CurRow[j];
  382. }
  383. }
  384. catch { }
  385. }
  386. if (alistColumns != null && alistValue != null)
  387. {
  388. for (int idx = 0; idx < alistColumns.Count; idx++)
  389. {
  390. try
  391. {
  392. if (dest.Columns.Contains(alistColumns[idx].ToString()))
  393. {
  394. NewRow[alistColumns[idx].ToString()] = alistValue[idx];
  395. }
  396. }
  397. catch { }
  398. }
  399. }
  400. dest.Rows.Add(NewRow);
  401. }
  402. }
  403. public static void CopyDataToDatatable(ref DataTable src, ref DataTable dest, bool ClearExists)
  404. {
  405. if (src == null || dest == null)
  406. {
  407. return;
  408. }
  409. if (ClearExists)
  410. {
  411. dest.Rows.Clear();
  412. }
  413. DataRow CurRow, NewRow;
  414. for (int i = 0; i < src.Rows.Count; i++)
  415. {
  416. CurRow = src.Rows[i];
  417. NewRow = dest.NewRow();
  418. for (int j = 0; j < src.Columns.Count; j++)
  419. {
  420. try
  421. {
  422. if (dest.Columns.Contains(src.Columns[j].ColumnName))
  423. {
  424. NewRow[src.Columns[j].ColumnName] = CurRow[j];
  425. }
  426. }
  427. catch { }
  428. }
  429. dest.Rows.Add(NewRow);
  430. }
  431. }
  432. public static DataRow GetDatatableRow(ref DataTable table, string strColumn, object value)
  433. {
  434. if (table == null || !table.Columns.Contains(strColumn))
  435. {
  436. return null;
  437. }
  438. DataRow row;
  439. for (int i = 0; i < table.Rows.Count; i++)
  440. {
  441. row = table.Rows[i];
  442. try
  443. {
  444. if (row[strColumn].Equals(value))
  445. {
  446. return row;
  447. }
  448. }
  449. catch { }
  450. }
  451. return null;
  452. }
  453. public static bool DataChanged(ref UltraGrid myGrid, ref DataTable dataSource, ref DataTable tblChanged)
  454. {
  455. if (myGrid == null)
  456. {
  457. return false;
  458. }
  459. myGrid.UpdateData();
  460. return DataChanged(ref dataSource, ref tblChanged);
  461. }
  462. public static bool DataChanged(ref DataTable dataSource, ref DataTable tblChanged)
  463. {
  464. if (dataSource == null)
  465. {
  466. return false;
  467. }
  468. tblChanged = dataSource.GetChanges(DataRowState.Modified);
  469. if (tblChanged != null && tblChanged.Rows.Count > 0)
  470. {
  471. return true;
  472. }
  473. return false;
  474. }
  475. public static void ResetArrayList(ref ArrayList alist)
  476. {
  477. if (alist == null)
  478. {
  479. alist = new ArrayList();
  480. }
  481. else
  482. {
  483. alist.Clear();
  484. }
  485. }
  486. public static bool GridContainsColumn(ref UltraGrid grid, string strColumn)
  487. {
  488. for (int i = 0; i < grid.DisplayLayout.Bands[0].Columns.Count; i++)
  489. {
  490. if (grid.DisplayLayout.Bands[0].Columns[i].Key.Equals(strColumn))
  491. return true;
  492. }
  493. return false;
  494. }
  495. public static bool GridContainsColumn(ref UltraGrid grid, int BandIndex, string strColumn)
  496. {
  497. if (BandIndex <= grid.DisplayLayout.Bands.Count - 1)
  498. {
  499. for (int i = 0; i < grid.DisplayLayout.Bands[BandIndex].Columns.Count; i++)
  500. {
  501. if (grid.DisplayLayout.Bands[BandIndex].Columns[i].Key.Equals(strColumn))
  502. return true;
  503. }
  504. }
  505. return false;
  506. }
  507. public static void SetGridValuelist(ref UltraGrid myGrid, string strColumn, ref ValueList vlist)
  508. {
  509. try
  510. {
  511. if (GridContainsColumn(ref myGrid, strColumn))
  512. {
  513. myGrid.DisplayLayout.Bands[0].Columns[strColumn].ValueList = vlist;
  514. }
  515. }
  516. catch { }
  517. }
  518. public static void SetGridValuelist(ref UltraGrid myGrid, int BandIndex, string strColumn, ref ValueList vlist)
  519. {
  520. try
  521. {
  522. if (GridContainsColumn(ref myGrid, BandIndex, strColumn))
  523. {
  524. myGrid.DisplayLayout.Bands[BandIndex].Columns[strColumn].ValueList = vlist;
  525. }
  526. }
  527. catch { }
  528. }
  529. public static string Substring(string strSrc, int startIndex, int length)
  530. {
  531. try
  532. {
  533. return strSrc.Substring(startIndex, length);
  534. }
  535. catch { }
  536. return strSrc;
  537. }
  538. public static void SetValueToDatatableColumn(ref DataTable tbl, string strColumnName, object value)
  539. {
  540. if (tbl == null || !tbl.Columns.Contains(strColumnName))
  541. {
  542. return;
  543. }
  544. for (int i = 0; i < tbl.Rows.Count; i++)
  545. {
  546. try
  547. {
  548. if (tbl.Rows[i][strColumnName] != value)
  549. tbl.Rows[i][strColumnName] = value;
  550. }
  551. catch { }
  552. }
  553. }
  554. public static string[] proc_GeneralItemList(ref ArrayList alist)
  555. {
  556. try
  557. {
  558. if (alist == null || alist.Count == 0)
  559. return new string[] { "''" };
  560. int iCount = alist.Count / 1000 + 1;
  561. string[] strList = new string[iCount];
  562. int iDiv = 0, index = 0;
  563. for (int i = 0; i < alist.Count; i++, index++)
  564. {
  565. iDiv = i / 1000;
  566. if (i % 1000 == 0)
  567. {
  568. index = 0;
  569. }
  570. strList[iDiv] += (index == 0 ? "" : ",") + Convert.ToString(alist[i]);
  571. }
  572. for (int i = 0; i < strList.Length; i++)
  573. {
  574. strList[i] = "'" + strList[i].Replace(",", "','") + "'";
  575. }
  576. return strList;
  577. }
  578. catch (Exception ex)
  579. {
  580. Debug.WriteLine(ex.Message);
  581. }
  582. return new string[] { "''" };
  583. }
  584. public static string[] proc_GeneralItemList(ref Hashtable hs)
  585. {
  586. try
  587. {
  588. if (hs == null || hs.Count == 0)
  589. return new string[] { "''" };
  590. ArrayList alist = new ArrayList(hs.Keys);
  591. int iCount = alist.Count / 1000 + 1;
  592. string[] strList = new string[iCount];
  593. int iDiv = 0, index = 0;
  594. for (int i = 0; i < alist.Count; i++, index++)
  595. {
  596. iDiv = i / 1000;
  597. if (i % 1000 == 0)
  598. {
  599. index = 0;
  600. }
  601. strList[iDiv] += (index == 0 ? "" : ",") + Convert.ToString(alist[i]);
  602. }
  603. for (int i = 0; i < strList.Length; i++)
  604. {
  605. strList[i] = "'" + strList[i].Replace(",", "','") + "'";
  606. }
  607. return strList;
  608. }
  609. catch (Exception ex)
  610. {
  611. Debug.WriteLine(ex.Message);
  612. }
  613. return new string[] { "''" };
  614. }
  615. public static UltraGridRow RetrieveRowByKey(ref UltraGrid grid, string strColumn, string strKey)
  616. {
  617. if (grid == null || !GridContainsColumn(ref grid, strColumn))
  618. {
  619. return null;
  620. }
  621. for (int i = 0; i < grid.Rows.Count; i++)
  622. {
  623. if (Convert.ToString(grid.Rows[i].Cells[strColumn].Value).Equals(strKey))
  624. {
  625. return grid.Rows[i];
  626. }
  627. }
  628. return null;
  629. }
  630. public static void LocateMyGridByKey(ref UltraGrid myGrid1, string strKey, string strValue, bool NullThenLast)
  631. {
  632. if (myGrid1 == null)
  633. {
  634. return;
  635. }
  636. if (string.IsNullOrEmpty(strKey))
  637. {
  638. if (myGrid1.Rows.Count > 0 && NullThenLast)
  639. {
  640. myGrid1.ActiveRow = myGrid1.Rows[myGrid1.Rows.Count - 1];
  641. }
  642. }
  643. else
  644. {
  645. UltraGridRow row = RetrieveRowByKey(ref myGrid1, strKey, strValue);
  646. if (row != null)
  647. {
  648. myGrid1.ActiveRow = row;
  649. }
  650. }
  651. }
  652. public static Color GetInvertColor(Color src)
  653. {
  654. return Color.FromArgb((int)(src.R ^ 255), (int)(src.R ^ 255), (int)(src.R ^ 255));
  655. }
  656. public static void SetGridGroupBy(ref UltraGrid myGrid1, bool bAllowGroupBy)
  657. {
  658. try
  659. {
  660. if (!bAllowGroupBy)
  661. {
  662. for (int i = 0; i < myGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
  663. {
  664. try
  665. {
  666. if (myGrid1.DisplayLayout.Bands[0].Columns[i].IsGroupByColumn)
  667. myGrid1.DisplayLayout.Bands[0].Columns[i].ResetIsGroupByColumn();
  668. }
  669. catch { }
  670. }
  671. }
  672. myGrid1.DisplayLayout.GroupByBox.Hidden = !bAllowGroupBy;
  673. }
  674. catch { }
  675. }
  676. public static void SetGridRowFilter(ref UltraGrid myGrid1, bool bAllowFilter)
  677. {
  678. try
  679. {
  680. if (bAllowFilter)
  681. {
  682. if (myGrid1.DisplayLayout.Override.FilterUIType != FilterUIType.FilterRow)
  683. myGrid1.DisplayLayout.Override.FilterUIType = FilterUIType.FilterRow;
  684. for (int i = 0; i < myGrid1.DisplayLayout.Bands.Count; i++)
  685. {
  686. for (int j = 0; j < myGrid1.DisplayLayout.Bands[i].Columns.Count; j++)
  687. {
  688. try
  689. {
  690. if (!myGrid1.DisplayLayout.Bands[i].Columns[j].Hidden &&
  691. myGrid1.DisplayLayout.Bands[i].Columns[j].RowLayoutColumnInfo.LabelPosition != LabelPosition.LabelOnly)
  692. myGrid1.DisplayLayout.Bands[i].Columns[j].AllowRowFiltering = Infragistics.Win.DefaultableBoolean.True;
  693. }
  694. catch { }
  695. }
  696. }
  697. }
  698. else
  699. {
  700. if (myGrid1.DisplayLayout.Override.FilterUIType != FilterUIType.HeaderIcons)
  701. myGrid1.DisplayLayout.Override.FilterUIType = FilterUIType.HeaderIcons;
  702. for (int i = 0; i < myGrid1.DisplayLayout.Bands.Count; i++)
  703. {
  704. try
  705. {
  706. myGrid1.DisplayLayout.Bands[i].ColumnFilters.ClearAllFilters();
  707. }
  708. catch { }
  709. for (int j = 0; j < myGrid1.DisplayLayout.Bands[i].Columns.Count; j++)
  710. {
  711. try
  712. {
  713. myGrid1.DisplayLayout.Bands[i].Columns[j].AllowRowFiltering = Infragistics.Win.DefaultableBoolean.False;
  714. }
  715. catch { }
  716. }
  717. }
  718. }
  719. }
  720. catch { }
  721. }
  722. public static void SetGridRowSort(ref UltraGrid myGrid1, bool bAllowSort)
  723. {
  724. try
  725. {
  726. if (bAllowSort)
  727. {
  728. myGrid1.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.SortMulti;
  729. }
  730. else
  731. {
  732. for (int i = 0; i < myGrid1.DisplayLayout.Bands.Count; i++)
  733. {
  734. try
  735. {
  736. for (int j = 0; j < myGrid1.DisplayLayout.Bands[i].Columns.Count; j++)
  737. {
  738. myGrid1.DisplayLayout.Bands[i].Columns[j].SortIndicator = SortIndicator.None;
  739. }
  740. }
  741. catch { }
  742. }
  743. myGrid1.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Default;
  744. }
  745. }
  746. catch { }
  747. }
  748. public static void SetStaticsInfoFormula(ref UltraGrid myGrid1, ArrayList alistColumns, ArrayList alistFormulas, bool clearExists)
  749. {
  750. try
  751. {
  752. UltraGridBand band = myGrid1.DisplayLayout.Bands[0];
  753. if (clearExists)
  754. band.Summaries.Clear();
  755. band.Override.SummaryFooterCaptionVisible = Infragistics.Win.DefaultableBoolean.False;
  756. for (int i = 0; i < alistColumns.Count; i++)
  757. {
  758. try
  759. {
  760. SummarySettings summary = band.Summaries.Add(alistFormulas[i].ToString(), SummaryPosition.UseSummaryPositionColumn, band.Columns[alistColumns[i].ToString()]);
  761. summary.SummaryType = SummaryType.Formula;
  762. summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
  763. summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
  764. summary.DisplayFormat = "{0}";
  765. summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
  766. summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
  767. summary.Appearance.FontData.Bold = DefaultableBoolean.True;
  768. }
  769. catch { }
  770. }
  771. }
  772. catch { }
  773. }
  774. public static void SetStaticsInfoSum(ref UltraGrid myGrid1, ArrayList alistColumns, bool clearExists)
  775. {
  776. try
  777. {
  778. UltraGridBand band = myGrid1.DisplayLayout.Bands[0];
  779. if (clearExists)
  780. band.Summaries.Clear();
  781. band.Override.SummaryFooterCaptionVisible = Infragistics.Win.DefaultableBoolean.False;
  782. for (int i = 0; i < alistColumns.Count; i++)
  783. {
  784. try
  785. {
  786. SummarySettings summary = band.Summaries.Add(SummaryType.Sum, band.Columns[alistColumns[i].ToString()]);
  787. summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
  788. summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
  789. if (alistColumns[i].ToString().Contains("COUNT"))
  790. {
  791. summary.DisplayFormat = "{0:N0}";
  792. }
  793. else
  794. {
  795. summary.DisplayFormat = "{0:N3}";
  796. }
  797. summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
  798. summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
  799. summary.Appearance.FontData.Bold = DefaultableBoolean.True;
  800. summary.Lines = 3;
  801. }
  802. catch { }
  803. }
  804. }
  805. catch { }
  806. }
  807. public static void SetGridSumArea(Infragistics.Win.UltraWinGrid.UltraGridBase Grid)
  808. {
  809. try
  810. {
  811. //Grid.DisplayLayout.GroupByBox.Hidden
  812. if (Grid.Rows.Count == 0)
  813. {
  814. foreach (Infragistics.Win.UltraWinGrid.UltraGridBand band in Grid.DisplayLayout.Bands)
  815. {
  816. foreach (Infragistics.Win.UltraWinGrid.SummarySettings sum in band.Summaries)
  817. {
  818. sum.SummaryDisplayArea = Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.None;
  819. }
  820. }
  821. }
  822. else
  823. {
  824. foreach (Infragistics.Win.UltraWinGrid.UltraGridBand band in Grid.DisplayLayout.Bands)
  825. {
  826. foreach (Infragistics.Win.UltraWinGrid.SummarySettings sum in band.Summaries)
  827. {
  828. if (Grid.DisplayLayout.GroupByBox.Hidden)
  829. {
  830. sum.SummaryDisplayArea = Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.Top;
  831. }
  832. else
  833. {
  834. sum.SummaryDisplayArea = ((Infragistics.Win.UltraWinGrid.SummaryDisplayAreas)((Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.Top | Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.InGroupByRows | Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.GroupByRowsFooter)));
  835. }
  836. }
  837. }
  838. }
  839. }
  840. catch (System.Exception ex)
  841. {
  842. System.Diagnostics.Debug.WriteLine(ex.ToString());
  843. }
  844. }
  845. public static void SetStaticsInfoCount(ref UltraGrid myGrid1, ArrayList alistColumns, bool clearExists)
  846. {
  847. try
  848. {
  849. UltraGridBand band = myGrid1.DisplayLayout.Bands[0];
  850. if (clearExists)
  851. band.Summaries.Clear();
  852. band.Override.SummaryFooterCaptionVisible = Infragistics.Win.DefaultableBoolean.False;
  853. for (int i = 0; i < alistColumns.Count; i++)
  854. {
  855. try
  856. {
  857. SummarySettings summary = band.Summaries.Add(SummaryType.Count, band.Columns[alistColumns[i].ToString()]);
  858. //summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
  859. summary.SummaryDisplayArea = Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.BottomFixed | Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.InGroupByRows | Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.GroupByRowsFooter;
  860. summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
  861. summary.DisplayFormat = "{0:0,0}";
  862. summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
  863. summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
  864. summary.Appearance.FontData.Bold = DefaultableBoolean.True;
  865. }
  866. catch { }
  867. }
  868. }
  869. catch { }
  870. }
  871. public static Point SetChildWindowLocation(Size ChildWindowSize)
  872. {
  873. int width = Cursor.Position.X + ChildWindowSize.Width - Screen.PrimaryScreen.Bounds.Width;
  874. int height = Cursor.Position.Y + ChildWindowSize.Height - Screen.PrimaryScreen.Bounds.Height + 30;
  875. width = (width > 0) ? (Cursor.Position.X - width) : Cursor.Position.X; // X坐标
  876. height = (height > 0) ? (Cursor.Position.Y - height + 10) : (Cursor.Position.Y + 10); // Y坐标
  877. return new Point(width, height);
  878. }
  879. private static UltraGridExcelExporter ultraGridExcelExporter1 = new UltraGridExcelExporter();
  880. public static void ExportDataWithSaveDialog(ref UltraGrid myGrid1, string strFileName)
  881. {
  882. try
  883. {
  884. if (myGrid1.Rows.Count == 0) return;
  885. if (strFileName.Length == 0)
  886. strFileName = "未命名";
  887. SaveFileDialog dlg = new SaveFileDialog();
  888. dlg.Title = "保存";
  889. dlg.OverwritePrompt = true;
  890. dlg.Filter = "Excel文件(*.xls)|*.xls";
  891. dlg.AddExtension = true;
  892. dlg.FileName = strFileName;
  893. if (dlg.ShowDialog() == DialogResult.OK)
  894. {
  895. strFileName = dlg.FileName;
  896. ultraGridExcelExporter1.Export(myGrid1, strFileName);
  897. if (MessageBox.Show("数据导出成功!\r\n需要打开所导出文件吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  898. {
  899. ProcessStartInfo p = new ProcessStartInfo(strFileName);
  900. p.WorkingDirectory = Path.GetDirectoryName(strFileName);
  901. Process.Start(p);
  902. }
  903. }
  904. }
  905. catch (Exception ex)
  906. {
  907. MessageBox.Show(ex.Message);
  908. }
  909. }
  910. public static bool HasCheckedRows(ref UltraGrid ultraGrid, string strColumnCondition, object value, string strOutColumn, out ArrayList alistValue, out string strMsg)
  911. {
  912. strMsg = "";
  913. alistValue = new ArrayList();
  914. try
  915. {
  916. if (ultraGrid == null || ultraGrid.Rows.Count == 0)
  917. {
  918. return false;
  919. }
  920. if (!string.IsNullOrEmpty(strColumnCondition))
  921. {
  922. if (!CommonMethod.GridContainsColumn(ref ultraGrid, 0, strColumnCondition))
  923. {
  924. strMsg = "不存在条件字段【" + strColumnCondition + "】!";
  925. return false;
  926. }
  927. }
  928. if (string.IsNullOrEmpty(strOutColumn))
  929. {
  930. strMsg = "未指定输出字段【" + strOutColumn + "】!";
  931. return false;
  932. }
  933. if (!CommonMethod.GridContainsColumn(ref ultraGrid, 0, strOutColumn))
  934. {
  935. strMsg = "不存在输出字段【" + strOutColumn + "】!";
  936. return false;
  937. }
  938. for (int i = 0; i < ultraGrid.Rows.Count; i++)
  939. {
  940. if (!string.IsNullOrEmpty(strColumnCondition))
  941. {
  942. if (ultraGrid.Rows[i].Cells[strColumnCondition].Value.Equals(value))
  943. {
  944. alistValue.Add(ultraGrid.Rows[i].Cells[strOutColumn].Value);
  945. }
  946. }
  947. else
  948. {
  949. alistValue.Add(ultraGrid.Rows[i].Cells[strOutColumn].Value);
  950. }
  951. }
  952. return true;
  953. }
  954. catch (Exception ex)
  955. {
  956. strMsg = ex.Message;
  957. alistValue = null;
  958. }
  959. return false;
  960. }
  961. public static Hashtable GetHashtableFromDatatable(ref DataTable table, string strColumnKey, string strColumnValue)
  962. {
  963. Hashtable htbl = new Hashtable();
  964. if (table == null || table.Rows.Count == 0)
  965. {
  966. return htbl;
  967. }
  968. if (!table.Columns.Contains(strColumnKey) || !table.Columns.Contains(strColumnValue))
  969. {
  970. return htbl;
  971. }
  972. object Key = null, Value = null;
  973. for (int i = 0; i < table.Rows.Count; i++)
  974. {
  975. try
  976. {
  977. Key = table.Rows[i][strColumnKey];
  978. if (!htbl.Contains(Key))
  979. {
  980. Value = table.Rows[i][strColumnValue];
  981. htbl.Add(Key, Value);
  982. }
  983. }
  984. catch { }
  985. }
  986. return htbl;
  987. }
  988. /// <summary>
  989. /// 对目标对象进行字符串的转换
  990. /// </summary>
  991. /// <param name="obj"></param>
  992. /// <returns></returns>
  993. public static string CheckNullStr(object obj)
  994. {
  995. if (obj == null || obj.GetType() == typeof(System.DBNull))
  996. {
  997. return "";
  998. }
  999. else
  1000. {
  1001. return Convert.ToString(obj).Trim();
  1002. }
  1003. }
  1004. /// <summary>
  1005. /// 初始化UltraCombo数据
  1006. /// </summary>
  1007. /// <param name="ulcme">ultraComboEditor控件</param>
  1008. /// <param name="dset">DataSet数据源</param>
  1009. public static void FillUltraComboItems(Infragistics.Win.UltraWinEditors.UltraComboEditor ulcme, DataSet dset)
  1010. {
  1011. if (dset.Tables.Count > 0 && dset.Tables[0].Columns.Count > 1)
  1012. {
  1013. for (int i = 0; i < dset.Tables[0].Rows.Count; i++)
  1014. ulcme.Items.Add(dset.Tables[0].Rows[i][0].ToString(), dset.Tables[0].Rows[i][1].ToString());
  1015. }
  1016. }
  1017. /// <summary>
  1018. /// 初始化下拉框 --带参数的
  1019. /// </summary>
  1020. /// <param name="uce"></param>
  1021. /// <param name="methodId"></param>
  1022. /// <param name="valueMember"></param>
  1023. /// <param name="ob"></param>
  1024. /// <param name="isEmpty"></param>
  1025. /// <param name="obj"></param>
  1026. public static void InitComboEditorWithParm(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, bool isEmpty, Object[] parm)
  1027. {
  1028. DataTable dt = ServerHelper.GetData(methodId, parm, ob);
  1029. if (dt != null && dt.Rows.Count > 0)
  1030. {
  1031. if (isEmpty)
  1032. {
  1033. Object[] obj = new Object[] { "", "" };
  1034. dt.Rows.Add(obj);
  1035. }
  1036. uce.DataSource = dt;
  1037. uce.ValueMember = valueMember;
  1038. SetComboItemHeight(uce);
  1039. }
  1040. }
  1041. /// <summary>
  1042. /// 设置UltraComboEditor中的中文和非中文统一高度。
  1043. /// </summary>
  1044. /// <param name="cmb"></param>
  1045. public static void SetComboItemHeight(UltraComboEditor cmb)
  1046. {
  1047. foreach (ValueListItem item in cmb.Items)
  1048. {
  1049. if (Regex.IsMatch(item.DisplayText, @"[\u4e00-\u9fa5]+"))
  1050. {
  1051. item.Appearance.FontData.SizeInPoints = 9.0F;
  1052. }
  1053. else
  1054. {
  1055. item.Appearance.FontData.SizeInPoints = 10.5F;
  1056. }
  1057. }
  1058. }
  1059. /// <summary>
  1060. /// 设置列显示位数
  1061. /// </summary>
  1062. /// <param name="ug"></param>
  1063. /// <param name="arr"></param>
  1064. //public static void setUltraGridColumnMaxInput(UltraGrid ug, string[] arr)
  1065. //{
  1066. // if (ug == null || arr == null || arr.Length == 0)
  1067. // {
  1068. // return;
  1069. // }
  1070. // arr;
  1071. // foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns)
  1072. // {
  1073. // if (arr.Contains(ugc.Key.ToString()))
  1074. // {
  1075. // ugc.MaskDisplayMode = MaskMode.IncludeLiterals;
  1076. // ugc.MaskInput = "{LOC}nn,nnn,nnn.nnn";
  1077. // }
  1078. // }
  1079. //}
  1080. }
  1081. }