HistoryTaskUI.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using Pms.DataLibrary.Models;
  2. using Pms.DataLibrary.Order;
  3. using ProjectManagementSystem.Common.Extenions;
  4. using ProjectManagementSystem.Common.WebApi;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace ProjectManagementSystem.UI
  15. {
  16. public partial class HistoryTaskUI : UserControl, IDisplayUI
  17. {
  18. public HistoryTaskUI()
  19. {
  20. InitializeComponent();
  21. }
  22. public bool Init()
  23. {
  24. dateTimePicker1.Value = DateTime.Now.AddDays(-1);
  25. dateTimePicker2.Value = DateTime.Now;
  26. return true;
  27. }
  28. public void UpdateDisplay()
  29. {
  30. if (!this.Visible) return;
  31. string taskId = dataGridUI1.GetCurrentColValue("TaskID");
  32. string taskId_StepList = dataGridUI2.GetCurrentColValue("TaskID");
  33. if(!string.IsNullOrEmpty(taskId_StepList)
  34. && taskId == taskId_StepList)
  35. {
  36. return;
  37. }
  38. if (string.IsNullOrEmpty(taskId))
  39. {
  40. dataGridUI2.ShowDataGrid<StepData>(null);
  41. return;
  42. }
  43. var stepInfoList = PmsApi.GetHistoryStepList(taskId);
  44. if (stepInfoList == null) return;
  45. dataGridUI2.ShowDataGrid(stepInfoList.OrderBy(d => d.TemplateStepID).ToList());
  46. }
  47. private List<TaskInfo> GetHistoryTaskList()
  48. {
  49. var startTime = dateTimePicker1.Value;
  50. var endTime = dateTimePicker2.Value;
  51. if (endTime <= startTime)
  52. {
  53. MessageBox.Show("结束时间必须晚于开始时间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  54. return null;
  55. }
  56. var taskDataList = PmsApi.GetHistoryTaskList(startTime, endTime);
  57. if (taskDataList == null) return null;
  58. foreach (var item in taskDataList)
  59. {
  60. item.AllWarehouse = item.AllWarehouse.ToShortPosString();
  61. }
  62. return taskDataList;
  63. }
  64. private void button1_Click(object sender, EventArgs e)
  65. {
  66. try
  67. {
  68. var taskDataList = GetHistoryTaskList();
  69. if (taskDataList == null) return;
  70. dataGridUI1.ShowDataGrid(taskDataList);
  71. }
  72. catch (Exception ex)
  73. {
  74. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  75. }
  76. }
  77. private void button2_Click(object sender, EventArgs e)
  78. {
  79. using (SaveFileDialog dialog = new SaveFileDialog())
  80. {
  81. dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  82. dialog.FileName = string.Format("历史数据_{0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmss"));
  83. dialog.Filter = "Excel文件(*.xlsx)|*.xlsx|所有文件(*.*)|*.*";
  84. dialog.ValidateNames = true;
  85. dialog.CheckPathExists = true;
  86. dialog.AddExtension = true;
  87. DialogResult dialogResult = dialog.ShowDialog();
  88. if (dialogResult == DialogResult.OK)
  89. {
  90. try
  91. {
  92. var dataList = dataGridUI1.GetDataTable();
  93. Common.Config.ExcelConfig.Instance.SaveExcel(dialog.FileName, dataList);
  94. MessageBox.Show("导出成功!");
  95. }
  96. catch (Exception ex)
  97. {
  98. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  99. }
  100. }
  101. }
  102. }
  103. }
  104. }