19b389d13a7f8358ed6799c9dfa253b1dfe787de.svn-base 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Reflection;
  4. using System.Drawing;
  5. using System.Collections;
  6. namespace Core.XgMes.Client.JGKC.RollManager
  7. {
  8. /// <summary>
  9. /// Comm 的摘要说明。
  10. /// </summary>
  11. public class Comm
  12. {
  13. public Comm()
  14. {
  15. //
  16. // TODO: 在此处添加构造函数逻辑
  17. //
  18. }
  19. /// <summary>
  20. /// 获取ulGridRow指定字段值(针对有分组行时)
  21. /// </summary>
  22. /// <param name="row">UltraGridRow</param>
  23. /// <param name="_Key">选择字段KEY</param>
  24. /// <param name="_CompareValue">比对值</param>
  25. /// <param name="_CellKey">指定字段KEY</param>
  26. /// <param name="_ResultField">返回制定字段值数组</param>
  27. /// <returns></returns>
  28. public static void GetAdjustData(Infragistics.Win.UltraWinGrid.UltraGridRow row, string _Key, string _CompareValue, string _CellKey, ref ArrayList _ResultField)
  29. {
  30. if (row.GetType() == typeof(Infragistics.Win.UltraWinGrid.UltraGridRow))
  31. {
  32. if (Comm.ObjToStr(row.Cells[_Key].Value).ToUpper() == _CompareValue)
  33. {
  34. _ResultField.Add(Comm.ObjToStr(row.Cells[_CellKey].Value));
  35. }
  36. }
  37. else
  38. {
  39. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow tmprow in row.ChildBands[0].Rows)
  40. {
  41. GetAdjustData(tmprow, _Key, _CompareValue, _CellKey, ref _ResultField);
  42. }
  43. }
  44. }
  45. /// <summary>
  46. /// 获取grid-选择字段="TRUE"指定字段值
  47. /// </summary>
  48. /// <param name="_SelectGrid">存在选择行的UltraGrid</param>
  49. /// <param name="_Select">选择字段</param>
  50. /// <param name="_FieldValue">字段值</param>
  51. /// <returns>ArrayList</returns>
  52. public static System.Collections.ArrayList GetFieldValue(Infragistics.Win.UltraWinGrid.UltraGrid _SelectGrid,string _Select,string _FieldValue)
  53. {
  54. System.Collections.ArrayList resultArray = new System.Collections.ArrayList();
  55. foreach(Infragistics.Win.UltraWinGrid.UltraGridRow row in _SelectGrid.Rows)
  56. {
  57. if(ObjToStr(row.Cells[_Select].Value).ToUpper() == "TRUE")
  58. resultArray.Add(ObjToStr(row.Cells[_FieldValue].Value));
  59. }
  60. return resultArray;
  61. }
  62. /// <summary>
  63. /// 对目标对象进行字符串的转换
  64. /// </summary>
  65. /// <param name="obj"></param>
  66. /// <returns></returns>
  67. public static string ObjToStr(object obj)
  68. {
  69. if(obj == null || obj.GetType() == typeof(System.DBNull))
  70. {
  71. return "";
  72. }
  73. else
  74. {
  75. return Convert.ToString(obj);
  76. }
  77. }
  78. /// <summary>
  79. /// 设置ulGridRow指定字段值
  80. /// </summary>
  81. /// <param name="GridRow">目标GridRow</param>
  82. /// <param name="Value">设置值 </param>
  83. /// <param name="Key">字段KEY</param>
  84. /// <returns></returns>
  85. public static void SetGridFlagValue(Infragistics.Win.UltraWinGrid.UltraGridRow GridRow, string Value, string Key)
  86. {
  87. if (GridRow.GetType() == typeof(Infragistics.Win.UltraWinGrid.UltraGridGroupByRow))
  88. {
  89. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in GridRow.ChildBands[0].Rows)
  90. {
  91. SetGridFlagValue(row, Value, Key);
  92. }
  93. }
  94. else
  95. {
  96. if (!GridRow.IsFilteredOut)
  97. GridRow.Cells[Key].Value = Value;
  98. }
  99. }
  100. /// <summary>
  101. /// 对目标对象进行数字的转换
  102. /// </summary>
  103. /// <param name="obj"></param>
  104. /// <returns></returns>
  105. public static int ObjToInt(object obj)
  106. {
  107. try
  108. {
  109. if(obj == null || obj.GetType() == typeof(System.DBNull) || ObjToStr(obj).Length ==0)
  110. {
  111. return 0;
  112. }
  113. else
  114. {
  115. return Convert.ToInt32(obj);
  116. }
  117. }
  118. catch(System.Exception ex)
  119. {
  120. System.Diagnostics.Debug.WriteLine(ex.ToString());
  121. return 0;
  122. }
  123. }
  124. /// <summary>
  125. /// 对目标对象进行数字(小数)的转换
  126. /// </summary>
  127. /// <param name="obj"></param>
  128. /// <returns></returns>
  129. public static System.Decimal ObjToDecimal(object obj)
  130. {
  131. try
  132. {
  133. if(obj == null || obj.GetType() == typeof(System.DBNull) || ObjToStr(obj).Length ==0)
  134. {
  135. return 0;
  136. }
  137. else
  138. {
  139. return Convert.ToDecimal(obj);
  140. }
  141. }
  142. catch(System.Exception ex)
  143. {
  144. System.Diagnostics.Debug.WriteLine(ex.ToString());
  145. return 0;
  146. }
  147. }
  148. /// <summary>
  149. /// 对目标对象进行数字(小数)的转换
  150. /// </summary>
  151. /// <param name="obj"></param>
  152. /// <returns></returns>
  153. public static System.Double ObjToDouble(object obj)
  154. {
  155. try
  156. {
  157. if(obj == null || obj.GetType() == typeof(System.DBNull) || ObjToStr(obj).Length ==0)
  158. {
  159. return 0;
  160. }
  161. else
  162. {
  163. return Convert.ToDouble(obj);
  164. }
  165. }
  166. catch(System.Exception ex)
  167. {
  168. System.Diagnostics.Debug.WriteLine(ex.ToString());
  169. return 0;
  170. }
  171. }
  172. /// <summary>
  173. /// 设置Grid求和区域
  174. /// </summary>
  175. /// <param name="pGrid">目标Grid</param>
  176. /// <returns></returns>
  177. public static void SetGridSumArea(Infragistics.Win.UltraWinGrid.UltraGridBase pGrid)
  178. {
  179. try
  180. {
  181. if(pGrid.Rows.Count == 0)
  182. {
  183. foreach(Infragistics.Win.UltraWinGrid.UltraGridBand band in pGrid.DisplayLayout.Bands)
  184. {
  185. foreach(Infragistics.Win.UltraWinGrid.SummarySettings sum in band.Summaries)
  186. {
  187. sum.SummaryDisplayArea = Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.None;
  188. }
  189. }
  190. }
  191. else
  192. {
  193. foreach(Infragistics.Win.UltraWinGrid.UltraGridBand band in pGrid.DisplayLayout.Bands)
  194. {
  195. foreach(Infragistics.Win.UltraWinGrid.SummarySettings sum in band.Summaries)
  196. {
  197. if(pGrid.DisplayLayout.GroupByBox.Hidden)
  198. {
  199. sum.SummaryDisplayArea = Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.Bottom;
  200. }
  201. else
  202. {
  203. sum.SummaryDisplayArea = ((Infragistics.Win.UltraWinGrid.SummaryDisplayAreas)((Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.Bottom | Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.InGroupByRows | Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.GroupByRowsFooter)));
  204. }
  205. }
  206. }
  207. }
  208. }
  209. catch(System.Exception ex)
  210. {
  211. System.Diagnostics.Debug.WriteLine(ex.ToString());
  212. }
  213. }
  214. /// <summary>
  215. /// 初始化Infragistics.Win.UltraWinGrid.UltraCombo 控件绑定表
  216. /// </summary>
  217. /// <param name="_grid">Grid</param>
  218. /// <param name="_ds">DataSet</param>
  219. /// <param name="tableName">绑定表名</param>
  220. /// <param name="_displayColumn">绑定列名</param>
  221. /// <param name="_displayMember">显示项</param>
  222. /// <param name="_ValueMember">值项</param>
  223. /// <returns></returns>
  224. public static void Init_ComboControl(System.Windows.Forms.Control ComboControl,string TableName,string _displayMember,string _valueMember,ref System.Data.DataSet dst)
  225. {
  226. try
  227. {
  228. switch(ComboControl.GetType().ToString())
  229. {
  230. case "Infragistics.Win.UltraWinGrid.UltraCombo":
  231. if(!dst.Tables.Contains(TableName))
  232. {
  233. MessageBox.Show("绑定表:"+TableName+"不存在,不能对控件"+ComboControl.Name+"进行初始化!");
  234. return;
  235. }
  236. System.Data.DataTable newTable = dst.Tables[TableName].Copy();
  237. newTable.TableName=TableName;
  238. System.Data.DataRow newRow = newTable.NewRow();
  239. for(int i=0;i<dst.Tables[TableName].Columns.Count;i++)
  240. {
  241. newRow[i]="";
  242. }
  243. newTable.Rows.Add(newRow);
  244. newTable.AcceptChanges();
  245. ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).DataSource = new System.Data.DataView(newTable);
  246. ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).DisplayMember = _displayMember;
  247. ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).ValueMember = _valueMember;
  248. foreach(System.Data.DataColumn col in dst.Tables[TableName].Columns)
  249. {
  250. if(col.ColumnName != _displayMember)
  251. {
  252. ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).DisplayLayout.Bands[TableName].Columns[col.ColumnName].Hidden = true;
  253. }
  254. else
  255. {
  256. ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).DisplayLayout.Bands[TableName].Columns[col.ColumnName].Band.ColHeadersVisible = false;
  257. ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).DisplayLayout.Bands[TableName].Columns[col.ColumnName].Width = ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).Width;
  258. }
  259. }
  260. break;
  261. }
  262. }
  263. catch(System.Exception ex)
  264. {
  265. System.Diagnostics.Debug.WriteLine(ex.ToString());
  266. }
  267. }
  268. /// <summary>
  269. /// 将目标GRID导出EXCEL文件
  270. /// </summary>
  271. /// <param name="ulGrid"></param>
  272. /// <param name="ExcelExporter"></param>
  273. /// <returns></returns>
  274. public static void ExPortExcel(Infragistics.Win.UltraWinGrid.UltraGrid ulGrid,Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter ExcelExporter)
  275. {
  276. string filePath;
  277. string fileName;
  278. SaveFileDialog saveDlg = new SaveFileDialog();
  279. try
  280. {
  281. if( !System.IO.Directory.Exists(System.Windows.Forms.Application.StartupPath + @"\Report"))
  282. {
  283. System.IO.Directory.CreateDirectory(System.Windows.Forms.Application.StartupPath + @"\Report");
  284. }
  285. filePath = System.Windows.Forms.Application.StartupPath + @"\Report";
  286. saveDlg.InitialDirectory = filePath;
  287. saveDlg.DefaultExt = "*.xls";
  288. saveDlg.Filter = "XLS Files|*.xls";
  289. saveDlg.FilterIndex = 2;
  290. saveDlg.RestoreDirectory = true ;
  291. if(saveDlg.ShowDialog() == DialogResult.OK)
  292. {
  293. fileName = saveDlg.FileName;
  294. ExcelExporter.Export(ulGrid,fileName);
  295. //创建一个新的进程打开excel
  296. System.Diagnostics.ProcessStartInfo st = new System.Diagnostics.ProcessStartInfo(fileName);
  297. st.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
  298. System.Diagnostics.Process.Start(st);
  299. }
  300. }
  301. catch(Exception ex)
  302. {
  303. System.Diagnostics.Debug.WriteLine(ex.ToString());
  304. }
  305. }
  306. }
  307. }