TaskEditor.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. using DataSimulation.Repostory;
  2. using DataSimulation.Repostory.EFContext;
  3. using DataSimulation.Repostory.Model;
  4. using DevExpress.Utils.About;
  5. using DevExpress.XtraEditors;
  6. using DevExpress.XtraEditors.Controls;
  7. using DxHelper;
  8. using ExtensionsDev;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.ComponentModel;
  12. using System.Data;
  13. using System.Data.Entity;
  14. using System.Drawing;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using System.Windows.Forms;
  19. namespace DataSimulation.Forms.EditForms
  20. {
  21. public partial class TaskEditor : DevExpress.XtraEditors.XtraForm
  22. {
  23. public TaskInfo info;
  24. public TaskEditor()
  25. {
  26. InitializeComponent();
  27. //this.layoutControl1.UseDefault();
  28. this.Text = "添加任务";
  29. info = new TaskInfo();
  30. this.StartPosition = FormStartPosition.CenterParent;
  31. List<RadioGroupItem> radioGroups = new List<RadioGroupItem>();
  32. var values = Enum.GetValues(typeof(EnumSimulationType));
  33. foreach (var item in values)
  34. {
  35. radioGroups.Add(new RadioGroupItem(Convert.ToInt32(item), ((EnumSimulationType)item).GetEnumDisplayName()));
  36. }
  37. this.radioSimulationType.Properties.Items.AddRange(radioGroups.ToArray());
  38. this.radioSimulationType.SelectedIndex = 0;
  39. }
  40. public TaskEditor(TaskInfo info)
  41. : this()
  42. {
  43. this.Text = "编辑任务";
  44. this.info = info;
  45. }
  46. private async void TaskEditor_Load(object sender, EventArgs e)
  47. {
  48. mapControl.UseDefalutOptions()
  49. .UseClearAll()
  50. .UseDistanceLine()
  51. .UseMarkDot()
  52. .UseExportImg()
  53. .UseExportXlsx()
  54. .UseExportCsv()
  55. .UseFlightLine(res =>
  56. {
  57. (bool isShowPopup, XtraUserControl frm) = res;
  58. if (isShowPopup)
  59. {
  60. DxHelper.PopupHelper.ShowPopup(frm, mapControl, 400);
  61. }
  62. else
  63. {
  64. DxHelper.PopupHelper.HidePopup(frm);
  65. }
  66. })
  67. .SetMapLayerType(null)
  68. .UseDrawRect(rect =>
  69. {
  70. (double startLon, double startLat, double centerLon, double centerLat, double endLon, double endLat, double lonRange, double latRange) = rect;
  71. });
  72. var hjList = await SimulationCache.GetAllAsync();
  73. this.txtHj.UseDefault().SetData(hjList, nameof(SimulationInfo.SimulationName)).UseDoubleClickToSelectAll();
  74. using (SimulationContext db = new SimulationContext())
  75. {
  76. var sats = await db.SatInfos.ToListAsync();
  77. this.txtMainSat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  78. this.txtAdjaSat1.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  79. this.txtAdjaSat2.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  80. var ants = await db.AntInfos.ToListAsync();
  81. foreach (var item in ants)
  82. {
  83. this.txtTx.Properties.Items.Add(new ImageComboBoxItem(item.AntName, item.ID));
  84. }
  85. var refs = await db.RefInfos.ToListAsync();
  86. foreach (var item in refs)
  87. {
  88. this.txtRefStation.Properties.Items.Add(new ImageComboBoxItem(item.RefName, item.ID));
  89. }
  90. }
  91. if (this.Text == "编辑任务" && info != null)
  92. {
  93. using (SimulationContext db = new SimulationContext())
  94. {
  95. var satMain = await db.SatInfos.Where(w => w.SatCode == info.MainSat).FirstOrDefaultAsync();
  96. var satAdja1 = await db.SatInfos.Where(w => w.SatCode == info.Adja1Sat).FirstOrDefaultAsync();
  97. var satAdja2 = await db.SatInfos.Where(w => w.SatCode == info.Adja2Sat).FirstOrDefaultAsync();
  98. this.txtTaskName.Text = info.TaskName;
  99. this.radioSimulationType.SelectedIndex = (int)info.SimulationType;
  100. this.txtMainSat.EditValue = satMain;
  101. this.txtAdjaSat1.EditValue = satAdja1;
  102. this.txtAdjaSat2.EditValue = satAdja2;
  103. this.txtTx.EditValue = info.AntID;
  104. this.txtRefStation.EditValue = info.RefID;
  105. this.txtFreqUp.EditValue = info.Freq * (decimal)1e-6;
  106. this.txtBand.EditValue = info.Band * (decimal)1e-6;
  107. this.txtSpeed.EditValue = info.Speed;
  108. }
  109. }
  110. }
  111. /// <summary>
  112. /// 验证信息
  113. /// </summary>
  114. private void validation()
  115. {
  116. try
  117. {
  118. dxErrorProvider.ClearErrors();
  119. if (txtTaskName.EditValue == null)
  120. {
  121. dxErrorProvider.SetError(txtTaskName, "请填写任务名");
  122. return;
  123. }
  124. if (radioSimulationType.SelectedIndex == -1)
  125. {
  126. dxErrorProvider.SetError(radioSimulationType, "请选择仿真类型");
  127. return;
  128. }
  129. var posType = (EnumSimulationType)radioSimulationType.Properties.Items[radioSimulationType.SelectedIndex].Value;
  130. if (posType == EnumSimulationType.X3TwoDto)
  131. {
  132. if (txtMainSat.EditValue == null)
  133. {
  134. dxErrorProvider.SetError(txtMainSat, "请选择主星");
  135. return;
  136. }
  137. if (txtAdjaSat1.EditValue == null)
  138. {
  139. dxErrorProvider.SetError(txtAdjaSat1, "请选择邻星1");
  140. return;
  141. }
  142. if (txtAdjaSat2.EditValue == null)
  143. {
  144. dxErrorProvider.SetError(txtAdjaSat2, "请选择邻星2");
  145. return;
  146. }
  147. }
  148. if (txtTx.EditValue == null)
  149. {
  150. dxErrorProvider.SetError(txtTx, "请选择天线");
  151. return;
  152. }
  153. if (txtRefStation.EditValue == null)
  154. {
  155. dxErrorProvider.SetError(txtRefStation, "请选择参考站");
  156. return;
  157. }
  158. if (txtFreqUp.EditValue == null)
  159. {
  160. dxErrorProvider.SetError(txtFreqUp, "请填写频点");
  161. return;
  162. }
  163. if (txtBand.EditValue == null)
  164. {
  165. dxErrorProvider.SetError(txtBand, "请填写带宽");
  166. return;
  167. }
  168. if (txtSpeed.EditValue == null)
  169. {
  170. dxErrorProvider.SetError(txtSpeed, "请填写速度");
  171. return;
  172. }
  173. info.TaskState = EnumTaskState.Stopped;
  174. info.TaskName = txtTaskName.Text;
  175. info.SimulationType = (EnumSimulationType)radioSimulationType.SelectedIndex;
  176. info.MainSat = ((SatInfo)txtMainSat.EditValue).SatCode;
  177. if (txtAdjaSat1.EditValue != null)
  178. info.Adja1Sat = ((SatInfo)txtAdjaSat1.EditValue).SatCode;
  179. if (txtAdjaSat2.EditValue != null)
  180. info.Adja2Sat = ((SatInfo)txtAdjaSat2.EditValue).SatCode;
  181. info.AntID = Convert.ToInt64(txtTx.EditValue);
  182. info.RefID = Convert.ToInt64(txtRefStation.EditValue);
  183. info.Freq = (long)(Convert.ToDouble(txtFreqUp.EditValue) * 1e6);
  184. info.Band = (long)(Convert.ToDouble(txtBand.EditValue) * 1e6);
  185. info.Speed = Convert.ToInt64(txtSpeed.EditValue);
  186. info.isHistory = false;
  187. this.DialogResult = DialogResult.OK;
  188. }
  189. catch (Exception ex)
  190. {
  191. Serilog.Log.Error(ex, "编辑任务信息出错");
  192. DxHelper.MsgBoxHelper.ShowError("编辑任务信息出错");
  193. }
  194. }
  195. private void btnSave_Click(object sender, EventArgs e)
  196. {
  197. validation();
  198. }
  199. private void btnSaveOther_Click(object sender, EventArgs e)
  200. {
  201. validation();
  202. }
  203. }
  204. }