TaskEditor.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. using DevExpress.Utils.About;
  2. using DevExpress.XtraBars.Customization;
  3. using DevExpress.XtraEditors;
  4. using DevExpress.XtraEditors.Controls;
  5. using DevExpress.XtraEditors.DXErrorProvider;
  6. using DxHelper;
  7. using ExtensionsDev;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.ComponentModel.DataAnnotations;
  12. using System.Data;
  13. using System.Data.Entity;
  14. using System.Drawing;
  15. using System.Linq;
  16. using System.Reflection;
  17. using System.Runtime.InteropServices;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using System.Windows.Documents;
  21. using System.Windows.Forms;
  22. using XdCxRhDW.Repostory.EFContext;
  23. using XdCxRhDW.Repostory.Model;
  24. namespace XdCxRhDW.App.EditForms
  25. {
  26. public partial class TaskEditor : DevExpress.XtraEditors.XtraForm
  27. {
  28. public TaskInfo info;
  29. public TaskEditor()
  30. {
  31. InitializeComponent();
  32. this.layoutControl1.UseDefault();
  33. this.Text = "添加任务";
  34. info = new TaskInfo();
  35. this.StartPosition = FormStartPosition.CenterParent;
  36. //加载DW类型
  37. List<RadioGroupItem> radioGroups = new List<RadioGroupItem>();
  38. var values = Enum.GetValues(typeof(EnumPosType));
  39. foreach (var item in values)
  40. {
  41. radioGroups.Add(new RadioGroupItem(Convert.ToInt32(item), ((EnumPosType)item).GetEnumDisplayName()));
  42. }
  43. this.txtPosType.Properties.Items.AddRange(radioGroups.ToArray());
  44. }
  45. public TaskEditor(TaskInfo info)
  46. : this()
  47. {
  48. this.Text = "编辑任务";
  49. this.info = info;
  50. }
  51. private async void TaskEditor_Load(object sender, EventArgs e)
  52. {
  53. using (RHDWContext db = new RHDWContext())
  54. {
  55. var sats = await db.SatInfos.ToListAsync();
  56. this.txtMainSat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  57. this.txtAdja1Sat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  58. this.txtAdja2Sat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  59. }
  60. if (this.Text == "编辑任务" && info != null)
  61. {
  62. using (RHDWContext db = new RHDWContext())
  63. {
  64. var satMain = await db.SatInfos.Where(w => w.SatCode == info.MainSat).FirstOrDefaultAsync();
  65. var satAdja1 = await db.SatInfos.Where(w => w.SatCode == info.Adja1Sat).FirstOrDefaultAsync();
  66. var satAdja2 = await db.SatInfos.Where(w => w.SatCode == info.Adja2Sat).FirstOrDefaultAsync();
  67. this.txtTaskName.Text = info.TaskName;
  68. this.txtPosType.SelectedIndex = (int)info.PosType;
  69. this.txtMainSat.EditValue = satMain;
  70. this.txtAdja1Sat.EditValue = satAdja1;
  71. this.txtAdja2Sat.EditValue = satAdja2;
  72. this.txtFreq.EditValue = info.Freq * (decimal)1e-6;
  73. this.txtBand.EditValue = info.Band * (decimal)1e-6;
  74. }
  75. }
  76. }
  77. private void btnSave_Click(object sender, EventArgs e)
  78. {
  79. try
  80. {
  81. dxErrorProvider.ClearErrors();
  82. if (txtTaskName.EditValue == null)
  83. {
  84. dxErrorProvider.SetError(txtTaskName, "请填写任务名");
  85. return;
  86. }
  87. if (this.Text == "添加卫星")
  88. {
  89. using (RHDWContext db = new RHDWContext())
  90. {
  91. if (db.TaskInfos.Any(p => p.TaskName == txtTaskName.Text))
  92. {
  93. dxErrorProvider.SetError(txtTaskName, "任务名称重复");
  94. return;
  95. }
  96. }
  97. }
  98. else
  99. {
  100. using (RHDWContext db = new RHDWContext())
  101. {
  102. if (db.TaskInfos.Any(p => p.ID != info.ID && p.TaskName == txtTaskName.Text))
  103. {
  104. dxErrorProvider.SetError(txtTaskName, "任务名称重复");
  105. return;
  106. }
  107. }
  108. if (txtPosType.SelectedIndex == -1)
  109. {
  110. dxErrorProvider.SetError(txtPosType, "请选择定位类型");
  111. return;
  112. }
  113. var posType = (EnumPosType)txtPosType.Properties.Items[txtPosType.SelectedIndex].Value;
  114. if (posType == EnumPosType.X1D1CX)
  115. {
  116. if (txtMainSat.EditValue == null)
  117. {
  118. dxErrorProvider.SetError(txtMainSat, "请选择卫星");
  119. return;
  120. }
  121. }
  122. else if (posType == EnumPosType.X2D1 || posType == EnumPosType.RH || posType == EnumPosType.X2Dfo)
  123. {
  124. if (txtMainSat.EditValue == null)
  125. {
  126. dxErrorProvider.SetError(txtMainSat, "请选择主星");
  127. return;
  128. }
  129. if (txtAdja1Sat.EditValue == null)
  130. {
  131. dxErrorProvider.SetError(txtAdja1Sat, "请选择邻星");
  132. return;
  133. }
  134. }
  135. else if (posType == EnumPosType.X3TwoDto || posType == EnumPosType.X3TwoDfo)
  136. {
  137. if (txtMainSat.EditValue == null)
  138. {
  139. dxErrorProvider.SetError(txtMainSat, "请选择主星");
  140. return;
  141. }
  142. if (txtAdja1Sat.EditValue == null)
  143. {
  144. dxErrorProvider.SetError(txtAdja1Sat, "请选择邻星1");
  145. return;
  146. }
  147. if (txtAdja2Sat.EditValue == null)
  148. {
  149. dxErrorProvider.SetError(txtAdja2Sat, "请选择邻星2");
  150. return;
  151. }
  152. }
  153. if (txtFreq.EditValue == null)
  154. {
  155. dxErrorProvider.SetError(txtFreq, "请填写频点");
  156. return;
  157. }
  158. if (txtBand.EditValue == null)
  159. {
  160. dxErrorProvider.SetError(txtBand, "请填写带宽");
  161. return;
  162. }
  163. info.TaskState = EnumTaskState.Stopped;
  164. info.TaskName = txtTaskName.Text;
  165. info.PosType = (EnumPosType)txtPosType.SelectedIndex;
  166. info.MainSat = ((SatInfo)txtMainSat.EditValue).SatCode;
  167. if (txtAdja1Sat.EditValue != null)
  168. info.Adja1Sat = ((SatInfo)txtAdja1Sat.EditValue).SatCode;
  169. if (txtAdja2Sat.EditValue != null)
  170. info.Adja2Sat = ((SatInfo)txtAdja2Sat.EditValue).SatCode;
  171. info.Freq = (long)(Convert.ToDouble(txtFreq.EditValue) * 1e6);
  172. info.Band = (int)(Convert.ToDouble(txtBand.EditValue) * 1e6);
  173. this.DialogResult = DialogResult.OK;
  174. }
  175. }
  176. catch (Exception ex)
  177. {
  178. Serilog.Log.Error(ex, "编辑任务信息出错");
  179. DxHelper.MsgBoxHelper.ShowError("编辑任务信息出错");
  180. }
  181. }
  182. private void txtPosType_EditValueChanged(object sender, EventArgs e)
  183. {
  184. RadioGroup posTypeRadioGroup = sender as RadioGroup;
  185. var posType = (EnumPosType)posTypeRadioGroup.Properties.Items[posTypeRadioGroup.SelectedIndex].Value;
  186. //var description = (EnumPosType)posType.Properties.Items[posType.SelectedIndex].Description;
  187. if (posType == EnumPosType.X1D1CX)
  188. {
  189. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  190. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  191. }
  192. else if (posType == EnumPosType.X2D1)
  193. {
  194. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  195. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  196. this.layoutControlItemAdja1.Text = "邻星";
  197. }
  198. else if (posType == EnumPosType.RH)
  199. {
  200. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  201. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  202. this.layoutControlItemAdja1.Text = "邻星";
  203. }
  204. else if (posType == EnumPosType.X3TwoDto)
  205. {
  206. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  207. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  208. this.layoutControlItemAdja1.Text = "邻星1";
  209. }
  210. else if (posType == EnumPosType.X3TwoDfo)
  211. {
  212. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  213. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  214. this.layoutControlItemAdja1.Text = "邻星1";
  215. }
  216. else if (posType == EnumPosType.X2Dfo)
  217. {
  218. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  219. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  220. this.layoutControlItemAdja1.Text = "邻星";
  221. }
  222. else
  223. {
  224. return;
  225. }
  226. }
  227. }
  228. }