TaskEditor.cs 7.9 KB

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