| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Windows.Forms;
- using Infragistics.Win.UltraWinGrid;
- namespace Core.StlMes.Client.Plan.Order
- {
- 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
- }
-
- }
|