using System; using System.Windows.Forms; using System.Reflection; using System.Drawing; using System.Collections; namespace Core.XgMes.Client.JGKC.RollManager { /// /// Comm 的摘要说明。 /// public class Comm { public Comm() { // // TODO: 在此处添加构造函数逻辑 // } /// /// 获取ulGridRow指定字段值(针对有分组行时) /// /// UltraGridRow /// 选择字段KEY /// 比对值 /// 指定字段KEY /// 返回制定字段值数组 /// public static void GetAdjustData(Infragistics.Win.UltraWinGrid.UltraGridRow row, string _Key, string _CompareValue, string _CellKey, ref ArrayList _ResultField) { if (row.GetType() == typeof(Infragistics.Win.UltraWinGrid.UltraGridRow)) { if (Comm.ObjToStr(row.Cells[_Key].Value).ToUpper() == _CompareValue) { _ResultField.Add(Comm.ObjToStr(row.Cells[_CellKey].Value)); } } else { foreach (Infragistics.Win.UltraWinGrid.UltraGridRow tmprow in row.ChildBands[0].Rows) { GetAdjustData(tmprow, _Key, _CompareValue, _CellKey, ref _ResultField); } } } /// /// 获取grid-选择字段="TRUE"指定字段值 /// /// 存在选择行的UltraGrid /// 选择字段 /// 字段值 /// ArrayList public static System.Collections.ArrayList GetFieldValue(Infragistics.Win.UltraWinGrid.UltraGrid _SelectGrid,string _Select,string _FieldValue) { System.Collections.ArrayList resultArray = new System.Collections.ArrayList(); foreach(Infragistics.Win.UltraWinGrid.UltraGridRow row in _SelectGrid.Rows) { if(ObjToStr(row.Cells[_Select].Value).ToUpper() == "TRUE") resultArray.Add(ObjToStr(row.Cells[_FieldValue].Value)); } return resultArray; } /// /// 对目标对象进行字符串的转换 /// /// /// public static string ObjToStr(object obj) { if(obj == null || obj.GetType() == typeof(System.DBNull)) { return ""; } else { return Convert.ToString(obj); } } /// /// 设置ulGridRow指定字段值 /// /// 目标GridRow /// 设置值 /// 字段KEY /// public static void SetGridFlagValue(Infragistics.Win.UltraWinGrid.UltraGridRow GridRow, string Value, string Key) { if (GridRow.GetType() == typeof(Infragistics.Win.UltraWinGrid.UltraGridGroupByRow)) { foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in GridRow.ChildBands[0].Rows) { SetGridFlagValue(row, Value, Key); } } else { if (!GridRow.IsFilteredOut) GridRow.Cells[Key].Value = Value; } } /// /// 对目标对象进行数字的转换 /// /// /// public static int ObjToInt(object obj) { try { if(obj == null || obj.GetType() == typeof(System.DBNull) || ObjToStr(obj).Length ==0) { return 0; } else { return Convert.ToInt32(obj); } } catch(System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); return 0; } } /// /// 对目标对象进行数字(小数)的转换 /// /// /// public static System.Decimal ObjToDecimal(object obj) { try { if(obj == null || obj.GetType() == typeof(System.DBNull) || ObjToStr(obj).Length ==0) { return 0; } else { return Convert.ToDecimal(obj); } } catch(System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); return 0; } } /// /// 对目标对象进行数字(小数)的转换 /// /// /// public static System.Double ObjToDouble(object obj) { try { if(obj == null || obj.GetType() == typeof(System.DBNull) || ObjToStr(obj).Length ==0) { return 0; } else { return Convert.ToDouble(obj); } } catch(System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); return 0; } } /// /// 设置Grid求和区域 /// /// 目标Grid /// public static void SetGridSumArea(Infragistics.Win.UltraWinGrid.UltraGridBase pGrid) { try { if(pGrid.Rows.Count == 0) { foreach(Infragistics.Win.UltraWinGrid.UltraGridBand band in pGrid.DisplayLayout.Bands) { foreach(Infragistics.Win.UltraWinGrid.SummarySettings sum in band.Summaries) { sum.SummaryDisplayArea = Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.None; } } } else { foreach(Infragistics.Win.UltraWinGrid.UltraGridBand band in pGrid.DisplayLayout.Bands) { foreach(Infragistics.Win.UltraWinGrid.SummarySettings sum in band.Summaries) { if(pGrid.DisplayLayout.GroupByBox.Hidden) { sum.SummaryDisplayArea = Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.Bottom; } else { sum.SummaryDisplayArea = ((Infragistics.Win.UltraWinGrid.SummaryDisplayAreas)((Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.Bottom | Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.InGroupByRows | Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.GroupByRowsFooter))); } } } } } catch(System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } /// /// 初始化Infragistics.Win.UltraWinGrid.UltraCombo 控件绑定表 /// /// Grid /// DataSet /// 绑定表名 /// 绑定列名 /// 显示项 /// 值项 /// public static void Init_ComboControl(System.Windows.Forms.Control ComboControl,string TableName,string _displayMember,string _valueMember,ref System.Data.DataSet dst) { try { switch(ComboControl.GetType().ToString()) { case "Infragistics.Win.UltraWinGrid.UltraCombo": if(!dst.Tables.Contains(TableName)) { MessageBox.Show("绑定表:"+TableName+"不存在,不能对控件"+ComboControl.Name+"进行初始化!"); return; } System.Data.DataTable newTable = dst.Tables[TableName].Copy(); newTable.TableName=TableName; System.Data.DataRow newRow = newTable.NewRow(); for(int i=0;i /// 将目标GRID导出EXCEL文件 /// /// /// /// public static void ExPortExcel(Infragistics.Win.UltraWinGrid.UltraGrid ulGrid,Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter ExcelExporter) { string filePath; string fileName; SaveFileDialog saveDlg = new SaveFileDialog(); try { if( !System.IO.Directory.Exists(System.Windows.Forms.Application.StartupPath + @"\Report")) { System.IO.Directory.CreateDirectory(System.Windows.Forms.Application.StartupPath + @"\Report"); } filePath = System.Windows.Forms.Application.StartupPath + @"\Report"; saveDlg.InitialDirectory = filePath; saveDlg.DefaultExt = "*.xls"; saveDlg.Filter = "XLS Files|*.xls"; saveDlg.FilterIndex = 2; saveDlg.RestoreDirectory = true ; if(saveDlg.ShowDialog() == DialogResult.OK) { fileName = saveDlg.FileName; ExcelExporter.Export(ulGrid,fileName); //创建一个新的进程打开excel System.Diagnostics.ProcessStartInfo st = new System.Diagnostics.ProcessStartInfo(fileName); st.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized; System.Diagnostics.Process.Start(st); } } catch(Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } } }