Constant.cs 3.1 KB

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