CommonMethod.cs 46 KB

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