TaskEditor.cs 9.8 KB

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