TaskEditor.cs 13 KB

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