TaskEditor.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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.Properties.DataSource = hjList;
  75. this.txtHj.Properties.ValueMember = nameof(SimulationInfo);
  76. // this.txtHj.Properties.KeyMember = nameof(SimulationInfo.CreateTime);
  77. this.txtHj.Properties.DisplayMember = nameof(SimulationInfo.SimulationName);
  78. this.txtHj.SetSearchGridLookUpEditMultiSelected<SimulationInfo>();
  79. using (SimulationContext db = new SimulationContext())
  80. {
  81. var sats = await db.SatInfos.ToListAsync();
  82. this.txtMainSat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  83. this.txtAdjaSat1.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  84. this.txtAdjaSat2.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  85. var ants = await db.AntInfos.ToListAsync();
  86. foreach (var item in ants)
  87. {
  88. this.txtTx.Properties.Items.Add(new ImageComboBoxItem(item.AntName, item.ID));
  89. }
  90. var refs = await db.RefInfos.ToListAsync();
  91. foreach (var item in refs)
  92. {
  93. this.txtRefStation.Properties.Items.Add(new ImageComboBoxItem(item.RefName, item.ID));
  94. }
  95. }
  96. if (this.Text == "编辑任务" && info != null)
  97. {
  98. using (SimulationContext db = new SimulationContext())
  99. {
  100. var satMain = await db.SatInfos.Where(w => w.SatCode == info.MainSat).FirstOrDefaultAsync();
  101. var satAdja1 = await db.SatInfos.Where(w => w.SatCode == info.Adja1Sat).FirstOrDefaultAsync();
  102. var satAdja2 = await db.SatInfos.Where(w => w.SatCode == info.Adja2Sat).FirstOrDefaultAsync();
  103. this.txtTaskName.Text = info.TaskName;
  104. this.radioSimulationType.SelectedIndex = (int)info.SimulationType;
  105. this.txtMainSat.EditValue = satMain;
  106. this.txtAdjaSat1.EditValue = satAdja1;
  107. this.txtAdjaSat2.EditValue = satAdja2;
  108. this.txtTx.EditValue = info.AntID;
  109. this.txtRefStation.EditValue = info.RefID;
  110. this.txtFreqUp.EditValue = info.Freq * (decimal)1e-6;
  111. this.txtBand.EditValue = info.Band * (decimal)1e-6;
  112. this.txtSpeed.EditValue = info.Speed;
  113. }
  114. }
  115. }
  116. /// <summary>
  117. /// 验证信息
  118. /// </summary>
  119. private void validation()
  120. {
  121. try
  122. {
  123. dxErrorProvider.ClearErrors();
  124. if (txtTaskName.EditValue == null)
  125. {
  126. dxErrorProvider.SetError(txtTaskName, "请填写任务名");
  127. return;
  128. }
  129. if (radioSimulationType.SelectedIndex == -1)
  130. {
  131. dxErrorProvider.SetError(radioSimulationType, "请选择仿真类型");
  132. return;
  133. }
  134. var posType = (EnumSimulationType)radioSimulationType.Properties.Items[radioSimulationType.SelectedIndex].Value;
  135. if (posType == EnumSimulationType.X3TwoDto)
  136. {
  137. if (txtMainSat.EditValue == null)
  138. {
  139. dxErrorProvider.SetError(txtMainSat, "请选择主星");
  140. return;
  141. }
  142. if (txtAdjaSat1.EditValue == null)
  143. {
  144. dxErrorProvider.SetError(txtAdjaSat1, "请选择邻星1");
  145. return;
  146. }
  147. if (txtAdjaSat2.EditValue == null)
  148. {
  149. dxErrorProvider.SetError(txtAdjaSat2, "请选择邻星2");
  150. return;
  151. }
  152. }
  153. if (txtTx.EditValue == null)
  154. {
  155. dxErrorProvider.SetError(txtTx, "请选择天线");
  156. return;
  157. }
  158. if (txtRefStation.EditValue == null)
  159. {
  160. dxErrorProvider.SetError(txtRefStation, "请选择参考站");
  161. return;
  162. }
  163. if (txtFreqUp.EditValue == null)
  164. {
  165. dxErrorProvider.SetError(txtFreqUp, "请填写频点");
  166. return;
  167. }
  168. if (txtBand.EditValue == null)
  169. {
  170. dxErrorProvider.SetError(txtBand, "请填写带宽");
  171. return;
  172. }
  173. if (txtSpeed.EditValue == null)
  174. {
  175. dxErrorProvider.SetError(txtSpeed, "请填写速度");
  176. return;
  177. }
  178. info.TaskState = EnumTaskState.Stopped;
  179. info.TaskName = txtTaskName.Text;
  180. info.SimulationType = (EnumSimulationType)radioSimulationType.SelectedIndex;
  181. info.MainSat = ((SatInfo)txtMainSat.EditValue).SatCode;
  182. if (txtAdjaSat1.EditValue != null)
  183. info.Adja1Sat = ((SatInfo)txtAdjaSat1.EditValue).SatCode;
  184. if (txtAdjaSat2.EditValue != null)
  185. info.Adja2Sat = ((SatInfo)txtAdjaSat2.EditValue).SatCode;
  186. info.AntID = Convert.ToInt64(txtTx.EditValue);
  187. info.RefID = Convert.ToInt64(txtRefStation.EditValue);
  188. info.Freq = (long)(Convert.ToDouble(txtFreqUp.EditValue) * 1e6);
  189. info.Band = (long)(Convert.ToDouble(txtBand.EditValue) * 1e6);
  190. info.Speed = Convert.ToInt64(txtSpeed.EditValue);
  191. info.isHistory = false;
  192. this.DialogResult = DialogResult.OK;
  193. }
  194. catch (Exception ex)
  195. {
  196. Serilog.Log.Error(ex, "编辑任务信息出错");
  197. DxHelper.MsgBoxHelper.ShowError("编辑任务信息出错");
  198. }
  199. }
  200. private void btnSave_Click(object sender, EventArgs e)
  201. {
  202. validation();
  203. }
  204. private void btnSaveOther_Click(object sender, EventArgs e)
  205. {
  206. validation();
  207. }
  208. private void txtHj_EditValueChanged(object sender, EventArgs e)
  209. {
  210. var selectedValue = txtHj.Properties.Tag.MapTo<List<SimulationInfo>>();
  211. if (selectedValue != null)
  212. {
  213. List<FlightInfo> flightInfos = new List<FlightInfo>();
  214. foreach (var item in selectedValue)
  215. {
  216. var simulationPonitInfo = SimulationCache.GetAllByIDAsync(item.ID, item.CreateTime).Result;
  217. var flinfo = new FlightInfo(item.SimulationName, item.SimulationSpeed);
  218. var fpoinits = simulationPonitInfo.Select(s => new FlightData(s.SimulationLon, s.SimulationLat));
  219. flinfo.flights.AddRange(fpoinits);
  220. flightInfos.Add(flinfo);
  221. }
  222. mapControl.SetFlightLine(flightInfos);
  223. }
  224. }
  225. }
  226. }