using System; using System.Diagnostics; using System.IO; using System.Windows.Forms; using Infragistics.Win.UltraWinGrid; using Core.StlMes.Client.ZGMil; namespace Core.StlMes.Client.ZGMil { public class ConstantZg { //C:\Users\Administrator\Desktop\a.xlsx private static string m_RunPath = "";//设置程序运行(启动)路径 public static WaitingFormZg WaitingForm = null; public ConstantZg() { // // TODO: 在此处添加构造函数逻辑 // WaitingForm = new WaitingFormZg(); 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 (ConstantZg.WaitingForm == null) { ConstantZg.WaitingForm = new WaitingFormZg(); } ConstantZg.WaitingForm.ShowToUser = true; ConstantZg.WaitingForm.Show(); ConstantZg.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; ConstantZg.WaitingForm.ShowToUser = false; ConstantZg.WaitingForm.Close(); } catch (Exception ex) { Form.Cursor = oldCursor; ConstantZg.WaitingForm.ShowToUser = false; ConstantZg.WaitingForm.Close(); MessageBox.Show(ex.Message); } } #endregion } }