ConstantZg.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Windows.Forms;
  5. using Infragistics.Win.UltraWinGrid;
  6. using Core.StlMes.Client.ZGMil;
  7. namespace Core.StlMes.Client.ZGMil
  8. {
  9. public class ConstantZg
  10. {
  11. //C:\Users\Administrator\Desktop\a.xlsx
  12. private static string m_RunPath = "";//设置程序运行(启动)路径
  13. public static WaitingFormZg WaitingForm = null;
  14. public ConstantZg()
  15. {
  16. //
  17. // TODO: 在此处添加构造函数逻辑
  18. //
  19. WaitingForm = new WaitingFormZg();
  20. if (m_RunPath.Trim().Length == 0)
  21. {
  22. m_RunPath = System.Environment.CurrentDirectory;
  23. }
  24. }
  25. public static string RunPath
  26. {//取得运行路径
  27. get
  28. {
  29. return m_RunPath;
  30. }
  31. set
  32. {
  33. m_RunPath = value;
  34. }
  35. }
  36. #region UltraGrid设置
  37. public static void RefreshAndAutoSize(Infragistics.Win.UltraWinGrid.UltraGrid grid)
  38. {
  39. grid.DataBind();
  40. grid.ActiveRow = null;
  41. foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn ugc in grid.DisplayLayout.Bands[0].Columns)
  42. {
  43. ugc.PerformAutoResize(PerformAutoSizeType.AllRowsInBand);
  44. }
  45. grid.Refresh();
  46. }
  47. public static void ExportGrid2Excel(System.Windows.Forms.Form Form,
  48. Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter ExcelExporter,
  49. Infragistics.Win.UltraWinGrid.UltraGrid Grid, SaveFileDialog sfdFile)
  50. {
  51. Cursor oldCursor = Form.Cursor;
  52. Form.Cursor = Cursors.WaitCursor;
  53. if (ConstantZg.WaitingForm == null)
  54. {
  55. ConstantZg.WaitingForm = new WaitingFormZg();
  56. }
  57. ConstantZg.WaitingForm.ShowToUser = true;
  58. ConstantZg.WaitingForm.Show();
  59. ConstantZg.WaitingForm.Update();
  60. try
  61. {
  62. //if (!System.IO.Directory.Exists(System.Environment.CurrentDirectory + "\\temp"))
  63. //{
  64. // System.IO.Directory.CreateDirectory(System.Environment.CurrentDirectory + "\\temp");
  65. //}
  66. //string StrfileName = string.Format(System.Environment.CurrentDirectory + "\\temp\\" + Form.Text + ".xls");
  67. string strFileName = sfdFile.FileName;
  68. ExcelExporter.Export(Grid, strFileName);
  69. ProcessStartInfo p = new ProcessStartInfo(strFileName);
  70. p.WorkingDirectory = Path.GetDirectoryName(strFileName);
  71. Process.Start(p);
  72. Form.Cursor = oldCursor;
  73. ConstantZg.WaitingForm.ShowToUser = false;
  74. ConstantZg.WaitingForm.Close();
  75. }
  76. catch (Exception ex)
  77. {
  78. Form.Cursor = oldCursor;
  79. ConstantZg.WaitingForm.ShowToUser = false;
  80. ConstantZg.WaitingForm.Close();
  81. MessageBox.Show(ex.Message);
  82. }
  83. }
  84. #endregion
  85. }
  86. }