TaskEditor.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 repsSat = unitOfWork.Of<SatInfo>();
  66. var sats = await repsSat.GetAllAsync();
  67. this.txtMainSat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  68. this.txtAdja1Sat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  69. this.txtAdja2Sat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  70. if (this.Text.StartsWith("编辑任务") && info != null)
  71. {
  72. var satMain = sats.FirstOrDefault(w => w.SatCode == info.MainSat);
  73. var satAdja1 = sats.FirstOrDefault(w => w.SatCode == info.Adja1Sat);
  74. var satAdja2 = sats.FirstOrDefault(w => w.SatCode == info.Adja2Sat);
  75. this.txtTaskName.Text = info.TaskName;
  76. this.txtPosType.SelectedIndex = (int)info.PosType;
  77. this.txtTaskType.SelectedIndex = (int)info.TaskType;
  78. this.txtMainSat.EditValue = satMain;
  79. this.txtAdja1Sat.EditValue = satAdja1;
  80. this.txtAdja2Sat.EditValue = satAdja2;
  81. txtCapDir.Text = info.CapDir;
  82. txtCapDirFormat.Text = info.CapDirFormat;
  83. }
  84. }
  85. private async void btnSave_ClickAsync(object sender, EventArgs e)
  86. {
  87. try
  88. {
  89. dxErrorProvider.ClearErrors();
  90. var posType = (EnumPosType)txtPosType.Properties.Items[txtPosType.SelectedIndex].Value;
  91. if (txtTaskName.EditValue == null)
  92. {
  93. dxErrorProvider.SetError(txtTaskName, "请填写任务名");
  94. return;
  95. }
  96. if (!selectedItem.Any())
  97. {
  98. DxHelper.MsgBoxHelper.ShowError("请选择信号");
  99. return;
  100. }
  101. if (this.Text == "添加任务")
  102. {
  103. var repsTask = unitOfWork.Of<TaskInfo>();
  104. if (await repsTask.FirstOrDefaultAsync(p => p.TaskName == txtTaskName.Text) != null)
  105. {
  106. dxErrorProvider.SetError(txtTaskName, "任务名称重复");
  107. return;
  108. }
  109. }
  110. else
  111. {
  112. var repsTask = unitOfWork.Of<TaskInfo>();
  113. if (await repsTask.FirstOrDefaultAsync(p => p.Id != info.Id && p.TaskName == txtTaskName.Text) != null)
  114. {
  115. dxErrorProvider.SetError(txtTaskName, "任务名称重复");
  116. return;
  117. }
  118. }
  119. if (posType == EnumPosType.X1D1CX)
  120. {
  121. if (txtMainSat.EditValue == null)
  122. {
  123. dxErrorProvider.SetError(txtMainSat, "请选择卫星");
  124. return;
  125. }
  126. }
  127. else if (posType == EnumPosType.X2D1 || posType == EnumPosType.RH || posType == EnumPosType.X2Dfo)
  128. {
  129. if (txtMainSat.EditValue == null)
  130. {
  131. dxErrorProvider.SetError(txtMainSat, "请选择主星");
  132. return;
  133. }
  134. if (txtAdja1Sat.EditValue == null)
  135. {
  136. dxErrorProvider.SetError(txtAdja1Sat, "请选择邻星");
  137. return;
  138. }
  139. if (txtMainSat.EditValue == txtAdja1Sat.EditValue)
  140. {
  141. dxErrorProvider.SetError(txtAdja1Sat, "邻星不能和主星一致");
  142. return;
  143. }
  144. }
  145. else if (posType == EnumPosType.X3TwoDto || posType == EnumPosType.X3TwoDfo)
  146. {
  147. if (txtMainSat.EditValue == null)
  148. {
  149. dxErrorProvider.SetError(txtMainSat, "请选择主星");
  150. return;
  151. }
  152. if (txtAdja1Sat.EditValue == null)
  153. {
  154. dxErrorProvider.SetError(txtAdja1Sat, "请选择邻星1");
  155. return;
  156. }
  157. if (txtAdja2Sat.EditValue == null)
  158. {
  159. dxErrorProvider.SetError(txtAdja2Sat, "请选择邻星2");
  160. return;
  161. }
  162. if (txtMainSat.EditValue == txtAdja1Sat.EditValue)
  163. {
  164. dxErrorProvider.SetError(txtAdja1Sat, "邻星1不能和主星一致");
  165. return;
  166. }
  167. if (txtMainSat.EditValue == txtAdja2Sat.EditValue)
  168. {
  169. dxErrorProvider.SetError(txtAdja2Sat, "邻星2不能和主星一致");
  170. return;
  171. }
  172. if (txtAdja1Sat.EditValue == txtAdja2Sat.EditValue)
  173. {
  174. dxErrorProvider.SetError(txtAdja2Sat, "邻星2不能和邻星1一致");
  175. return;
  176. }
  177. }
  178. if ((EnumTaskType)txtTaskType.EditValue == EnumTaskType.History)//是历史任务
  179. {
  180. if (string.IsNullOrWhiteSpace(txtCapDir.Text))
  181. {
  182. dxErrorProvider.SetError(txtCapDir, "请填写采集文件目录");
  183. return;
  184. }
  185. }
  186. info.TaskState = EnumTaskState.Stopped;
  187. info.TaskName = txtTaskName.Text;
  188. info.PosType = (EnumPosType)txtPosType.SelectedIndex;
  189. info.MainSat = ((SatInfo)txtMainSat.EditValue).SatCode;
  190. if (txtAdja1Sat.EditValue != null)
  191. info.Adja1Sat = ((SatInfo)txtAdja1Sat.EditValue).SatCode;
  192. if (txtAdja2Sat.EditValue != null)
  193. info.Adja2Sat = ((SatInfo)txtAdja2Sat.EditValue).SatCode;
  194. info.TaskType = (EnumTaskType)txtTaskType.SelectedIndex;
  195. if (info.TaskType == EnumTaskType.Group)
  196. {
  197. info.CapDir = null;
  198. info.CapDirFormat = null;
  199. }
  200. else
  201. {
  202. info.CapDir = txtCapDir.Text.Trim();
  203. info.CapDirFormat = txtCapDirFormat.Text.Trim();
  204. }
  205. this.DialogResult = DialogResult.OK;
  206. }
  207. catch (Exception ex)
  208. {
  209. string msg = "编辑任务信息出错";
  210. IocContainer.Logger.Error(ex, msg);
  211. DxHelper.MsgBoxHelper.ShowError(msg);
  212. }
  213. }
  214. private void txtPosType_EditValueChanged(object sender, EventArgs e)
  215. {
  216. RadioGroup posTypeRadioGroup = sender as RadioGroup;
  217. var posType = (EnumPosType)posTypeRadioGroup.Properties.Items[posTypeRadioGroup.SelectedIndex].Value;
  218. if (posType == EnumPosType.X1D1CX)
  219. {
  220. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  221. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  222. }
  223. else if (posType == EnumPosType.X2D1)
  224. {
  225. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  226. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  227. this.layoutControlItemAdja1.Text = "邻星";
  228. }
  229. else if (posType == EnumPosType.RH)
  230. {
  231. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  232. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  233. this.layoutControlItemAdja1.Text = "邻星";
  234. }
  235. else if (posType == EnumPosType.X3TwoDto)
  236. {
  237. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  238. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  239. this.layoutControlItemAdja1.Text = "邻星1";
  240. }
  241. else if (posType == EnumPosType.X3TwoDfo)
  242. {
  243. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  244. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  245. this.layoutControlItemAdja1.Text = "邻星1";
  246. }
  247. else if (posType == EnumPosType.X2Dfo)
  248. {
  249. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  250. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  251. this.layoutControlItemAdja1.Text = "邻星";
  252. }
  253. this.layoutControl1.BestFit();
  254. }
  255. private void txtTaskType_SelectedIndexChanged(object sender, EventArgs e)
  256. {
  257. if ((EnumTaskType)txtTaskType.EditValue == EnumTaskType.Group)
  258. {
  259. itemCapDir.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  260. itemCapDirFormat.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  261. if (this.Height >= 438)
  262. this.Height -= 55;
  263. }
  264. else
  265. {
  266. itemCapDir.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  267. itemCapDirFormat.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  268. //txtSignalType.Properties.Items.Remove(normal);//不要移除了
  269. var a = this.Height;
  270. if (this.Height < 438)
  271. this.Height += 55;
  272. }
  273. this.layoutControl1.BestFit();
  274. }
  275. private void btnFreq_Click(object sender, EventArgs e)
  276. {
  277. if (this.Text.StartsWith("添加任务"))
  278. {
  279. TaskEditorSignal frm = new TaskEditorSignal();
  280. if (frm.ShowDialog() != DialogResult.OK) return;
  281. frm.info = info;
  282. selectedItem.Clear();
  283. selectedItem = frm.listSigInfoSelected;
  284. }
  285. else if (this.Text.StartsWith("编辑任务") && info != null)
  286. {
  287. TaskEditorSignal frm = new TaskEditorSignal(info, selectedItem);
  288. if (frm.ShowDialog() != DialogResult.OK) return;
  289. selectedItem.Clear();
  290. selectedItem = frm.listSigInfoSelected;
  291. }
  292. }
  293. }
  294. }