TaskEditor.cs 13 KB

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