TaskEditor.cs 13 KB

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