ClsControlPack.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.Drawing.Printing;
  8. using System.IO;
  9. using System.Net.NetworkInformation;
  10. using System.Reflection;
  11. using System.Text;
  12. using System.Text.RegularExpressions;
  13. using System.Windows.Forms;
  14. using Infragistics.Excel;
  15. using Infragistics.Win;
  16. using Infragistics.Win.Layout;
  17. using Infragistics.Win.Misc;
  18. using Infragistics.Win.UltraWinDataSource;
  19. using Infragistics.Win.UltraWinEditors;
  20. using Infragistics.Win.UltraWinGrid;
  21. using Infragistics.Win.UltraWinGrid.ExcelExport;
  22. using Infragistics.Win.UltraWinTabControl;
  23. using Infragistics.Win.UltraWinToolbars;
  24. using System.Collections.Generic;
  25. namespace Core.LZMes.Client.QCM
  26. {
  27. /// <summary>
  28. /// 控件设置、属性相关公用
  29. /// </summary>
  30. public class ClsControlPack
  31. {
  32. /// <summary>
  33. /// 获取子窗体弹出的位置坐标
  34. /// </summary>
  35. /// <param name="ChildWindowSize"></param>
  36. /// <returns></returns>
  37. public static Point GetChildWindowLocation(Size ChildWindowSize)
  38. {
  39. Point point = Cursor.Position;
  40. Size size = Cursor.Current.Size;
  41. int width = point.X + ChildWindowSize.Width - Screen.PrimaryScreen.Bounds.Width;
  42. int height = point.Y + ChildWindowSize.Height - Screen.PrimaryScreen.Bounds.Height;
  43. width = (width > 0) ? (point.X - width - size.Width) : point.X; // X坐标
  44. height = (height > 0) ? (point.Y - height - size.Height) : point.Y; // Y坐标
  45. return new Point(width, height);
  46. }
  47. /// <summary>
  48. /// DataTable数据拷贝
  49. /// </summary>
  50. /// <param name="src">源</param>
  51. /// <param name="dest">目标</param>
  52. /// <param name="ClearExists">是否清除目标DataTable现有数据</param>
  53. public static void CopyDataToDatatable(ref DataTable src, ref DataTable dest, bool ClearExists)
  54. {
  55. try
  56. {
  57. if (src == null || dest == null)
  58. {
  59. return;
  60. }
  61. if (ClearExists)
  62. {
  63. dest.Rows.Clear();
  64. }
  65. DataRow CurRow, NewRow;
  66. for (int i = 0; i < src.Rows.Count; i++)
  67. {
  68. CurRow = src.Rows[i];
  69. NewRow = dest.NewRow();
  70. for (int j = 0; j < src.Columns.Count; j++)
  71. {
  72. try
  73. {
  74. if (dest.Columns.Contains(src.Columns[j].ColumnName))
  75. {
  76. NewRow[src.Columns[j].ColumnName] = CurRow[j];
  77. }
  78. }
  79. catch { }
  80. }
  81. dest.Rows.Add(NewRow);
  82. }
  83. dest.AcceptChanges();
  84. }
  85. catch { }
  86. }
  87. /// <summary>
  88. /// UltraGrid列宽自适应
  89. /// </summary>
  90. /// <param name="ultraGrid"></param>
  91. public static void RefreshAndAutoSize(UltraGrid ultraGrid)
  92. {
  93. try
  94. {
  95. ultraGrid.BeginUpdate();
  96. foreach (UltraGridBand band in ultraGrid.DisplayLayout.Bands)
  97. {
  98. foreach (UltraGridColumn column in band.Columns)
  99. {
  100. column.PerformAutoResize(PerformAutoSizeType.AllRowsInBand, band.ColHeadersVisible ? true : false);
  101. }
  102. }
  103. }
  104. catch { }
  105. ultraGrid.EndUpdate();
  106. }
  107. /// <summary>
  108. /// 设置UltraComboEditor项目集合
  109. /// </summary>
  110. /// <param name="cbEdt"></param>
  111. /// <param name="vlist"></param>
  112. /// <param name="bNull">是否加入空项</param>
  113. /// <returns></returns>
  114. public static bool SetUltraComboEditor(ref UltraComboEditor cbEdt, ref ValueList vlist, bool bNull)
  115. {
  116. if (cbEdt == null || vlist == null)
  117. return false;
  118. cbEdt.Items.Clear();
  119. if (bNull)
  120. cbEdt.Items.Add(null, "");
  121. for (int i = 0; i < vlist.ValueListItems.Count; i++)
  122. {
  123. try
  124. {
  125. cbEdt.Items.Add(vlist.ValueListItems[i].DataValue, vlist.ValueListItems[i].DisplayText);
  126. }
  127. catch { }
  128. }
  129. return true;
  130. }
  131. public static void SetUltraComboDataSource(UltraCombo cmb, DataTable table, string ColumnValue, string ColumnDisplay)
  132. {
  133. if (table == null || !table.Columns.Contains(ColumnValue) || !table.Columns.Contains(ColumnDisplay)) return;
  134. try
  135. {
  136. if (cmb != null)
  137. {
  138. cmb.DataSource = table;
  139. cmb.DisplayLayout.Override.TipStyleScroll = TipStyle.Hide;
  140. cmb.DisplayLayout.Override.BorderStyleCell = UIElementBorderStyle.None;
  141. cmb.DisplayLayout.Override.BorderStyleRow = UIElementBorderStyle.None;
  142. cmb.DisplayLayout.Override.SelectTypeRow = SelectType.Single;
  143. cmb.DisplayLayout.Override.HeaderStyle = HeaderStyle.Standard;
  144. cmb.DisplayLayout.Override.HeaderAppearance.TextHAlign = HAlign.Center;
  145. cmb.DisplayLayout.Override.RowAppearance.TextVAlign = VAlign.Middle;
  146. cmb.DisplayLayout.Override.ActiveRowAppearance.BackColor = Color.FromArgb(51, 153, 255);
  147. cmb.DisplayLayout.Override.ActiveRowAppearance.ForeColor = Color.FromArgb(255, 255, 255);
  148. cmb.DisplayLayout.Override.SelectedRowAppearance.BackColor = Color.FromArgb(51, 153, 255);
  149. cmb.DisplayLayout.Override.SelectedRowAppearance.ForeColor = Color.FromArgb(255, 255, 255);
  150. //cmb.DisplayLayout.Override.ActiveRowAppearance.FontData.Bold = DefaultableBoolean.True;
  151. foreach (UltraGridBand band in cmb.DisplayLayout.Bands)
  152. {
  153. band.ColHeadersVisible = false;
  154. foreach (UltraGridColumn column in band.Columns)
  155. {
  156. if (!column.Key.Equals(ColumnDisplay)) column.Hidden = true;
  157. column.Width = cmb.Width;
  158. //column.PerformAutoResize(PerformAutoSizeType.AllRowsInBand);
  159. }
  160. }
  161. cmb.ValueMember = ColumnValue;
  162. cmb.DisplayMember = ColumnDisplay;
  163. cmb.DropDownWidth = -1;
  164. }
  165. }
  166. catch { }
  167. }
  168. /// <summary>
  169. /// 设置ultraGrid的激活单元格
  170. /// </summary>
  171. /// <param name="ultraGrid"></param>
  172. /// <param name="RowIndexNo"></param>
  173. /// <param name="ColumnName"></param>
  174. /// <param name="EnterEditMode"></param>
  175. public static void SetUltraGridActiveCell(ref UltraGrid ultraGrid, int RowIndexNo, string ColumnName, bool EnterEditMode)
  176. {
  177. try
  178. {
  179. if (ultraGrid != null && RowIndexNo >= 0 && ultraGrid.Rows.Count >= RowIndexNo + 1)
  180. {
  181. ultraGrid.ActiveCell = ultraGrid.Rows[RowIndexNo].Cells[ColumnName];
  182. if (EnterEditMode)
  183. ultraGrid.PerformAction(UltraGridAction.EnterEditMode);
  184. }
  185. }
  186. catch { }
  187. }
  188. /// <summary>
  189. /// 设置UltraGrid指定列的ValueList
  190. /// </summary>
  191. /// <param name="myGrid"></param>
  192. /// <param name="strColumn"></param>
  193. /// <param name="vlist"></param>
  194. public static void SetGridValuelist(ref UltraGrid myGrid, string strColumn, ref ValueList vlist)
  195. {
  196. SetGridValuelist(ref myGrid, 0, strColumn, ref vlist);
  197. }
  198. /// <summary>
  199. /// 设置UltraGrid指定列的ValueList,指定Band
  200. /// </summary>
  201. /// <param name="myGrid"></param>
  202. /// <param name="BandIndex"></param>
  203. /// <param name="strColumn"></param>
  204. /// <param name="vlist"></param>
  205. public static void SetGridValuelist(ref UltraGrid myGrid, int BandIndex, string strColumn, ref ValueList vlist)
  206. {
  207. bool Contains = GridContainsColumn(myGrid, BandIndex, strColumn);
  208. try
  209. {
  210. if (Contains)
  211. {
  212. myGrid.DisplayLayout.Bands[BandIndex].Columns[strColumn].ValueList = vlist;
  213. //myGrid.DisplayLayout.Bands[BandIndex].Columns[strColumn].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDown;
  214. }
  215. }
  216. catch { }
  217. }
  218. /// <summary>
  219. /// 根据指定DataTable生成ValueList
  220. /// </summary>
  221. /// <param name="table"></param>
  222. /// <param name="strKey">value</param>
  223. /// <param name="strText">Text</param>
  224. /// <returns></returns>
  225. public static ValueList GeneralValuelist(ref DataTable table, string strKey, string strText)
  226. {
  227. if (table == null || !table.Columns.Contains(strKey) || !table.Columns.Contains(strText))
  228. return null;
  229. ArrayList alist = new ArrayList();
  230. ValueList vlist = new ValueList();
  231. for (int i = 0; i < table.Rows.Count; i++)
  232. {
  233. try
  234. {
  235. if (!alist.Contains(table.Rows[i][strKey]))
  236. {
  237. alist.Add(table.Rows[i][strKey]);
  238. vlist.ValueListItems.Add(table.Rows[i][strKey], Convert.ToString(table.Rows[i][strText]));
  239. }
  240. }
  241. catch { }
  242. }
  243. return vlist;
  244. }
  245. /// <summary>
  246. /// ultraGrid设置Cell只读属性
  247. /// </summary>
  248. /// <param name="ultraGrid"></param>
  249. /// <param name="bReadOnly"></param>
  250. public static void SetUltraGridCellReadOnly(ref UltraGrid ultraGrid, bool bReadOnly)
  251. {
  252. try
  253. {
  254. for (int i = 0; i < ultraGrid.DisplayLayout.Bands[0].Columns.Count; i++)
  255. {
  256. ultraGrid.DisplayLayout.Bands[0].Columns[i].CellActivation = (bReadOnly ? Activation.ActivateOnly : Activation.AllowEdit);
  257. ultraGrid.DisplayLayout.Bands[0].Columns[i].CellAppearance.BackColor = (bReadOnly ? Color.LightBlue : Color.White);
  258. }
  259. }
  260. catch { }
  261. }
  262. public static bool GridContainsColumn(UltraGrid grid, string strColumn)
  263. {
  264. return GridContainsColumn(grid, 0, strColumn);
  265. }
  266. public static bool GridContainsColumn(UltraGridBand band, string strColumn)
  267. {
  268. for (int i = 0; i < band.Columns.Count; i++)
  269. {
  270. if (band.Columns[i].Key.Equals(strColumn))
  271. return true;
  272. }
  273. return false;
  274. }
  275. public static bool GridContainsColumn(UltraGrid grid, int BandIndex, string strColumn)
  276. {
  277. if (BandIndex <= grid.DisplayLayout.Bands.Count - 1)
  278. {
  279. for (int i = 0; i < grid.DisplayLayout.Bands[BandIndex].Columns.Count; i++)
  280. {
  281. if (grid.DisplayLayout.Bands[BandIndex].Columns[i].Key.Equals(strColumn))
  282. return true;
  283. }
  284. }
  285. return false;
  286. }
  287. public static void SetGridGroupBy(ref UltraGrid myGrid1, bool bAllowGroupBy)
  288. {
  289. try
  290. {
  291. if (!bAllowGroupBy)
  292. {
  293. for (int i = 0; i < myGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
  294. {
  295. try
  296. {
  297. if (myGrid1.DisplayLayout.Bands[0].Columns[i].IsGroupByColumn)
  298. myGrid1.DisplayLayout.Bands[0].Columns[i].ResetIsGroupByColumn();
  299. }
  300. catch { }
  301. }
  302. }
  303. myGrid1.DisplayLayout.GroupByBox.Hidden = !bAllowGroupBy;
  304. }
  305. catch { }
  306. }
  307. public static void SetUltraGridRowFilter(ref UltraGrid myGrid1, bool bAllowFilter)
  308. {
  309. try
  310. {
  311. if (bAllowFilter)
  312. {
  313. if (myGrid1.DisplayLayout.Override.FilterUIType != FilterUIType.Default)
  314. myGrid1.DisplayLayout.Override.FilterUIType = FilterUIType.Default;
  315. for (int i = 0; i < myGrid1.DisplayLayout.Bands.Count; i++)
  316. {
  317. if (myGrid1.DisplayLayout.Bands[i].CardView) continue;
  318. for (int j = 0; j < myGrid1.DisplayLayout.Bands[i].Columns.Count; j++)
  319. {
  320. try
  321. {
  322. if (!myGrid1.DisplayLayout.Bands[i].Columns[j].Hidden &&
  323. myGrid1.DisplayLayout.Bands[i].Columns[j].RowLayoutColumnInfo.LabelPosition != LabelPosition.LabelOnly)
  324. myGrid1.DisplayLayout.Bands[i].Columns[j].AllowRowFiltering = Infragistics.Win.DefaultableBoolean.True;
  325. }
  326. catch { }
  327. }
  328. }
  329. }
  330. else
  331. {
  332. if (myGrid1.DisplayLayout.Override.FilterUIType != FilterUIType.Default)
  333. myGrid1.DisplayLayout.Override.FilterUIType = FilterUIType.Default;
  334. for (int i = 0; i < myGrid1.DisplayLayout.Bands.Count; i++)
  335. {
  336. try
  337. {
  338. myGrid1.DisplayLayout.Bands[i].ColumnFilters.ClearAllFilters();
  339. }
  340. catch { }
  341. for (int j = 0; j < myGrid1.DisplayLayout.Bands[i].Columns.Count; j++)
  342. {
  343. try
  344. {
  345. myGrid1.DisplayLayout.Bands[i].Columns[j].AllowRowFiltering = Infragistics.Win.DefaultableBoolean.False;
  346. }
  347. catch { }
  348. }
  349. }
  350. }
  351. }
  352. catch { }
  353. }
  354. public static void SetGridColumnsReadOnly(ref UltraGrid ultraGrid, ArrayList alistAllowEdit, ArrayList alistActivateOnly, ArrayList alistNoEdit, ArrayList alistDisabled)
  355. {
  356. try
  357. {
  358. for (int i = 0; i < ultraGrid.Rows.Count; i++)
  359. {
  360. if (alistAllowEdit != null && alistAllowEdit.Count > 0)
  361. {
  362. for (int j = 0; j < alistAllowEdit.Count; j++)
  363. {
  364. try
  365. {
  366. if (GridContainsColumn(ultraGrid, alistAllowEdit[j].ToString()))
  367. {
  368. ultraGrid.Rows[i].Cells[alistAllowEdit[j].ToString()].Activation = Activation.AllowEdit;
  369. }
  370. }
  371. catch (Exception ex)
  372. {
  373. Debug.WriteLine(ex.Message);
  374. }
  375. }
  376. }
  377. if (alistActivateOnly != null && alistActivateOnly.Count > 0)
  378. {
  379. for (int j = 0; j < alistActivateOnly.Count; j++)
  380. {
  381. try
  382. {
  383. if (GridContainsColumn(ultraGrid, alistActivateOnly[j].ToString()))
  384. {
  385. ultraGrid.Rows[i].Cells[alistActivateOnly[j].ToString()].Activation = Activation.ActivateOnly;
  386. }
  387. }
  388. catch (Exception ex)
  389. {
  390. Debug.WriteLine(ex.Message);
  391. }
  392. }
  393. }
  394. if (alistNoEdit != null && alistNoEdit.Count > 0)
  395. {
  396. for (int j = 0; j < alistNoEdit.Count; j++)
  397. {
  398. try
  399. {
  400. if (GridContainsColumn(ultraGrid, alistNoEdit[j].ToString()))
  401. {
  402. ultraGrid.Rows[i].Cells[alistNoEdit[j].ToString()].Activation = Activation.NoEdit;
  403. }
  404. }
  405. catch (Exception ex)
  406. {
  407. Debug.WriteLine(ex.Message);
  408. }
  409. }
  410. }
  411. if (alistDisabled != null && alistDisabled.Count > 0)
  412. {
  413. for (int j = 0; j < alistDisabled.Count; j++)
  414. {
  415. try
  416. {
  417. if (GridContainsColumn(ultraGrid, alistDisabled[j].ToString()))
  418. {
  419. ultraGrid.Rows[i].Cells[alistDisabled[j].ToString()].Activation = Activation.Disabled;
  420. }
  421. }
  422. catch (Exception ex)
  423. {
  424. Debug.WriteLine(ex.Message);
  425. }
  426. }
  427. }
  428. }
  429. }
  430. catch (Exception ex)
  431. {
  432. Debug.WriteLine(ex.Message);
  433. }
  434. }
  435. public static bool HasCheckedRows(ref UltraGrid ultraGrid, string strColumnCondition, object value, string strOutColumn, out ArrayList alistValue, out string strMsg)
  436. {
  437. strMsg = "";
  438. alistValue = new ArrayList();
  439. try
  440. {
  441. if (ultraGrid == null || ultraGrid.Rows.Count == 0)
  442. {
  443. return false;
  444. }
  445. if (!string.IsNullOrEmpty(strColumnCondition))
  446. {
  447. if (!GridContainsColumn(ultraGrid, 0, strColumnCondition))
  448. {
  449. strMsg = "不存在条件字段【" + strColumnCondition + "】!";
  450. return false;
  451. }
  452. }
  453. if (string.IsNullOrEmpty(strOutColumn))
  454. {
  455. strMsg = "未指定输出字段【" + strOutColumn + "】!";
  456. return false;
  457. }
  458. if (!GridContainsColumn(ultraGrid, 0, strOutColumn))
  459. {
  460. strMsg = "不存在输出字段【" + strOutColumn + "】!";
  461. return false;
  462. }
  463. for (int i = 0; i < ultraGrid.Rows.Count; i++)
  464. {
  465. if (!string.IsNullOrEmpty(strColumnCondition))
  466. {
  467. if (ultraGrid.Rows[i].Cells[strColumnCondition].Value.Equals(value))
  468. {
  469. if (ultraGrid.Rows[i].Cells["FCFLAG"].Value.ToString() != "校磅")
  470. alistValue.Add(ultraGrid.Rows[i].Cells[strOutColumn].Value);
  471. }
  472. }
  473. else
  474. {
  475. if (ultraGrid.Rows[i].Cells["FCFLAG"].Value.ToString() != "校磅")
  476. alistValue.Add(ultraGrid.Rows[i].Cells[strOutColumn].Value);
  477. }
  478. }
  479. return true;
  480. }
  481. catch (Exception ex)
  482. {
  483. strMsg = ex.Message;
  484. alistValue = null;
  485. }
  486. return false;
  487. }
  488. private static UltraGridExcelExporter ultraGridExcelExporter1 = new UltraGridExcelExporter();
  489. /// <summary>
  490. /// 判断系统是否安装EXCEL组件
  491. /// </summary>
  492. /// <returns></returns>
  493. public static bool ExcelInstalled()
  494. {
  495. bool bInstalled = (Type.GetTypeFromProgID("Excel.Application") != null);
  496. if (!bInstalled)
  497. {
  498. MessageBox.Show("系统没有安装EXCEL组件,无法导出数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  499. }
  500. return bInstalled;
  501. }
  502. public static void ExportDataWithSaveDialog2(ref UltraGrid myGrid1, string strFileName)
  503. {
  504. try
  505. {
  506. if (myGrid1.Rows.Count == 0) return;
  507. if (strFileName.Length == 0) strFileName = "未命名";
  508. SaveFileDialog dlg = new SaveFileDialog();
  509. dlg.Title = "保存";
  510. dlg.OverwritePrompt = true;
  511. dlg.Filter = "Excel文件(*.xls)|*.xls";
  512. dlg.AddExtension = true;
  513. dlg.FileName = strFileName;
  514. if (dlg.ShowDialog() == DialogResult.OK)
  515. {
  516. strFileName = dlg.FileName;
  517. ultraGridExcelExporter1.Export(myGrid1, strFileName);
  518. if (MessageBox.Show("数据导出成功!\n需要打开所导出文件吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  519. {
  520. ProcessStartInfo p = new ProcessStartInfo(strFileName);
  521. p.WorkingDirectory = Path.GetDirectoryName(strFileName);
  522. Process.Start(p);
  523. }
  524. }
  525. }
  526. catch (Exception ex)
  527. {
  528. MessageBox.Show(ex.Message);
  529. }
  530. }
  531. public static bool IPCheck(string IP)
  532. {
  533. string Segment = @"(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)";
  534. return Regex.IsMatch(IP, ("^" + Segment + @"\." + Segment + @"\." + Segment + @"\." + Segment + "$"));
  535. }
  536. public static bool Pinging(string IP)
  537. {
  538. try
  539. {
  540. Ping ping = new Ping();
  541. PingOptions options = new PingOptions();
  542. options.DontFragment = true;
  543. byte[] buffer = Encoding.ASCII.GetBytes("TEST PING");
  544. PingReply reply = ping.Send(IP, 3000, buffer, options);
  545. if (reply.Status == IPStatus.Success)
  546. {
  547. return true;
  548. }
  549. }
  550. catch { }
  551. return false;
  552. }
  553. public static bool PrinterExists(string strPrinterName)
  554. {
  555. if (string.IsNullOrEmpty(strPrinterName))
  556. return false;
  557. foreach (string printerName in PrinterSettings.InstalledPrinters)
  558. {
  559. if (strPrinterName.Equals(printerName))
  560. return true;
  561. }
  562. return false;
  563. }
  564. public static bool FontFamilyNameExists(string strFontFamilyName)
  565. {
  566. if (string.IsNullOrEmpty(strFontFamilyName))
  567. return false;
  568. foreach (FontFamily fontfamily in FontFamily.Families)
  569. {
  570. if (strFontFamilyName.Equals(fontfamily.Name))
  571. return true;
  572. }
  573. return false;
  574. }
  575. public static void ResetHashtable(ref Hashtable htbl)
  576. {
  577. if (htbl == null)
  578. htbl = new Hashtable();
  579. else
  580. htbl.Clear();
  581. }
  582. public static void ResetArraylist(ref ArrayList alist)
  583. {
  584. if (alist == null)
  585. alist = new ArrayList();
  586. else
  587. alist.Clear();
  588. }
  589. public static bool CheckComboBoxSelection(UltraComboEditor cbEdit, string Caption, bool MustSelect, bool ShowError, out string Message)
  590. {
  591. Message = "";
  592. try
  593. {
  594. if (cbEdit != null)
  595. {
  596. if (MustSelect)
  597. {
  598. if (cbEdit.SelectedIndex < 0)
  599. {
  600. Message = cbEdit.Text.Trim().Length > 0 ? Caption + "不正确,请从列表中选取!" : "请选择" + Caption + "!";
  601. if (ShowError)
  602. MessageBox.Show(Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  603. return false;
  604. }
  605. }
  606. else
  607. {
  608. if (cbEdit.SelectedIndex < 0 && cbEdit.Text.Trim().Length > 0)
  609. {
  610. Message = Caption + "不正确,请从列表中选取!";
  611. if (ShowError)
  612. MessageBox.Show(Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  613. return false;
  614. }
  615. }
  616. }
  617. return true;
  618. }
  619. catch (Exception ex)
  620. {
  621. Message = Caption + "验证出错!\n" + ex.Message;
  622. if (ShowError)
  623. MessageBox.Show(Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  624. return false;
  625. }
  626. }
  627. public static void SetUltraGridColumnColor(ValueList colorList, string columnName, UltraGrid ultraGrid1)
  628. {
  629. try
  630. {
  631. Infragistics.Win.Appearance apprc;
  632. OperatorCondition oc;
  633. ConditionValueAppearance cva = new ConditionValueAppearance();
  634. for (int i = 0; i < colorList.ValueListItems.Count; i++)
  635. {
  636. apprc = new Infragistics.Win.Appearance();
  637. if (i == 0)
  638. apprc.BackColor = Color.Cornsilk;
  639. else if (i == 1)
  640. apprc.BackColor = Color.Gainsboro;
  641. else if (i == 2)
  642. apprc.BackColor = Color.LightSkyBlue;
  643. else if (i == 3)
  644. apprc.BackColor = Color.PaleGreen;
  645. else if (i == 4)
  646. apprc.BackColor = Color.Lime;
  647. oc = new OperatorCondition(ConditionOperator.Equals, colorList.ValueListItems[0].DisplayText, false, typeof(string));
  648. cva.Add((ICondition)oc, apprc);
  649. }
  650. ultraGrid1.DisplayLayout.Bands[0].Columns[columnName].ValueBasedAppearance = cva;
  651. }
  652. catch { }
  653. }
  654. public static void SetStaticsInfoCount(ref UltraGrid myGrid1, ArrayList alistColumns, bool clearExists)
  655. {
  656. try
  657. {
  658. UltraGridBand band = myGrid1.DisplayLayout.Bands[0];
  659. if (clearExists)
  660. band.Summaries.Clear();
  661. band.Override.SummaryFooterCaptionVisible = Infragistics.Win.DefaultableBoolean.False;
  662. for (int i = 0; i < alistColumns.Count; i++)
  663. {
  664. try
  665. {
  666. SummarySettings summary = band.Summaries.Add(SummaryType.Count, band.Columns[alistColumns[i].ToString()]);
  667. summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
  668. summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
  669. summary.DisplayFormat = "{0}";
  670. summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
  671. summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
  672. summary.Appearance.FontData.Bold = DefaultableBoolean.True;
  673. }
  674. catch { }
  675. }
  676. }
  677. catch { }
  678. }
  679. public static void SetStaticsInfoSum(ref UltraGrid myGrid1, ArrayList alistColumns, bool clearExists)
  680. {
  681. try
  682. {
  683. UltraGridBand band = myGrid1.DisplayLayout.Bands[0];
  684. if (clearExists)
  685. band.Summaries.Clear();
  686. band.Override.SummaryFooterCaptionVisible = Infragistics.Win.DefaultableBoolean.False;
  687. for (int i = 0; i < alistColumns.Count; i++)
  688. {
  689. try
  690. {
  691. SummarySettings summary = band.Summaries.Add(SummaryType.Sum, band.Columns[alistColumns[i].ToString()]);
  692. summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
  693. summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
  694. summary.DisplayFormat = "{0}";
  695. summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
  696. summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
  697. summary.Appearance.FontData.Bold = DefaultableBoolean.True;
  698. }
  699. catch { }
  700. }
  701. }
  702. catch { }
  703. }
  704. public static void ClearUltraGridColumnsSort(UltraGrid ultraGrid)
  705. {
  706. if (ultraGrid != null)
  707. {
  708. foreach (UltraGridBand band in ultraGrid.DisplayLayout.Bands)
  709. {
  710. foreach (UltraGridColumn col in band.Columns)
  711. {
  712. if (col.SortIndicator == SortIndicator.Disabled)
  713. continue;
  714. col.SortIndicator = SortIndicator.None;
  715. }
  716. }
  717. }
  718. }
  719. public static DataTable ConvertToDataTable(IList list)
  720. {
  721. DataTable table = new DataTable();
  722. if ((list != null) && (list.Count > 0))
  723. {
  724. Hashtable hashtable2;
  725. Hashtable hashtable = (Hashtable)list[0];
  726. foreach (DictionaryEntry entry in hashtable)
  727. {
  728. string columnName = entry.Key.ToString();
  729. if (entry.Value == null)
  730. {
  731. table.Columns.Add(columnName, typeof(string));
  732. }
  733. else if ((entry.Value != null) && typeof(Hashtable).Equals(entry.Value.GetType()))
  734. {
  735. hashtable2 = (Hashtable)entry.Value;
  736. table.Columns.Add(columnName, hashtable2["value"].GetType());
  737. }
  738. else
  739. {
  740. table.Columns.Add(columnName, entry.Value.GetType());
  741. }
  742. }
  743. for (int i = 0; i < list.Count; i++)
  744. {
  745. hashtable = (Hashtable)list[i];
  746. ArrayList list2 = new ArrayList();
  747. foreach (DictionaryEntry entry in hashtable)
  748. {
  749. if ((entry.Value != null) && typeof(Hashtable).Equals(entry.Value.GetType()))
  750. {
  751. hashtable2 = (Hashtable)entry.Value;
  752. list2.Add(hashtable2["value"]);
  753. }
  754. else
  755. {
  756. list2.Add(entry.Value);
  757. }
  758. }
  759. table.LoadDataRow(list2.ToArray(), true);
  760. }
  761. }
  762. return table;
  763. }
  764. /// <summary>
  765. /// 某个空间是否某个特定的类型
  766. /// </summary>
  767. /// <param name="ctrl"></param>
  768. /// <param name="SomeType"></param>
  769. /// <returns></returns>
  770. public static bool SpecificType(Control ctrl, Type SomeType)
  771. {
  772. if (ctrl == null || SomeType == null) return false;
  773. Type type = ctrl.GetType();
  774. while (type != null)
  775. {
  776. if (type.Equals(SomeType))
  777. return true;
  778. type = type.BaseType;
  779. }
  780. return false;
  781. }
  782. }
  783. }