CtrlHome.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using DataSimulation.Forms.EditForms;
  2. using DataSimulation.Repostory;
  3. using DataSimulation.Repostory.EFContext;
  4. using DataSimulation.Repostory.Model;
  5. using DevExpress.Utils;
  6. using DevExpress.XtraEditors.ButtonsPanelControl;
  7. using DevExpress.XtraMap;
  8. using DxHelper;
  9. using ExtensionsDev;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Data;
  14. using System.Data.Entity;
  15. using System.Drawing;
  16. using System.IO;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using System.Windows.Forms;
  21. namespace DataSimulation.Forms.UserControl
  22. {
  23. public partial class CtrlHome : DevExpress.XtraEditors.XtraUserControl
  24. {
  25. List<TaskInfo> taskList = new List<TaskInfo>();
  26. public CtrlHome()
  27. {
  28. InitializeComponent();
  29. gridControl.Init<TaskInfo>().UseFilter();
  30. layoutControl1.UseDefault();
  31. mapControl
  32. .UseDefalutOptions()
  33. .UseClearAll()
  34. .UseDistanceLine()
  35. .UseMarkDot()
  36. .UseExportImg()
  37. .UseExportXlsx()
  38. .UseExportCsv()
  39. .SetMapLayerType(null)
  40. .UseDrawRect(rect =>
  41. {
  42. (double startLon, double startLat, double centerLon, double centerLat, double endLon, double endLat, double lonRange, double latRange) = rect;
  43. }).UseFlightLine()
  44. ;
  45. }
  46. private async void CtrlHome_Load(object sender, EventArgs e)
  47. {
  48. try
  49. {
  50. var yearDirs = Directory.EnumerateDirectories(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbPart")).OrderByDescending(p => Convert.ToInt32(new DirectoryInfo(p).Name));//年目录,倒叙排列
  51. foreach (var yearDir in yearDirs)
  52. {
  53. //每一天的db文件,倒序排列
  54. var dayFiles = Directory.EnumerateFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, yearDir), "*.db").OrderByDescending(p => Convert.ToInt32(new DirectoryInfo(p).Name.Substring(0, 4)));
  55. foreach (var dayFile in dayFiles)
  56. {
  57. using (SimulationPartContext db = SimulationPartContext.GetContext(dayFile))
  58. {
  59. taskList.AddRange(await db.TaskInfos.ToListAsync());
  60. var runningList = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running).ToListAsync();
  61. foreach (var item in runningList)
  62. {
  63. item.TaskState = EnumTaskState.Stopped;
  64. }
  65. await db.SaveChangesAsync();
  66. }
  67. }
  68. }
  69. gridControl.DataSource = taskList;
  70. gridView.Columns[nameof(TaskInfo.TaskName)].AppearanceCell.TextOptions.HAlignment = HorzAlignment.Near;
  71. this.svgImageCollection1.Add("Stopped", SvgHelper.CreateCycle("#1E8B58"));
  72. this.svgImageCollection1.Add("Running", SvgHelper.CreateCycle("#2E8B57"));
  73. }
  74. catch (Exception)
  75. {
  76. throw;
  77. }
  78. }
  79. private async void layoutControlGroup_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
  80. {
  81. var txt = (e.Button as GroupBoxButton).Caption;
  82. if (txt == "新建任务")
  83. {
  84. try
  85. {
  86. TaskEditor frm = new TaskEditor();
  87. if (frm.ShowDialog() != DialogResult.OK) return;
  88. var addItem = frm.info;
  89. var taskList = await TaskCache.GetAllAsync();
  90. //if (await taskList.ToList().(p => p.TaskName == addItem.TaskName))
  91. //{
  92. // DxHelper.MsgBoxHelper.ShowWarning("任务名称重复");
  93. // return;
  94. //}
  95. //using (SimulationContext db = new RHDWContext())
  96. //{
  97. // if (await db.TaskInfos.AnyAsync(p => p.TaskName == addItem.TaskName))
  98. // {
  99. // DxHelper.MsgBoxHelper.ShowWarning("任务名称重复");
  100. // return;
  101. // }
  102. // if (addItem.PosType == EnumPosType.X1D1CX)
  103. // {
  104. // addItem.Adja1Sat = null;
  105. // addItem.Adja2Sat = null;
  106. // }
  107. // else if (addItem.PosType == EnumPosType.X2D1 || addItem.PosType == EnumPosType.X2Dfo || addItem.PosType == EnumPosType.RH)
  108. // {
  109. // addItem.Adja2Sat = null;
  110. // }
  111. // db.TaskInfos.Add(addItem);
  112. // await db.SaveChangesAsync();
  113. //}
  114. //list.Insert(0, addItem);
  115. //gridView1.RefreshData();
  116. //gridView1.FocusedRowHandle = 0;
  117. }
  118. catch (Exception ex)
  119. {
  120. Serilog.Log.Error(ex, "保存任务异常");
  121. DxHelper.MsgBoxHelper.ShowError("保存任务异常");
  122. }
  123. }
  124. }
  125. }
  126. }