using System; using System.Diagnostics; using System.IO; using System.Windows.Forms; using Infragistics.Win.UltraWinGrid; namespace Core.StlMes.Client.YdmPipeManage { public class Constant { //C:\Users\Administrator\Desktop\a.xlsx private static string m_RunPath = "";//设置程序运行(启动)路径 public static WaitingForm WaitingForm = null; public Constant() { // // TODO: 在此处添加构造函数逻辑 // WaitingForm = new WaitingForm(); if (m_RunPath.Trim().Length == 0) { m_RunPath = System.Environment.CurrentDirectory; } } public static string RunPath {//取得运行路径 get { return m_RunPath; } set { m_RunPath = value; } } #region UltraGrid设置 public static void RefreshAndAutoSize(Infragistics.Win.UltraWinGrid.UltraGrid grid) { grid.DataBind(); grid.ActiveRow = null; foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn ugc in grid.DisplayLayout.Bands[0].Columns) { ugc.PerformAutoResize(PerformAutoSizeType.AllRowsInBand); } grid.Refresh(); } public static void ExportGrid2Excel(System.Windows.Forms.Form Form, Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter ExcelExporter, Infragistics.Win.UltraWinGrid.UltraGrid Grid, SaveFileDialog sfdFile) { Cursor oldCursor = Form.Cursor; Form.Cursor = Cursors.WaitCursor; if (Constant.WaitingForm == null) { Constant.WaitingForm = new WaitingForm(); } Constant.WaitingForm.ShowToUser = true; Constant.WaitingForm.Show(); Constant.WaitingForm.Update(); try { //if (!System.IO.Directory.Exists(System.Environment.CurrentDirectory + "\\temp")) //{ // System.IO.Directory.CreateDirectory(System.Environment.CurrentDirectory + "\\temp"); //} //string StrfileName = string.Format(System.Environment.CurrentDirectory + "\\temp\\" + Form.Text + ".xls"); string strFileName = sfdFile.FileName; ExcelExporter.Export(Grid, strFileName); ProcessStartInfo p = new ProcessStartInfo(strFileName); p.WorkingDirectory = Path.GetDirectoryName(strFileName); Process.Start(p); Form.Cursor = oldCursor; Constant.WaitingForm.ShowToUser = false; Constant.WaitingForm.Close(); } catch (Exception ex) { Form.Cursor = oldCursor; Constant.WaitingForm.ShowToUser = false; Constant.WaitingForm.Close(); MessageBox.Show(ex.Message); } } #endregion } }