TaskEditor.cs 9.0 KB

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