TaskEditor.cs 9.1 KB

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