TaskEditor.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. using DevExpress.Utils.About;
  2. using DevExpress.Utils.Extensions;
  3. using DevExpress.XtraBars.Customization;
  4. using DevExpress.XtraEditors;
  5. using DevExpress.XtraEditors.ButtonsPanelControl;
  6. using DevExpress.XtraEditors.Controls;
  7. using DevExpress.XtraEditors.DXErrorProvider;
  8. using DevExpress.XtraPrinting.Native;
  9. using DxHelper;
  10. using ExtensionsDev;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.ComponentModel;
  14. using System.ComponentModel.DataAnnotations;
  15. using System.Data;
  16. using System.Drawing;
  17. using System.Linq;
  18. using System.Reflection;
  19. using System.Runtime.InteropServices;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. using System.Windows.Documents;
  23. using System.Windows.Forms;
  24. using DW5S.DTO;
  25. using DW5S.Entity;
  26. using DW5S.Repostory;
  27. using Serilog;
  28. using DW5S.Service;
  29. namespace DW5S.App.EditForms
  30. {
  31. public partial class TaskEditor : DevExpress.XtraEditors.XtraForm
  32. {
  33. public TaskInfo info;
  34. public List<SigInfo> selectedItem = new List<SigInfo>();
  35. public TaskEditor()
  36. {
  37. InitializeComponent();
  38. this.layoutControl1.UseDefault();
  39. this.Text = "添加任务";
  40. info = new TaskInfo();
  41. this.StartPosition = FormStartPosition.CenterParent;
  42. //加载DW类型
  43. var values = Enum.GetValues(typeof(EnumPosType));
  44. foreach (var item in values)
  45. {
  46. this.txtPosType.Properties.Items.Add(new RadioGroupItem(Convert.ToInt32(item), ((EnumPosType)item).GetEnumDisplayName()));
  47. }
  48. values = Enum.GetValues(typeof(EnumTaskType));
  49. foreach (var item in values)
  50. {
  51. this.txtTaskType.Properties.Items.Add(new RadioGroupItem(Convert.ToInt32(item), ((EnumTaskType)item).GetEnumDisplayName()));
  52. }
  53. this.txtTaskType.SelectedIndex = 0;
  54. this.txtTaskType_SelectedIndexChanged(this, EventArgs.Empty);
  55. }
  56. public TaskEditor(TaskInfo info, List<SigInfo> taskSigList)
  57. : this()
  58. {
  59. this.Text = $"编辑任务[{info.TaskName}]";
  60. this.info = info;
  61. this.selectedItem = taskSigList;
  62. }
  63. private async void TaskEditor_Load(object sender, EventArgs e)
  64. {
  65. var unitOfWork = IocContainer.UnitOfWork;
  66. var repsSat = unitOfWork.Of<SatInfo>();
  67. var sats = await repsSat.GetAllAsync();
  68. this.txtMainSat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  69. this.txtAdja1Sat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  70. this.txtAdja2Sat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  71. if (this.Text.StartsWith("编辑任务") && info != null)
  72. {
  73. var satMain = sats.FirstOrDefault(w => w.SatCode == info.MainSat);
  74. var satAdja1 = sats.FirstOrDefault(w => w.SatCode == info.Adja1Sat);
  75. var satAdja2 = sats.FirstOrDefault(w => w.SatCode == info.Adja2Sat);
  76. this.txtTaskName.Text = info.TaskName;
  77. this.txtPosType.SelectedIndex = (int)info.PosType;
  78. this.txtTaskType.SelectedIndex = (int)info.TaskType;
  79. this.txtMainSat.EditValue = satMain;
  80. this.txtAdja1Sat.EditValue = satAdja1;
  81. this.txtAdja2Sat.EditValue = satAdja2;
  82. txtCapDir.Text = info.CapDir;
  83. txtCapDirFormat.Text = info.CapDirFormat;
  84. }
  85. }
  86. private async void btnSave_ClickAsync(object sender, EventArgs e)
  87. {
  88. try
  89. {
  90. dxErrorProvider.ClearErrors();
  91. var posType = (EnumPosType)txtPosType.Properties.Items[txtPosType.SelectedIndex].Value;
  92. if (txtTaskName.EditValue == null)
  93. {
  94. dxErrorProvider.SetError(txtTaskName, "请填写任务名");
  95. return;
  96. }
  97. if (!selectedItem.Any())
  98. {
  99. DxHelper.MsgBoxHelper.ShowError("请选择信号");
  100. return;
  101. }
  102. if (this.Text == "添加任务")
  103. {
  104. var unitOfWork = IocContainer.UnitOfWork;
  105. var repsTask = unitOfWork.Of<TaskInfo>();
  106. if (await repsTask.FirstOrDefaultAsync(p => p.TaskName == txtTaskName.Text) != null)
  107. {
  108. dxErrorProvider.SetError(txtTaskName, "任务名称重复");
  109. return;
  110. }
  111. }
  112. else
  113. {
  114. var unitOfWork = IocContainer.UnitOfWork;
  115. var repsTask = unitOfWork.Of<TaskInfo>();
  116. if (await repsTask.FirstOrDefaultAsync(p => p.Id != info.Id && p.TaskName == txtTaskName.Text) != null)
  117. {
  118. dxErrorProvider.SetError(txtTaskName, "任务名称重复");
  119. return;
  120. }
  121. }
  122. if (posType == EnumPosType.X1D1CX)
  123. {
  124. if (txtMainSat.EditValue == null)
  125. {
  126. dxErrorProvider.SetError(txtMainSat, "请选择卫星");
  127. return;
  128. }
  129. }
  130. else if (posType == EnumPosType.X2D1 || posType == EnumPosType.RH || posType == EnumPosType.X2Dfo)
  131. {
  132. if (txtMainSat.EditValue == null)
  133. {
  134. dxErrorProvider.SetError(txtMainSat, "请选择主星");
  135. return;
  136. }
  137. if (txtAdja1Sat.EditValue == null)
  138. {
  139. dxErrorProvider.SetError(txtAdja1Sat, "请选择邻星");
  140. return;
  141. }
  142. if (txtMainSat.EditValue == txtAdja1Sat.EditValue)
  143. {
  144. dxErrorProvider.SetError(txtAdja1Sat, "邻星不能和主星一致");
  145. return;
  146. }
  147. }
  148. else if (posType == EnumPosType.X3TwoDto || posType == EnumPosType.X3TwoDfo)
  149. {
  150. if (txtMainSat.EditValue == null)
  151. {
  152. dxErrorProvider.SetError(txtMainSat, "请选择主星");
  153. return;
  154. }
  155. if (txtAdja1Sat.EditValue == null)
  156. {
  157. dxErrorProvider.SetError(txtAdja1Sat, "请选择邻星1");
  158. return;
  159. }
  160. if (txtAdja2Sat.EditValue == null)
  161. {
  162. dxErrorProvider.SetError(txtAdja2Sat, "请选择邻星2");
  163. return;
  164. }
  165. if (txtMainSat.EditValue == txtAdja1Sat.EditValue)
  166. {
  167. dxErrorProvider.SetError(txtAdja1Sat, "邻星1不能和主星一致");
  168. return;
  169. }
  170. if (txtMainSat.EditValue == txtAdja2Sat.EditValue)
  171. {
  172. dxErrorProvider.SetError(txtAdja2Sat, "邻星2不能和主星一致");
  173. return;
  174. }
  175. if (txtAdja1Sat.EditValue == txtAdja2Sat.EditValue)
  176. {
  177. dxErrorProvider.SetError(txtAdja2Sat, "邻星2不能和邻星1一致");
  178. return;
  179. }
  180. }
  181. if ((EnumTaskType)txtTaskType.EditValue == EnumTaskType.History)//是历史任务
  182. {
  183. if (string.IsNullOrWhiteSpace(txtCapDir.Text))
  184. {
  185. dxErrorProvider.SetError(txtCapDir, "请填写采集文件目录");
  186. return;
  187. }
  188. }
  189. info.TaskState = EnumTaskState.Stopped;
  190. info.TaskName = txtTaskName.Text;
  191. info.PosType = (EnumPosType)txtPosType.SelectedIndex;
  192. info.MainSat = ((SatInfo)txtMainSat.EditValue).SatCode;
  193. if (txtAdja1Sat.EditValue != null)
  194. info.Adja1Sat = ((SatInfo)txtAdja1Sat.EditValue).SatCode;
  195. if (txtAdja2Sat.EditValue != null)
  196. info.Adja2Sat = ((SatInfo)txtAdja2Sat.EditValue).SatCode;
  197. info.TaskType = (EnumTaskType)txtTaskType.SelectedIndex;
  198. if (info.TaskType == EnumTaskType.Group)
  199. {
  200. info.CapDir = null;
  201. info.CapDirFormat = null;
  202. }
  203. else
  204. {
  205. info.CapDir = txtCapDir.Text.Trim();
  206. info.CapDirFormat = txtCapDirFormat.Text.Trim();
  207. }
  208. this.DialogResult = DialogResult.OK;
  209. }
  210. catch (Exception ex)
  211. {
  212. string msg = "编辑任务信息出错";
  213. IocContainer.Logger.Error(ex, msg);
  214. DxHelper.MsgBoxHelper.ShowError(msg);
  215. }
  216. }
  217. private void txtPosType_EditValueChanged(object sender, EventArgs e)
  218. {
  219. RadioGroup posTypeRadioGroup = sender as RadioGroup;
  220. var posType = (EnumPosType)posTypeRadioGroup.Properties.Items[posTypeRadioGroup.SelectedIndex].Value;
  221. if (posType == EnumPosType.X1D1CX)
  222. {
  223. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  224. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  225. }
  226. else if (posType == EnumPosType.X2D1)
  227. {
  228. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  229. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  230. this.layoutControlItemAdja1.Text = "邻星";
  231. }
  232. else if (posType == EnumPosType.RH)
  233. {
  234. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  235. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  236. this.layoutControlItemAdja1.Text = "邻星";
  237. }
  238. else if (posType == EnumPosType.X3TwoDto)
  239. {
  240. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  241. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  242. this.layoutControlItemAdja1.Text = "邻星1";
  243. }
  244. else if (posType == EnumPosType.X3TwoDfo)
  245. {
  246. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  247. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  248. this.layoutControlItemAdja1.Text = "邻星1";
  249. }
  250. else if (posType == EnumPosType.X2Dfo)
  251. {
  252. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  253. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  254. this.layoutControlItemAdja1.Text = "邻星";
  255. }
  256. this.layoutControl1.BestFit();
  257. }
  258. private void txtTaskType_SelectedIndexChanged(object sender, EventArgs e)
  259. {
  260. if ((EnumTaskType)txtTaskType.EditValue == EnumTaskType.Group)
  261. {
  262. itemCapDir.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  263. itemCapDirFormat.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  264. if (this.Height >= 438)
  265. this.Height -= 55;
  266. }
  267. else
  268. {
  269. itemCapDir.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  270. itemCapDirFormat.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  271. //txtSignalType.Properties.Items.Remove(normal);//不要移除了
  272. var a = this.Height;
  273. if (this.Height < 438)
  274. this.Height += 55;
  275. }
  276. this.layoutControl1.BestFit();
  277. }
  278. private void btnFreq_Click(object sender, EventArgs e)
  279. {
  280. if (this.Text.StartsWith("添加任务"))
  281. {
  282. TaskEditorSignal frm = new TaskEditorSignal();
  283. if (frm.ShowDialog() != DialogResult.OK) return;
  284. frm.info = info;
  285. selectedItem.Clear();
  286. selectedItem = frm.listSigInfoSelected;
  287. }
  288. else if (this.Text.StartsWith("编辑任务") && info != null)
  289. {
  290. TaskEditorSignal frm = new TaskEditorSignal(info, selectedItem);
  291. if (frm.ShowDialog() != DialogResult.OK) return;
  292. selectedItem.Clear();
  293. selectedItem = frm.listSigInfoSelected;
  294. }
  295. }
  296. }
  297. }