TaskEditor.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  49. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  50. this.layoutControl1.BestFit();
  51. }
  52. public TaskEditor(TaskInfo info, List<SigInfo> taskSigList)
  53. : this()
  54. {
  55. this.Text = $"编辑任务[{info.TaskName}]";
  56. this.info = info;
  57. this.selectedItem = taskSigList;
  58. }
  59. private async void TaskEditor_Load(object sender, EventArgs e)
  60. {
  61. using (RHDWContext db = new RHDWContext())
  62. {
  63. var sats = await db.SatInfos.ToListAsync();
  64. this.txtMainSat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  65. this.txtAdja1Sat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  66. this.txtAdja2Sat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  67. }
  68. if (this.Text.StartsWith("编辑任务") && info != null)
  69. {
  70. using (RHDWContext db = new RHDWContext())
  71. {
  72. var satMain = await db.SatInfos.Where(w => w.SatCode == info.MainSat).FirstOrDefaultAsync();
  73. var satAdja1 = await db.SatInfos.Where(w => w.SatCode == info.Adja1Sat).FirstOrDefaultAsync();
  74. var satAdja2 = await db.SatInfos.Where(w => w.SatCode == info.Adja2Sat).FirstOrDefaultAsync();
  75. this.txtTaskName.Text = info.TaskName;
  76. this.txtPosType.SelectedIndex = (int)info.PosType;
  77. this.txtMainSat.EditValue = satMain;
  78. this.txtAdja1Sat.EditValue = satAdja1;
  79. this.txtAdja2Sat.EditValue = satAdja2;
  80. }
  81. }
  82. }
  83. private void btnSave_Click(object sender, EventArgs e)
  84. {
  85. try
  86. {
  87. dxErrorProvider.ClearErrors();
  88. var posType = (EnumPosType)txtPosType.Properties.Items[txtPosType.SelectedIndex].Value;
  89. if (txtTaskName.EditValue == null)
  90. {
  91. dxErrorProvider.SetError(txtTaskName, "请填写任务名");
  92. return;
  93. }
  94. if (!selectedItem.Any())
  95. {
  96. DxHelper.MsgBoxHelper.ShowError("请选择信号");
  97. return;
  98. }
  99. if (this.Text == "添加任务")
  100. {
  101. using (RHDWContext db = new RHDWContext())
  102. {
  103. if (db.TaskInfos.Any(p => p.TaskName == txtTaskName.Text))
  104. {
  105. dxErrorProvider.SetError(txtTaskName, "任务名称重复");
  106. return;
  107. }
  108. }
  109. }
  110. else
  111. {
  112. using (RHDWContext db = new RHDWContext())
  113. {
  114. if (db.TaskInfos.Any(p => p.ID != info.ID && p.TaskName == txtTaskName.Text))
  115. {
  116. dxErrorProvider.SetError(txtTaskName, "任务名称重复");
  117. return;
  118. }
  119. }
  120. }
  121. if (posType == EnumPosType.X1Leo)
  122. {
  123. if (txtMainSat.EditValue == null)
  124. {
  125. dxErrorProvider.SetError(txtMainSat, "请选择卫星");
  126. return;
  127. }
  128. }
  129. else if (posType == EnumPosType.X2D1 || posType == EnumPosType.X2Leo)
  130. {
  131. if (txtMainSat.EditValue == null)
  132. {
  133. dxErrorProvider.SetError(txtMainSat, "请选择主星");
  134. return;
  135. }
  136. if (txtAdja1Sat.EditValue == null)
  137. {
  138. dxErrorProvider.SetError(txtAdja1Sat, "请选择邻星");
  139. return;
  140. }
  141. if (txtMainSat.EditValue == txtAdja1Sat.EditValue)
  142. {
  143. dxErrorProvider.SetError(txtAdja1Sat, "邻星不能和主星一致");
  144. return;
  145. }
  146. }
  147. else if (posType == EnumPosType.X3TwoDto || posType == EnumPosType.X3Leo)
  148. {
  149. if (txtMainSat.EditValue == null)
  150. {
  151. dxErrorProvider.SetError(txtMainSat, "请选择主星");
  152. return;
  153. }
  154. if (txtAdja1Sat.EditValue == null)
  155. {
  156. dxErrorProvider.SetError(txtAdja1Sat, "请选择邻星1");
  157. return;
  158. }
  159. if (txtAdja2Sat.EditValue == null)
  160. {
  161. dxErrorProvider.SetError(txtAdja2Sat, "请选择邻星2");
  162. return;
  163. }
  164. if (txtMainSat.EditValue == txtAdja1Sat.EditValue)
  165. {
  166. dxErrorProvider.SetError(txtAdja1Sat, "邻星1不能和主星一致");
  167. return;
  168. }
  169. if (txtMainSat.EditValue == txtAdja2Sat.EditValue)
  170. {
  171. dxErrorProvider.SetError(txtAdja2Sat, "邻星2不能和主星一致");
  172. return;
  173. }
  174. if (txtAdja1Sat.EditValue == txtAdja2Sat.EditValue)
  175. {
  176. dxErrorProvider.SetError(txtAdja2Sat, "邻星2不能和邻星1一致");
  177. return;
  178. }
  179. }
  180. info.TaskState = EnumTaskState.Stopped;
  181. info.TaskName = txtTaskName.Text;
  182. info.PosType = (EnumPosType)txtPosType.SelectedIndex;
  183. info.MainSat = ((SatInfo)txtMainSat.EditValue).SatCode;
  184. if (txtAdja1Sat.EditValue != null)
  185. info.Adja1Sat = ((SatInfo)txtAdja1Sat.EditValue).SatCode;
  186. if (txtAdja2Sat.EditValue != null)
  187. info.Adja2Sat = ((SatInfo)txtAdja2Sat.EditValue).SatCode;
  188. info.TaskType = EnumTaskType.Real;
  189. this.DialogResult = DialogResult.OK;
  190. }
  191. catch (Exception ex)
  192. {
  193. Serilog.Log.Error(ex, "编辑任务信息出错");
  194. DxHelper.MsgBoxHelper.ShowError("编辑任务信息出错");
  195. }
  196. }
  197. private void txtPosType_EditValueChanged(object sender, EventArgs e)
  198. {
  199. RadioGroup posTypeRadioGroup = sender as RadioGroup;
  200. var posType = (EnumPosType)posTypeRadioGroup.Properties.Items[posTypeRadioGroup.SelectedIndex].Value;
  201. if (posType == EnumPosType.X1Leo)
  202. {
  203. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  204. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  205. }
  206. else if (posType == EnumPosType.X2D1 || posType == EnumPosType.X2Leo)
  207. {
  208. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  209. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  210. this.layoutControlItemAdja1.Text = "邻星";
  211. }
  212. else if (posType == EnumPosType.X3TwoDto || posType == EnumPosType.X3Leo)
  213. {
  214. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  215. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  216. this.layoutControlItemAdja1.Text = "邻星1";
  217. }
  218. this.layoutControl1.BestFit();
  219. }
  220. private void btnFreq_Click(object sender, EventArgs e)
  221. {
  222. if (this.Text.StartsWith("添加任务"))
  223. {
  224. TaskEditorSignal frm = new TaskEditorSignal();
  225. if (frm.ShowDialog() != DialogResult.OK) return;
  226. frm.info = info;
  227. selectedItem.Clear();
  228. selectedItem = frm.listSigInfoSelected;
  229. }
  230. else if (this.Text.StartsWith("编辑任务") && info != null)
  231. {
  232. TaskEditorSignal frm = new TaskEditorSignal(info, selectedItem);
  233. if (frm.ShowDialog() != DialogResult.OK) return;
  234. selectedItem.Clear();
  235. selectedItem = frm.listSigInfoSelected;
  236. }
  237. }
  238. }
  239. }