BaseMethod.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using Infragistics.Win.UltraWinEditors;
  2. using Infragistics.Win.UltraWinGrid;
  3. using Infragistics.Win.UltraWinMaskedEdit;
  4. using Microsoft.Office.Interop.Excel;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Text.RegularExpressions;
  11. using System.Windows.Forms;
  12. namespace Core.StlMes.Client.Lims.Port.封装类.方法
  13. {
  14. class BaseMethod
  15. {
  16. /// <summary>
  17. /// 设置列显示位数
  18. /// </summary>
  19. /// <param name="ug"></param>
  20. /// <param name="arr"></param>
  21. public static void setUltraGridColumnMaxInput(UltraGrid ug, string[] arr)
  22. {
  23. if (ug == null || arr == null || arr.Length == 0)
  24. {
  25. return;
  26. }
  27. arr.ToArray();
  28. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns)
  29. {
  30. if (arr.Contains(ugc.Key.ToString()))
  31. {
  32. ugc.MaskClipMode = MaskMode.IncludeLiterals;
  33. ugc.MaskInput = "{LOC}nn,nnn,nnn.nnn";
  34. }
  35. }
  36. }
  37. /// <summary>
  38. /// 炉号去-后的字符
  39. /// </summary>
  40. /// <param name="JudgeStoveNo"></param>
  41. /// <returns></returns>
  42. public static string getJudgeStoveNo(string JudgeStoveNo)
  43. {
  44. Regex regex = new Regex("-[0-9]*");
  45. return regex.Replace(JudgeStoveNo, "");
  46. }
  47. /// <summary>
  48. /// 键盘按下Ctrl+D,拷贝活动单元格的数据到所有已勾选的此列的单元格中
  49. /// </summary>
  50. /// <param name="ugrid">UltraGrid</param>
  51. /// <param name="e"></param>
  52. /// <param name="strs">可以进行列名称</param>
  53. public static void setGridCopyActColumn(UltraGrid ugrid, KeyEventArgs e, params string[] strs)
  54. {
  55. if (e.Control && e.KeyCode == Keys.D)
  56. {
  57. if (ugrid != null && ugrid.ActiveRow != null)
  58. {
  59. UltraGridRow ugr = ugrid.ActiveRow;
  60. foreach (string colName in strs)
  61. {
  62. if (ugrid.ActiveCell.Column.Key.Equals(colName))
  63. {
  64. if (ugr.Cells[colName].Activation != Activation.AllowEdit)
  65. {
  66. return;
  67. }
  68. ugrid.UpdateData();
  69. ArrayList list = new ArrayList();
  70. IQueryable<UltraGridRow> checkRows = ugrid.Rows.AsQueryable().Where("CHK = 'True' ");
  71. if (checkRows.Count() == 0)
  72. {
  73. return;
  74. }
  75. foreach (UltraGridRow uRow in checkRows)
  76. {
  77. if (uRow != ugr && uRow.Cells[colName].Activation == Activation.AllowEdit)
  78. {
  79. uRow.Cells[colName].Value = ugr.Cells[colName].Value;
  80. }
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }
  87. /// <summary>
  88. /// 键盘按下Ctrl+D,拷贝活动单元格的数据到所有已勾选的此列的单元格中
  89. /// </summary>
  90. /// <param name="ugrid">UltraGrid</param>
  91. /// <param name="e"></param>
  92. /// <param name="strs">可以进行列名称</param>
  93. public static void setGridCopyActColumn1(UltraGrid ugrid, KeyEventArgs e, params string[] strs)
  94. {
  95. if (e.Control && e.KeyCode == Keys.D)
  96. {
  97. if (ugrid != null && ugrid.ActiveRow != null)
  98. {
  99. UltraGridRow ugr = ugrid.ActiveRow;
  100. foreach (string colName in strs)
  101. {
  102. if (ugrid.ActiveCell.Column.Key.Equals(colName))
  103. {
  104. if (ugr.Cells[colName].Activation != Activation.AllowEdit)
  105. {
  106. return;
  107. }
  108. ugrid.UpdateData();
  109. ArrayList list = new ArrayList();
  110. IQueryable<UltraGridRow> checkRows = ugrid.Rows.AsQueryable().Where("CHOOSE = 'True' ");
  111. if (checkRows.Count() == 0)
  112. {
  113. return;
  114. }
  115. foreach (UltraGridRow uRow in checkRows)
  116. {
  117. if (uRow != ugr && uRow.Cells[colName].Activation == Activation.AllowEdit)
  118. {
  119. uRow.Cells[colName].Value = ugr.Cells[colName].Value;
  120. }
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }
  127. /// <summary>
  128. /// 获取数据源中第一行数据赋到类中(grid 带下划线)
  129. /// </summary>
  130. /// <typeparam name="T">返回类</typeparam>
  131. /// <param name="ds">输入带数据的数据源</param>
  132. /// <param name="t">输入类</param>
  133. /// <returns></returns>
  134. public static T GetUltraGridToEntityNEW<T>(UltraGrid _grid, T t)
  135. {
  136. String[] strColumns = null;
  137. String[] strColumnsNew = null;
  138. UltraGridRow dr = _grid.Rows[0];
  139. int columnNum = dr.Cells.Count;
  140. strColumns = new String[columnNum];
  141. strColumnsNew = new String[columnNum];
  142. for (int i = 0; i < columnNum; i++)
  143. {
  144. strColumns[i] = _grid.DisplayLayout.Bands[0].Columns[i].Key.ToString().Replace("_", "");
  145. strColumnsNew[i] = _grid.DisplayLayout.Bands[0].Columns[i].Key.ToString();
  146. }
  147. System.Reflection.PropertyInfo[] pro = t.GetType().GetProperties();
  148. foreach (System.Reflection.PropertyInfo item in pro)
  149. {
  150. for (int i = 0; i < strColumns.Length; i++)
  151. {
  152. if (string.Compare(item.Name.ToString(), strColumns[i].ToString(), true) == 0)
  153. {
  154. if (item.PropertyType == typeof(int?))
  155. {
  156. item.SetValue(t, Convert.ToInt32(dr.Cells[strColumnsNew[i]].Value.ToString3()), null);
  157. }
  158. else if (item.PropertyType == typeof(decimal?))
  159. {
  160. item.SetValue(t, Convert.ToDecimal(dr.Cells[strColumnsNew[i]].Value.ToString3()), null);
  161. }
  162. else
  163. {
  164. item.SetValue(t, Convert.ToString(dr.Cells[strColumnsNew[i]].Value.ToString()), null);
  165. }
  166. }
  167. }
  168. }
  169. return t;
  170. }
  171. }
  172. }