BaseHelper.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using Core.Mes.Client.Comm.Server;
  8. using Core.Mes.Client.Comm.Tool;
  9. using CoreFS.CA06;
  10. using Infragistics.Win.UltraWinEditors;
  11. using Infragistics.Win.UltraWinGrid;
  12. using Infragistics.Win.UltraWinMaskedEdit;
  13. using Infragistics.Win;
  14. using System.Collections;
  15. using System.Text.RegularExpressions;
  16. using System.ComponentModel;
  17. using System.Runtime.CompilerServices;
  18. using System.Windows.Forms;
  19. namespace Core.StlMes.Client.Mcp.BaseMethod
  20. {
  21. public class BaseHelper
  22. {
  23. /// <summary>
  24. /// 仓库数据权限(用于报表)
  25. /// </summary>
  26. /// <param name="customInfo">页面配制信息(自定义参数)</param>
  27. /// <param name="validDataPurviewIds">用户数据权限</param>
  28. /// <returns>可查看仓库组成的字符串</returns>
  29. public static string[] WarehousePermissionsStore1(String[] validDataPurviewIds, OpeBase ob)
  30. {
  31. DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.CollarLibrary.FrmCollarOutBound.getWarehousePermissionsStore", new object[] { validDataPurviewIds }, ob);
  32. if (dt != null && dt.Rows.Count > 0)
  33. {
  34. string[] storages = new string[dt.Rows.Count];
  35. for (int i = 0; i < dt.Rows.Count; i++)
  36. {
  37. storages[i] = dt.Rows[i]["STORAGE_NO"].ToString();
  38. }
  39. return storages;
  40. }
  41. else
  42. {
  43. return new string[1] { "" };
  44. }
  45. }
  46. /// <summary>
  47. /// 通过科室查找对应的部门
  48. /// </summary>
  49. /// <param name="sectionName">科室ID</param>
  50. /// <param name="ob"></param>
  51. /// <returns>部门名称</returns>
  52. public static string GetDepartBySectionId1(string sectionId, OpeBase ob)
  53. {
  54. DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.CollarLibrary.FrmCollarOutBound.getDeptBySection", new object[] { sectionId }, ob);
  55. if (dt.Rows.Count > 0)
  56. {
  57. return dt.Rows[0]["DEPARTNAME"].ToString();
  58. }
  59. else
  60. {
  61. return "";
  62. }
  63. }
  64. /// <summary>
  65. /// 通过科室查找对应的部门
  66. /// </summary>
  67. /// <param name="sectionName">科室ID</param>
  68. /// <param name="ob"></param>
  69. /// <returns>部门ID</returns>
  70. public static string GetDepartIdBySectionId1(string sectionId, OpeBase ob)
  71. {
  72. DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.CollarLibrary.FrmCollarOutBound.getDeptBySection", new object[] { sectionId }, ob);
  73. if (dt.Rows.Count > 0)
  74. {
  75. return dt.Rows[0]["DEPARTID"].ToString();
  76. }
  77. else
  78. {
  79. return "";
  80. }
  81. }
  82. public static string[] SetData(string methodId, object[] param, OpeBase ob)
  83. {
  84. CoreClientParam ccp = new CoreClientParam();
  85. ccp.ServerName = methodId.Substring(0, methodId.LastIndexOf("."));
  86. ccp.MethodName = methodId.Substring(methodId.LastIndexOf(".") + 1);
  87. ccp.ServerParams = param;
  88. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  89. if (ccp.ReturnCode == -1)
  90. {
  91. return null;
  92. }
  93. else
  94. {
  95. string[] strArray = new string[2];
  96. strArray[0] = ccp.ReturnObject.ToString();
  97. strArray[1] = ccp.ReturnInfo;
  98. return strArray;
  99. }
  100. }
  101. /// <summary>
  102. /// 设置Grid统计格式
  103. ///
  104. /// </summary>
  105. /// <param name="Arrsumtype"></param>统计格式集合
  106. /// <param name="HeadeVale"></param>显示格式
  107. /// <param name="ColumName"></param>列名
  108. /// <param name="band"></param>
  109. /// <param name="areas"></param>位置
  110. public static void SetupSummaryHeade(string[] Arrsumtype, string[] HeadeVale, string[] ColumName, UltraGridBand band, SummaryDisplayAreas areas)
  111. {
  112. if (HeadeVale.Length != Arrsumtype.Length && Arrsumtype.Length != ColumName.Length)
  113. {
  114. return;
  115. }
  116. SummaryType sumType; ;
  117. for (int i = 0; i < HeadeVale.Length; i++)
  118. {
  119. //SummaryType.Count 统计 Average平均值 Maximum最大值 Minimum 最小值 Sum 求和
  120. if (Arrsumtype[i] == "Count")
  121. {
  122. sumType = SummaryType.Count;
  123. }
  124. else if (Arrsumtype[i] == "Maximum")
  125. {
  126. sumType = SummaryType.Maximum;
  127. }
  128. else if (Arrsumtype[i] == "Minimum")
  129. {
  130. sumType = SummaryType.Minimum;
  131. }
  132. else
  133. {
  134. sumType = SummaryType.Sum;
  135. }
  136. if (band.Columns.Exists(ColumName[i]))
  137. {
  138. SummarySettings summary = band.Summaries.Add(sumType, band.Columns[ColumName[i]]);
  139. summary.SummaryDisplayArea = areas;
  140. summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
  141. summary.DisplayFormat = HeadeVale[i];
  142. summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Center;
  143. summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
  144. //summary.Appearance.ForeColor = Color.Black;
  145. //summary.Appearance.BackColor = Color.FromArgb(248, 253, 180);
  146. }
  147. }
  148. Infragistics.Win.Appearance appearance21 = new Infragistics.Win.Appearance();
  149. Infragistics.Win.Appearance appearance20 = new Infragistics.Win.Appearance();
  150. appearance20.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(224)))), ((int)(((byte)(192)))));
  151. band.Override.SummaryFooterAppearance = appearance20;
  152. appearance21.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(224)))), ((int)(((byte)(192)))));
  153. appearance21.TextHAlignAsString = "Right";
  154. band.Override.SummaryValueAppearance = appearance21;
  155. }
  156. /// <summary>
  157. /// 查询选择记录
  158. /// </summary>
  159. /// <typeparam name="T">类名</typeparam>
  160. /// <param name="ug">Grid</param>
  161. /// <param name="columns">列</param>
  162. /// <param name="value">对应值</param>
  163. /// <returns></returns>
  164. public static ArrayList GetRows<T>(UltraGrid ug, string columns, string value)
  165. {
  166. try { ug.UpdateData(); }
  167. catch (Exception) { return null; }
  168. IQueryable<UltraGridRow> chcRows = ug.Rows.AsQueryable().Where(a => a.GetValue(columns) == value);
  169. if (chcRows == null || chcRows.Count() == 0)
  170. {
  171. return null;
  172. }
  173. ArrayList list = new ArrayList();
  174. foreach (UltraGridRow ugr in chcRows)
  175. {
  176. T t = (T)ugr.ListObject;
  177. list.Add(t);
  178. }
  179. return list;
  180. }
  181. /// <summary>
  182. /// 控制行
  183. /// </summary>
  184. /// <param name="row"></param>
  185. public static void ControlCellEdit(UltraGridRow row)
  186. {
  187. foreach (UltraGridCell cell in row.Cells)
  188. {
  189. if (cell.Column.CellAppearance.BackColor == Color.FromArgb(255, 255, 128))
  190. {
  191. if (row.Cells["CHC"].Value.ToString() == "True")
  192. {
  193. cell.Activation = Activation.AllowEdit;
  194. }
  195. else
  196. {
  197. cell.Activation = Activation.ActivateOnly;
  198. }
  199. }
  200. else
  201. {
  202. if (!cell.Column.Key.Equals("CHC"))
  203. {
  204. cell.Activation = Activation.ActivateOnly;
  205. }
  206. }
  207. }
  208. }
  209. /// <summary>
  210. /// UltraGrid可读(非主从结构)
  211. /// </summary>
  212. /// <param name="ugr">UltraGrid</param>
  213. /// <param name="keys">可编辑列</param>
  214. public static void setOtherColumnReadOnly(UltraGrid ugr, string[] keys)
  215. {
  216. if (keys == null || keys.Length == 0)
  217. {
  218. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
  219. {
  220. ugc.CellActivation = Activation.ActivateOnly;
  221. }
  222. }
  223. else
  224. {
  225. keys.ToArray();
  226. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
  227. {
  228. if (!keys.Contains(ugc.Key))
  229. {
  230. ugc.CellActivation = Activation.ActivateOnly;
  231. }
  232. }
  233. }
  234. }
  235. /// <summary>
  236. /// UltraGrid可读(主从结构)
  237. /// </summary>
  238. /// <param name="ugr"></param>
  239. /// <param name="keys"></param>
  240. public static void setColumnReadOnly(UltraGrid ugr, string[] keys)
  241. {
  242. keys.ToArray();
  243. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
  244. {
  245. if (!keys.Contains(ugc.Key))
  246. {
  247. ugc.CellActivation = Activation.ActivateOnly;
  248. }
  249. }
  250. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[1].Columns)
  251. {
  252. if (!keys.Contains(ugc.Key))
  253. {
  254. ugc.CellActivation = Activation.ActivateOnly;
  255. }
  256. }
  257. }
  258. /// <summary>
  259. /// 设置列背景颜色
  260. /// </summary>
  261. /// <param name="ugr">UltraGrid</param>
  262. /// <param name="columns">列数组</param>
  263. public static void setColumnBackColor(UltraGrid ugr, String[] columns)
  264. {
  265. for (int i = 0; i < columns.Length; i++)
  266. {
  267. ugr.DisplayLayout.Bands[0].Columns[columns[i]].CellAppearance.BackColor = Color.FromArgb(255, 255, 128);
  268. }
  269. }
  270. /// <summary>
  271. /// 设置列字段显示位置在右
  272. /// </summary>
  273. /// <param name="ug">UltraGrid</param>
  274. /// <param name="columnsKeys">要设置的列</param>
  275. public static void InitCellPosition(UltraGrid ug, string[] columnsKeys)
  276. {
  277. if (columnsKeys == null || columnsKeys.Length == 0)
  278. {
  279. return;
  280. }
  281. columnsKeys.ToArray();
  282. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns)
  283. {
  284. if (columnsKeys.Contains(ugc.Key.ToString()))
  285. {
  286. ugc.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right;
  287. }
  288. }
  289. }
  290. /// <summary>
  291. /// 设置列字段显示位置在右
  292. /// </summary>
  293. /// <param name="ug">UltraGrid从表</param>
  294. /// <param name="columnsKeys">要设置的列</param>
  295. public static void InitCellPositionC(UltraGrid ug, string[] columnsKeys)
  296. {
  297. columnsKeys.ToArray();
  298. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[1].Columns)
  299. {
  300. if (columnsKeys.Contains(ugc.Key.ToString()))
  301. {
  302. ugc.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right;
  303. }
  304. }
  305. }
  306. /// <summary>
  307. /// 列求和
  308. /// </summary>
  309. /// <param name="ug">UltraGrid</param>
  310. /// <param name="columnKeys">列数组</param>
  311. public static void GridColumnSum(UltraGrid ug, string[] columnKeys, string[] descritions)
  312. {
  313. if (columnKeys.Length == 0 || descritions.Length != columnKeys.Length)
  314. {
  315. return;
  316. }
  317. for (int i = 0; i < columnKeys.Length; i++)
  318. {
  319. SummarySettings summary = ug.DisplayLayout.Bands[0].Summaries.Add(SummaryType.Sum, ug.DisplayLayout.Bands[0].Columns[columnKeys[i]], SummaryPosition.UseSummaryPositionColumn);
  320. summary.DisplayFormat = "{0}" + descritions[i];
  321. summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
  322. }
  323. }
  324. /// <summary>
  325. /// 列求和
  326. /// </summary>
  327. /// <param name="ug"></param>
  328. /// <param name="columnKeys"></param>
  329. public static void GridColumnSum(UltraGrid ug, string[] columnKeys)
  330. {
  331. if (columnKeys.Length == 0)
  332. {
  333. return;
  334. }
  335. for (int i = 0; i < columnKeys.Length; i++)
  336. {
  337. SummarySettings summary = ug.DisplayLayout.Bands[0].Summaries.Add(SummaryType.Sum, ug.DisplayLayout.Bands[0].Columns[columnKeys[i]], SummaryPosition.UseSummaryPositionColumn);
  338. summary.DisplayFormat = "{0:N3}";
  339. summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
  340. }
  341. }/// <summary>
  342. /// 列求和
  343. /// </summary>
  344. /// <param name="ug">UltraGrid</param>
  345. /// <param name="columnKeys">列数组(支)</param>
  346. public static void GridColumnCount(UltraGrid ug, string[] columnKeys)
  347. {
  348. if (columnKeys.Length == 0)
  349. {
  350. return;
  351. }
  352. for (int i = 0; i < columnKeys.Length; i++)
  353. {
  354. SummarySettings summary = ug.DisplayLayout.Bands[0].Summaries.Add(SummaryType.Sum, ug.DisplayLayout.Bands[0].Columns[columnKeys[i]], SummaryPosition.UseSummaryPositionColumn);
  355. summary.DisplayFormat = "{0:N0}";
  356. summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
  357. }
  358. }
  359. /// <summary>
  360. /// 设置UltraGrid行颜色
  361. /// </summary>
  362. /// <param name="ug">UltraGrid</param>
  363. /// <param name="columnKeys">列</param>
  364. /// <param name="values">值</param>
  365. /// <param name="color">颜色</param>
  366. public static void SetUltraGridRowColor(UltraGrid ug, string[] columnKeys, string[] values, Color color)
  367. {
  368. if (ug.Rows.Count == 0 || columnKeys.Length == 0 || values.Length == 0 || color == null || values.Length != columnKeys.Length)
  369. {
  370. return;
  371. }
  372. foreach (UltraGridRow ugr in ug.Rows)
  373. {
  374. Boolean flag = true;
  375. for (int i = 0; i < columnKeys.Length; i++)
  376. {
  377. if (!ugr.Cells[columnKeys[i]].Value.ToString().Equals(values[i]))
  378. {
  379. flag = false;
  380. }
  381. }
  382. if (flag)
  383. {
  384. ugr.Appearance.BackColor = color;
  385. }
  386. }
  387. }
  388. /// <summary>
  389. /// 合并单元格
  390. /// </summary>
  391. /// <param name="ug"></param>
  392. /// <param name="columnKeys"></param>
  393. public static void MergedCell(UltraGrid ug, string[] columnKeys)
  394. {
  395. if (columnKeys.Length == 0)
  396. {
  397. return;
  398. }
  399. ug.DisplayLayout.Override.MergedCellStyle = MergedCellStyle.Never;
  400. for (int i = 0; i < columnKeys.Length; i++)
  401. {
  402. ug.DisplayLayout.Bands[0].Columns[columnKeys[i]].MergedCellStyle = MergedCellStyle.Always;
  403. }
  404. }
  405. /// <summary>
  406. /// 设置ULTRAGIRD列的颜色
  407. /// </summary>
  408. /// <param name="ug">ultragrid</param>
  409. /// <param name="arr">列Key</param>
  410. /// <param name="color">颜色</param>
  411. public static void setUltraGridColumnColor(UltraGrid ug, string[] arr, Color color)
  412. {
  413. if (arr == null || arr.Length == 0 || ug == null)
  414. {
  415. return;
  416. }
  417. arr.ToArray();
  418. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns)
  419. {
  420. if (arr.Contains(ugc.Key.ToString()))
  421. {
  422. ugc.CellAppearance.BackColor = color;
  423. }
  424. }
  425. }
  426. /// <summary>
  427. /// 设置列显示位数
  428. /// </summary>
  429. /// <param name="ug"></param>
  430. /// <param name="arr"></param>
  431. public static void setUltraGridColumnMaxInput(UltraGrid ug, string[] arr)
  432. {
  433. if (ug == null || arr == null || arr.Length == 0)
  434. {
  435. return;
  436. }
  437. arr.ToArray();
  438. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns)
  439. {
  440. if (arr.Contains(ugc.Key.ToString()))
  441. {
  442. ugc.MaskDisplayMode = MaskMode.IncludeLiterals;
  443. ugc.MaskInput = "{LOC}-n,nnn,nnn.nnn";
  444. }
  445. }
  446. }
  447. /// <summary>
  448. /// 设置列显示位数
  449. /// </summary>
  450. /// <param name="ug"></param>
  451. /// <param name="arr"></param>
  452. public static void setUltraGridColumnBits(UltraGrid ug, string[] arr)
  453. {
  454. if (ug == null || arr == null || arr.Length == 0)
  455. {
  456. return;
  457. }
  458. arr.ToArray();
  459. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns)
  460. {
  461. if (arr.Contains(ugc.Key.ToString()))
  462. {
  463. ugc.MaskDisplayMode = MaskMode.IncludeLiterals;
  464. ugc.MaskInput = "{LOC}-nn,nnn,nnn";
  465. }
  466. }
  467. }
  468. /// <summary>
  469. /// 列绑定下拉框
  470. /// </summary>
  471. /// <param name="uce">下拉框</param>
  472. /// <param name="column">列名</param>
  473. /// <param name="column">行</param>
  474. public static void BindColumn(UltraComboEditor uce, string column, UltraGridBand ugb)
  475. {
  476. ugb.Columns[column].EditorComponent = uce;
  477. ugb.Columns[column].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
  478. }
  479. /// <summary>
  480. /// 初始化下拉框
  481. /// </summary>
  482. /// <param name="uce">下拉框</param>
  483. /// <param name="methodID">方法名</param>
  484. /// <param name="showValue">显示值</param>
  485. /// <param name="hiddenValue">隐藏值</param>
  486. /// <param name="isNull">是否增加空行</param>
  487. /// <param name="ob">OB对象</param>
  488. public static void NitializeDropDownBox(UltraComboEditor uce, string methodID, string showValue, string hiddenValue, Boolean isNull, OpeBase ob)
  489. {
  490. DataTable dt = ServerHelper.GetData(methodID, new Object[] { }, ob);
  491. if (dt != null && dt.Rows.Count > 0 && isNull)
  492. {
  493. DataRow dr = dt.NewRow();
  494. for (int i = 0; i < dt.Columns.Count; i++)
  495. {
  496. dr[i] = "";
  497. }
  498. dt.Rows.InsertAt(dr, 0);
  499. }
  500. uce.DataSource = dt;
  501. uce.DisplayMember = showValue;
  502. uce.ValueMember = hiddenValue;
  503. ClsBaseInfo.SetComboItemHeight(uce);
  504. }
  505. /// <summary>
  506. /// 初始化下拉框
  507. /// </summary>
  508. /// <param name="uce">下拉框</param>
  509. /// <param name="methodID">方法名</param>
  510. /// <param name="methodID">参数</param>
  511. /// <param name="showValue">显示值</param>
  512. /// <param name="hiddenValue">隐藏值</param>
  513. /// <param name="isNull">是否增加空行</param>
  514. /// <param name="ob">OB对象</param>
  515. public static void NitializeDropDownBox(UltraComboEditor uce, string methodID, Object[] param, string showValue, string hiddenValue, Boolean isNull, OpeBase ob)
  516. {
  517. DataTable dt = ServerHelper.GetData(methodID, param, ob);
  518. if (dt != null && dt.Rows.Count > 0 && isNull)
  519. {
  520. DataRow dr = dt.NewRow();
  521. for (int i = 0; i < dt.Columns.Count; i++)
  522. {
  523. dr[i] = "";
  524. }
  525. dt.Rows.InsertAt(dr, 0);
  526. }
  527. uce.DropDownListWidth = -1;
  528. uce.DropDownStyle = DropDownStyle.DropDownList;
  529. uce.DataSource = dt;
  530. uce.DisplayMember = showValue;
  531. uce.ValueMember = hiddenValue;
  532. ClsBaseInfo.SetComboItemHeight(uce);
  533. }
  534. private Object setObjectByDataRow(Object obj, DataRow dr)
  535. {
  536. System.Reflection.PropertyInfo[] properties = obj.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
  537. foreach (System.Reflection.PropertyInfo item in properties)
  538. {
  539. string name = item.Name;
  540. string value = item.GetValue(obj, null).ToString();
  541. for (int i = 0; i < dr.Table.Columns.Count; i++)
  542. {
  543. if (dr.Table.Columns[i].ColumnName.ToString().Equals(name))
  544. {
  545. item.SetValue(obj, dr[i].ToString(), null);
  546. }
  547. }
  548. }
  549. return obj;
  550. }
  551. private Object setObjectByDataTable(Object obj, DataTable dt)
  552. {
  553. System.Reflection.PropertyInfo[] properties = obj.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
  554. foreach (System.Reflection.PropertyInfo item in properties)
  555. {
  556. string name = item.Name;
  557. string value = item.GetValue(obj, null).ToString();
  558. foreach (DataRow dr in dt.Rows)
  559. {
  560. {
  561. if (dr[0].ToString().Equals(name))
  562. item.SetValue(obj, dr[1].ToString(), null);
  563. }
  564. }
  565. }
  566. return obj;
  567. }
  568. /// <summary>
  569. /// 禁止排序
  570. /// </summary>
  571. /// <param name="ugr"></param>
  572. public static void ForbidSort(UltraGrid ugr)
  573. {
  574. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
  575. {
  576. ugc.SortIndicator = SortIndicator.Disabled;
  577. }
  578. }
  579. /// <summary>
  580. /// 用于初始化F1功能加字段问题
  581. /// </summary>
  582. /// <typeparam name="T"></typeparam>
  583. /// <param name="frm"></param>
  584. /// <param name="ug"></param>
  585. public static void SetGridColunmName<T>(FrmBase frm, UltraGrid ug)
  586. {
  587. System.Threading.Thread.Sleep(3000);
  588. if (!frm.IsDisposed)
  589. {
  590. EntityHelper.ShowGridCaption<T>(ug.DisplayLayout.Bands[0]);
  591. }
  592. }
  593. /// <summary>
  594. /// 设置列居中
  595. /// </summary>
  596. /// <param name="ug"></param>
  597. /// <param name="columnsKeys"></param>
  598. public static void InitCellPositionMiddle(UltraGrid ug, string[] columnsKeys)
  599. {
  600. columnsKeys.ToArray();
  601. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns)
  602. {
  603. if (columnsKeys.Contains(ugc.Key.ToString()))
  604. {
  605. ugc.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Center;
  606. }
  607. }
  608. }
  609. /// <summary>
  610. /// 激活行选中
  611. /// </summary>
  612. /// <param name="ug"></param>
  613. public static void SetRowChecked(UltraGrid ug)
  614. {
  615. foreach (UltraGridRow ugr in ug.Rows)
  616. {
  617. if (ugr.Activated)
  618. {
  619. ugr.Cells["CHC"].Value = true;
  620. }
  621. else
  622. {
  623. ugr.Cells["CHC"].Value = false;
  624. }
  625. }
  626. }
  627. /// <summary>
  628. /// 初始化下拉框(增强型)
  629. /// </summary>
  630. /// <param name="uce">下拉框</param>
  631. /// <param name="methodId">请求的服务</param>
  632. /// <param name="valueMember">值成员</param>
  633. /// <param name="textMember">显示成员</param>
  634. /// <param name="ob">ob对象</param>
  635. /// <param name="isEmpty">是否添加空行</param>
  636. public static void InitComboEditorNew(UltraComboEditor uce, string methodId, string valueMember, string textMember, OpeBase ob, bool isEmpty)
  637. {
  638. InitComboEditor(uce, methodId, valueMember, ob, isEmpty);
  639. uce.DisplayMember = textMember;
  640. }
  641. /// <summary>
  642. /// 初始化下拉框
  643. /// </summary>
  644. /// <param name="uce">下拉框</param>
  645. /// <param name="methodId">请求的服务</param>
  646. /// <param name="valueMember">值成员</param>
  647. /// <param name="ob">ob对象</param>
  648. /// <param name="isEmpty">是否有空行</param>
  649. public static void InitComboEditor(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, bool isEmpty)
  650. {
  651. DataTable dt = ServerHelper.GetData(methodId, null, ob);
  652. if (dt != null && dt.Rows.Count > 0)
  653. {
  654. if (isEmpty)
  655. {
  656. Object[] obj = new Object[] { "", "" };
  657. DataRow dr = dt.NewRow();
  658. dr.ItemArray = obj;
  659. dt.Rows.InsertAt(dr, 0);
  660. }
  661. uce.DataSource = dt;
  662. uce.ValueMember = valueMember;
  663. SetComboItemHeight(uce);
  664. }
  665. }
  666. /// <summary>
  667. /// 设置UltraComboEditor中的中文和非中文统一高度。
  668. /// </summary>
  669. /// <param name="cmb"></param>
  670. public static void SetComboItemHeight(UltraComboEditor cmb)
  671. {
  672. foreach (ValueListItem item in cmb.Items)
  673. {
  674. if (Regex.IsMatch(item.DisplayText, @"[\u4e00-\u9fa5]+"))
  675. {
  676. item.Appearance.FontData.SizeInPoints = 9.0F;
  677. }
  678. else
  679. {
  680. item.Appearance.FontData.SizeInPoints = 10.5F;
  681. }
  682. }
  683. }
  684. /// <summary>
  685. /// 将下拉框绑定到GRID列
  686. /// </summary>
  687. /// <param name="uce">下拉框(已经初始化完成)</param>
  688. /// <param name="ColumnName">列名</param>
  689. /// <param name="con">空间集合(每次只需填入this.Controls)</param>
  690. /// <param name="ug">GRID</param>
  691. /// <param name="i">GRID的第几层结构</param>
  692. public static void BindColumn(UltraComboEditor uce, string ColumnName, System.Windows.Forms.Control.ControlCollection con, UltraGrid ug, int i)
  693. {
  694. con.Add(uce);
  695. uce.Visible = false;
  696. ug.DisplayLayout.Bands[i].Columns[ColumnName].EditorComponent = uce;
  697. ug.DisplayLayout.Bands[i].Columns[ColumnName].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDown;
  698. SetComboItemHeight(uce);
  699. }
  700. ///接箍编辑区显示支数
  701. public static string piecesJg(string woidId,string[] plinCode,OpeBase ob)
  702. {
  703. string piece = "";
  704. try
  705. {
  706. DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.coup.BaseHelper.doQueryPiece", new Object[] { woidId,plinCode }, ob);
  707. {
  708. if (dt != null && dt.Rows.Count > 0)
  709. {
  710. piece = dt.Rows[0]["FAIL"].ToString();
  711. }
  712. }
  713. return piece;
  714. }
  715. catch (Exception ex)
  716. {
  717. return ex.ToString();
  718. }
  719. }
  720. /// <summary>
  721. /// 设置Grid可拖拽行, 设置拖拽前提条件,拖拽后的操作
  722. /// </summary>
  723. /// <param name="ug">待设置的Grid</param>
  724. /// <param name="action">拖拽后需要实现的业务</param>
  725. public static void SetGridDragDropRows(UltraGrid ug, Action<SelectedRowsCollection, int> action, Cursor myCursor)
  726. {
  727. ug.AllowDrop = true;
  728. ug.SelectionDrag += (sender, args) => { if (ug.Selected.Rows.Count > 0) ug.DoDragDrop(ug.Selected.Rows, DragDropEffects.Move); };
  729. ug.GiveFeedback += (sender, args) =>
  730. {
  731. //Cursor myCursor = new Cursor();
  732. //ug.Cursor = Cursors.Hand;
  733. args.UseDefaultCursors = false;
  734. ug.Cursor = myCursor;
  735. };
  736. ug.DragOver += (sender, args) =>
  737. {
  738. args.Effect = DragDropEffects.Move;
  739. UltraGrid grid = sender as UltraGrid;
  740. Point pointInGridCoords = grid.PointToClient(new Point(args.X, args.Y + 10));
  741. UIElement uieOver = ug.DisplayLayout.UIElement.ElementFromPoint(ug.PointToClient(new Point(args.X, args.Y + 10)));
  742. if (uieOver != null)
  743. {
  744. UltraGridRow ugrOver = uieOver.GetContext(typeof(UltraGridRow), true) as UltraGridRow;
  745. if (ugrOver != null) ug.ActiveRow = ugrOver;
  746. }
  747. if (pointInGridCoords.Y < 30)
  748. // 当拖动行到当前视图顶端,滑轮自动向上滚动.
  749. ug.ActiveRowScrollRegion.Scroll(RowScrollAction.LineUp);
  750. else if (pointInGridCoords.Y > grid.Height - 30)
  751. // 当拖动行到当前视图尾端,滑轮自动向下滚动.
  752. ug.ActiveRowScrollRegion.Scroll(RowScrollAction.LineDown);
  753. };
  754. ug.DragDrop += (sender, args) =>
  755. {
  756. ug.Cursor = Cursors.Default;
  757. UIElement uieOver = ug.DisplayLayout.UIElement.ElementFromPoint(ug.PointToClient(new Point(args.X, args.Y + 10)));
  758. UltraGridRow ugrOver = uieOver.GetContext(typeof(UltraGridRow), true) as UltraGridRow;
  759. if (ugrOver != null)
  760. {
  761. var dropIndex = ugrOver.HasParent() ? ugrOver.ParentRow.Index : ugrOver.Index;
  762. SelectedRowsCollection SelRows = args.Data.GetData(typeof(SelectedRowsCollection)) as SelectedRowsCollection;
  763. if (action != null)
  764. {
  765. action(SelRows, dropIndex);
  766. }
  767. else
  768. {
  769. foreach (UltraGridRow aRow in SelRows)
  770. {
  771. ug.Rows.Move(aRow, dropIndex);
  772. }
  773. }
  774. }
  775. };
  776. }
  777. /// <summary>
  778. /// 合并单元格统计
  779. /// </summary>
  780. public static void SetGroupBySum(UltraGrid ug, string[] columnKeys, string groupBy)
  781. {
  782. if (columnKeys.Length == 0)
  783. {
  784. return;
  785. }
  786. for (int i = 0; i < columnKeys.Length; i++)
  787. {
  788. SummarySettings summary = ug.DisplayLayout.Bands[0].Summaries.Add(
  789. columnKeys[i],
  790. SummaryType.Custom,
  791. new StringSummaryCalculator(groupBy), // Custom summary calculator
  792. ug.DisplayLayout.Bands[0].Columns[columnKeys[i]],
  793. SummaryPosition.UseSummaryPositionColumn, null);
  794. summary.DisplayFormat = "{0:N3}";
  795. summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
  796. }
  797. }
  798. }
  799. class StringSummaryCalculator : ICustomSummaryCalculator
  800. {
  801. private string _summaryText = "";
  802. private string groupby = "";
  803. internal StringSummaryCalculator(string GroupBy)
  804. {
  805. groupby = GroupBy;
  806. }
  807. public void AggregateCustomSummary(SummarySettings summarySettings, UltraGridRow row)
  808. {
  809. }
  810. public void BeginCustomSummary(SummarySettings summarySettings, RowsCollection rowCollection)
  811. {
  812. string key = summarySettings.Key;
  813. var list = rowCollection.GroupBy(p => p.Cells[groupby].Value.ToString()).Select(p => p.LastOrDefault()).ToList();
  814. _summaryText = list.Sum(p => double.Parse(p.Cells[key].Value.ToString())).ToString();
  815. }
  816. public object EndCustomSummary(SummarySettings summarySettings, RowsCollection rowCollection)
  817. {
  818. return this._summaryText;
  819. }
  820. }
  821. }