| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- using System;
- using System.Windows.Forms;
- using System.Reflection;
- using System.Drawing;
- using System.Collections;
- namespace Core.XgMes.Client.JGKC.RollManager
- {
- /// <summary>
- /// Comm 的摘要说明。
- /// </summary>
- public class Comm
- {
- public Comm()
- {
- //
- // TODO: 在此处添加构造函数逻辑
- //
- }
- /// <summary>
- /// 获取ulGridRow指定字段值(针对有分组行时)
- /// </summary>
- /// <param name="row">UltraGridRow</param>
- /// <param name="_Key">选择字段KEY</param>
- /// <param name="_CompareValue">比对值</param>
- /// <param name="_CellKey">指定字段KEY</param>
- /// <param name="_ResultField">返回制定字段值数组</param>
- /// <returns></returns>
- 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);
- }
- }
- }
- /// <summary>
- /// 获取grid-选择字段="TRUE"指定字段值
- /// </summary>
- /// <param name="_SelectGrid">存在选择行的UltraGrid</param>
- /// <param name="_Select">选择字段</param>
- /// <param name="_FieldValue">字段值</param>
- /// <returns>ArrayList</returns>
- 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;
- }
- /// <summary>
- /// 对目标对象进行字符串的转换
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- public static string ObjToStr(object obj)
- {
- if(obj == null || obj.GetType() == typeof(System.DBNull))
- {
- return "";
- }
- else
- {
- return Convert.ToString(obj);
- }
- }
- /// <summary>
- /// 设置ulGridRow指定字段值
- /// </summary>
- /// <param name="GridRow">目标GridRow</param>
- /// <param name="Value">设置值 </param>
- /// <param name="Key">字段KEY</param>
- /// <returns></returns>
- 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;
- }
- }
- /// <summary>
- /// 对目标对象进行数字的转换
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- 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;
- }
- }
- /// <summary>
- /// 对目标对象进行数字(小数)的转换
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- 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;
- }
- }
- /// <summary>
- /// 对目标对象进行数字(小数)的转换
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- 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;
- }
- }
- /// <summary>
- /// 设置Grid求和区域
- /// </summary>
- /// <param name="pGrid">目标Grid</param>
- /// <returns></returns>
- 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());
- }
- }
- /// <summary>
- /// 初始化Infragistics.Win.UltraWinGrid.UltraCombo 控件绑定表
- /// </summary>
- /// <param name="_grid">Grid</param>
- /// <param name="_ds">DataSet</param>
- /// <param name="tableName">绑定表名</param>
- /// <param name="_displayColumn">绑定列名</param>
- /// <param name="_displayMember">显示项</param>
- /// <param name="_ValueMember">值项</param>
- /// <returns></returns>
- 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<dst.Tables[TableName].Columns.Count;i++)
- {
- newRow[i]="";
- }
- newTable.Rows.Add(newRow);
- newTable.AcceptChanges();
-
- ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).DataSource = new System.Data.DataView(newTable);
- ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).DisplayMember = _displayMember;
- ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).ValueMember = _valueMember;
- foreach(System.Data.DataColumn col in dst.Tables[TableName].Columns)
- {
- if(col.ColumnName != _displayMember)
- {
- ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).DisplayLayout.Bands[TableName].Columns[col.ColumnName].Hidden = true;
- }
- else
- {
- ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).DisplayLayout.Bands[TableName].Columns[col.ColumnName].Band.ColHeadersVisible = false;
- ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).DisplayLayout.Bands[TableName].Columns[col.ColumnName].Width = ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).Width;
- }
- }
- break;
- }
- }
- catch(System.Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- }
- }
-
- /// <summary>
- /// 将目标GRID导出EXCEL文件
- /// </summary>
- /// <param name="ulGrid"></param>
- /// <param name="ExcelExporter"></param>
- /// <returns></returns>
- 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());
- }
-
- }
- }
- }
|