TaskEditor.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. using DevExpress.Utils.About;
  2. using DevExpress.XtraEditors;
  3. using DevExpress.XtraEditors.Controls;
  4. using DxHelper;
  5. using ExtensionsDev;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.ComponentModel.DataAnnotations;
  10. using System.Data;
  11. using System.Data.Entity;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Reflection;
  15. using System.Runtime.InteropServices;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using System.Windows.Documents;
  19. using System.Windows.Forms;
  20. using XdCxRhDW.Repostory.EFContext;
  21. using XdCxRhDW.Repostory.Model;
  22. namespace XdCxRhDW.App.EditForms
  23. {
  24. public partial class TaskEditor : DevExpress.XtraEditors.XtraForm
  25. {
  26. public TaskInfo info;
  27. public TaskEditor()
  28. {
  29. InitializeComponent();
  30. this.Text = "添加任务";
  31. info = new TaskInfo();
  32. this.StartPosition = FormStartPosition.CenterParent;
  33. //加载DW类型
  34. List<RadioGroupItem> radioGroups = new List<RadioGroupItem>();
  35. var values = Enum.GetValues(typeof(EnumPosType));
  36. foreach (var item in values)
  37. {
  38. radioGroups.Add(new RadioGroupItem(Convert.ToInt32(item), ((EnumPosType)item).GetEnumDisplayName()));
  39. }
  40. this.txtPosType.Properties.Items.AddRange(radioGroups.ToArray());
  41. }
  42. public TaskEditor(TaskInfo info)
  43. : this()
  44. {
  45. this.Text = "编辑任务";
  46. this.info = info;
  47. }
  48. private async void TaskEditor_Load(object sender, EventArgs e)
  49. {
  50. using (RHDWContext db = new RHDWContext())
  51. {
  52. var sats = await db.SatInfos.ToListAsync();
  53. this.txtMainSat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  54. this.txtAdja1Sat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  55. this.txtAdja2Sat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  56. }
  57. if (this.Text == "编辑任务" && info != null)
  58. {
  59. using (RHDWContext db = new RHDWContext())
  60. {
  61. var satMain = await db.SatInfos.Where(w => w.SatCode == info.MainSat).FirstOrDefaultAsync();
  62. var satAdja1 = await db.SatInfos.Where(w => w.SatCode == info.Adja1Sat).FirstOrDefaultAsync();
  63. var satAdja2 = await db.SatInfos.Where(w => w.SatCode == info.Adja2Sat).FirstOrDefaultAsync();
  64. this.txtTaskName.Text = info.TaskName;
  65. this.txtPosType.SelectedIndex = (int)info.PosType;
  66. this.txtMainSat.EditValue = satMain;
  67. this.txtAdja1Sat.EditValue = satAdja1;
  68. this.txtAdja2Sat.EditValue = satAdja2;
  69. this.txtFreq.EditValue = info.Freq * 1e-6;
  70. this.txtBand.EditValue = info.Band * 1e-6;
  71. }
  72. }
  73. }
  74. private void btnSave_Click(object sender, EventArgs e)
  75. {
  76. try
  77. {
  78. if (txtTaskName.EditValue == null)
  79. {
  80. DxHelper.MsgBoxHelper.ShowError("请填写任务名");
  81. return;
  82. }
  83. if (txtPosType.SelectedIndex== -1)
  84. {
  85. DxHelper.MsgBoxHelper.ShowError("请选择定位类型");
  86. return;
  87. }
  88. var posType = (EnumPosType)txtPosType.Properties.Items[txtPosType.SelectedIndex].Value;
  89. if (posType == EnumPosType.X1D1CX)
  90. {
  91. if (txtMainSat.EditValue == null)
  92. {
  93. DxHelper.MsgBoxHelper.ShowError("请选择卫星");
  94. return;
  95. }
  96. }
  97. else if (posType == EnumPosType.X2D1|| posType == EnumPosType.RH|| posType == EnumPosType.X2Dfo)
  98. {
  99. if (txtMainSat.EditValue == null)
  100. {
  101. DxHelper.MsgBoxHelper.ShowError("请选择主星");
  102. return;
  103. }
  104. if (txtAdja1Sat.EditValue == null)
  105. {
  106. DxHelper.MsgBoxHelper.ShowError("请选择邻星");
  107. return;
  108. }
  109. }
  110. else if (posType == EnumPosType.X3TwoDto|| posType == EnumPosType.X3TwoDfo)
  111. {
  112. if (txtMainSat.EditValue == null)
  113. {
  114. DxHelper.MsgBoxHelper.ShowError("请选择主星");
  115. return;
  116. }
  117. if (txtAdja1Sat.EditValue == null)
  118. {
  119. DxHelper.MsgBoxHelper.ShowError("请选择邻星1");
  120. return;
  121. }
  122. if (txtAdja2Sat.EditValue == null)
  123. {
  124. DxHelper.MsgBoxHelper.ShowError("请选择邻星2");
  125. return;
  126. }
  127. }
  128. if (txtFreq.EditValue == null)
  129. {
  130. DxHelper.MsgBoxHelper.ShowError("请填写频点");
  131. return;
  132. }
  133. if (txtBand.EditValue == null)
  134. {
  135. DxHelper.MsgBoxHelper.ShowError("请填写带宽");
  136. return;
  137. }
  138. info.TaskState = EnumTaskState.Stopped;
  139. info.TaskName = txtTaskName.Text;
  140. info.PosType = (EnumPosType)txtPosType.SelectedIndex;
  141. info.MainSat = ((SatInfo)txtMainSat.EditValue).SatCode;
  142. if (txtAdja1Sat.EditValue != null)
  143. info.Adja1Sat = ((SatInfo)txtAdja1Sat.EditValue).SatCode;
  144. if (txtAdja2Sat.EditValue != null)
  145. info.Adja2Sat = ((SatInfo)txtAdja2Sat.EditValue).SatCode;
  146. info.Freq = (long)(Convert.ToDouble(txtFreq.EditValue) * 1e6);
  147. info.Band = (int)(Convert.ToDouble(txtBand.EditValue) * 1e6);
  148. this.DialogResult = DialogResult.OK;
  149. }
  150. catch (Exception ex)
  151. {
  152. Serilog.Log.Error(ex, "编辑任务信息出错");
  153. DxHelper.MsgBoxHelper.ShowError("编辑任务信息出错");
  154. }
  155. }
  156. private void txtPosType_EditValueChanged(object sender, EventArgs e)
  157. {
  158. RadioGroup posTypeRadioGroup = sender as RadioGroup;
  159. var posType = (EnumPosType)posTypeRadioGroup.Properties.Items[posTypeRadioGroup.SelectedIndex].Value;
  160. //var description = (EnumPosType)posType.Properties.Items[posType.SelectedIndex].Description;
  161. if (posType == EnumPosType.X1D1CX)
  162. {
  163. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  164. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  165. }
  166. else if (posType == EnumPosType.X2D1)
  167. {
  168. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  169. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  170. this.layoutControlItemAdja1.Text = "邻星";
  171. }
  172. else if (posType == EnumPosType.RH)
  173. {
  174. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  175. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  176. this.layoutControlItemAdja1.Text = "邻星";
  177. }
  178. else if (posType == EnumPosType.X3TwoDto)
  179. {
  180. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  181. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  182. this.layoutControlItemAdja1.Text = "邻星1";
  183. }
  184. else if (posType == EnumPosType.X3TwoDfo)
  185. {
  186. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  187. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  188. this.layoutControlItemAdja1.Text = "邻星1";
  189. }
  190. else if (posType == EnumPosType.X2Dfo)
  191. {
  192. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  193. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  194. this.layoutControlItemAdja1.Text = "邻星";
  195. }
  196. else
  197. {
  198. return;
  199. }
  200. }
  201. }
  202. }