TaskEditor.cs 10 KB

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