CommonMethod.cs 45 KB

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