TaskEditor.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. using DevExpress.Utils.About;
  2. using DevExpress.Utils.Extensions;
  3. using DevExpress.XtraBars.Customization;
  4. using DevExpress.XtraEditors;
  5. using DevExpress.XtraEditors.Controls;
  6. using DevExpress.XtraEditors.DXErrorProvider;
  7. using DPP_YH_Core.Extensions;
  8. using DxHelper;
  9. using ExtensionsDev;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.ComponentModel.DataAnnotations;
  14. using System.Data;
  15. using System.Data.Entity;
  16. using System.Drawing;
  17. using System.Linq;
  18. using System.Reflection;
  19. using System.Runtime.InteropServices;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. using System.Windows.Documents;
  23. using System.Windows.Forms;
  24. using XdCxRhDW.Dto;
  25. using XdCxRhDW.Entity;
  26. using XdCxRhDW.Repostory;
  27. namespace XdCxRhDW.App.EditForms
  28. {
  29. public partial class TaskEditor : DevExpress.XtraEditors.XtraForm
  30. {
  31. public TaskInfo info;
  32. public List<EnumDetectionWay> taskDetectionWayList;
  33. public TaskEditor()
  34. {
  35. InitializeComponent();
  36. this.layoutControl1.UseDefault();
  37. this.Text = "添加任务";
  38. info = new TaskInfo();
  39. this.StartPosition = FormStartPosition.CenterParent;
  40. //加载DW类型
  41. var values = Enum.GetValues(typeof(EnumPosType));
  42. foreach (var item in values)
  43. {
  44. this.txtPosType.Properties.Items.Add(new RadioGroupItem(Convert.ToInt32(item), ((EnumPosType)item).GetEnumDisplayName()));
  45. }
  46. values = Enum.GetValues(typeof(EnumTaskType));
  47. foreach (var item in values)
  48. {
  49. this.txtTaskType.Properties.Items.Add(new RadioGroupItem(Convert.ToInt32(item), ((EnumTaskType)item).GetEnumDisplayName()));
  50. }
  51. this.txtTaskType.SelectedIndex = 0;
  52. this.txtTaskType_SelectedIndexChanged(this, EventArgs.Empty);
  53. }
  54. public TaskEditor(TaskInfo info,List<EnumDetectionWay> taskDetectionWayList)
  55. : this()
  56. {
  57. this.Text = "编辑任务";
  58. this.info = info;
  59. this.taskDetectionWayList = taskDetectionWayList;
  60. }
  61. private async void TaskEditor_Load(object sender, EventArgs e)
  62. {
  63. using (RHDWContext db = new RHDWContext())
  64. {
  65. var sats = await db.SatInfos.ToListAsync();
  66. this.txtMainSat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  67. this.txtAdja1Sat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  68. this.txtAdja2Sat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  69. }
  70. if (this.Text == "编辑任务" && info != null)
  71. {
  72. using (RHDWContext db = new RHDWContext())
  73. {
  74. var satMain = await db.SatInfos.Where(w => w.SatCode == info.MainSat).FirstOrDefaultAsync();
  75. var satAdja1 = await db.SatInfos.Where(w => w.SatCode == info.Adja1Sat).FirstOrDefaultAsync();
  76. var satAdja2 = await db.SatInfos.Where(w => w.SatCode == info.Adja2Sat).FirstOrDefaultAsync();
  77. this.txtTaskName.Text = info.TaskName;
  78. this.txtPosType.SelectedIndex = (int)info.PosType;
  79. this.txtTaskType.SelectedIndex = (int)info.TaskType;
  80. this.txtSignalType.EditValue = info.SigType;
  81. this.txtDetectionWay.EditValue = string.Join(",", taskDetectionWayList);
  82. this.txtDetectionWay.RefreshEditValue();
  83. this.txtMainSat.EditValue = satMain;
  84. this.txtAdja1Sat.EditValue = satAdja1;
  85. this.txtAdja2Sat.EditValue = satAdja2;
  86. this.txtFreq.EditValue = info.Freq * (decimal)1e-6;
  87. txtCapDir.Text = info.CapDir;
  88. txtCapDirFormat.Text = info.CapDirFormat;
  89. txtDoFreqUp.Text = info.HistoryFrequpMHz;
  90. }
  91. }
  92. }
  93. private void btnSave_Click(object sender, EventArgs e)
  94. {
  95. try
  96. {
  97. dxErrorProvider.ClearErrors();
  98. if (txtTaskName.EditValue == null)
  99. {
  100. dxErrorProvider.SetError(txtTaskName, "请填写任务名");
  101. return;
  102. }
  103. if (txtSignalType.EditValue == null)
  104. {
  105. dxErrorProvider.SetError(txtSignalType, "请选择信号类型");
  106. return;
  107. }
  108. if ((EnumSigType)txtSignalType.EditValue == EnumSigType.SX)
  109. {
  110. if (txtDetectionWay.EditValue == null)
  111. {
  112. dxErrorProvider.SetError(txtDetectionWay, "请选择检测方式");
  113. return;
  114. }
  115. }
  116. if (this.Text == "添加任务")
  117. {
  118. using (RHDWContext db = new RHDWContext())
  119. {
  120. if (db.TaskInfos.Any(p => p.TaskName == txtTaskName.Text))
  121. {
  122. dxErrorProvider.SetError(txtTaskName, "任务名称重复");
  123. return;
  124. }
  125. }
  126. }
  127. else
  128. {
  129. using (RHDWContext db = new RHDWContext())
  130. {
  131. if (db.TaskInfos.Any(p => p.ID != info.ID && p.TaskName == txtTaskName.Text))
  132. {
  133. dxErrorProvider.SetError(txtTaskName, "任务名称重复");
  134. return;
  135. }
  136. }
  137. }
  138. var posType = (EnumPosType)txtPosType.Properties.Items[txtPosType.SelectedIndex].Value;
  139. if (posType == EnumPosType.X1D1CX)
  140. {
  141. if (txtMainSat.EditValue == null)
  142. {
  143. dxErrorProvider.SetError(txtMainSat, "请选择卫星");
  144. return;
  145. }
  146. }
  147. else if (posType == EnumPosType.X2D1 || posType == EnumPosType.RH || posType == EnumPosType.X2Dfo)
  148. {
  149. if (txtMainSat.EditValue == null)
  150. {
  151. dxErrorProvider.SetError(txtMainSat, "请选择主星");
  152. return;
  153. }
  154. if (txtAdja1Sat.EditValue == null)
  155. {
  156. dxErrorProvider.SetError(txtAdja1Sat, "请选择邻星");
  157. return;
  158. }
  159. }
  160. else if (posType == EnumPosType.X3TwoDto || posType == EnumPosType.X3TwoDfo)
  161. {
  162. if (txtMainSat.EditValue == null)
  163. {
  164. dxErrorProvider.SetError(txtMainSat, "请选择主星");
  165. return;
  166. }
  167. if (txtAdja1Sat.EditValue == null)
  168. {
  169. dxErrorProvider.SetError(txtAdja1Sat, "请选择邻星1");
  170. return;
  171. }
  172. if (txtAdja2Sat.EditValue == null)
  173. {
  174. dxErrorProvider.SetError(txtAdja2Sat, "请选择邻星2");
  175. return;
  176. }
  177. }
  178. if (txtTaskType.SelectedIndex == 0)
  179. {
  180. if (txtFreq.EditValue == null)
  181. {
  182. dxErrorProvider.SetError(txtFreq, "请填写频点");
  183. return;
  184. }
  185. }
  186. else
  187. {
  188. if (string.IsNullOrWhiteSpace(txtCapDir.Text))
  189. {
  190. dxErrorProvider.SetError(txtCapDir, "请填写采集文件目录");
  191. return;
  192. }
  193. if (string.IsNullOrWhiteSpace(txtCapDirFormat.Text))
  194. {
  195. dxErrorProvider.SetError(txtCapDirFormat, "请填写目录日期格式");
  196. return;
  197. }
  198. if (string.IsNullOrWhiteSpace(txtDoFreqUp.Text))
  199. {
  200. dxErrorProvider.SetError(txtDoFreqUp, "请填写要处理的频点");
  201. return;
  202. }
  203. try
  204. {
  205. var str = txtDoFreqUp.Text.Replace(",", ",").Replace(";", ",").Replace(";", ",").Trim();
  206. var freqs = str.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  207. List<double> list = new List<double>();
  208. foreach (var item in freqs)
  209. {
  210. double.TryParse(item, out double freqUpMHz);
  211. list.Add(freqUpMHz);
  212. }
  213. txtDoFreqUp.Text = string.Join(",", list.Select(p => p.ToString("f3")));
  214. }
  215. catch
  216. {
  217. dxErrorProvider.SetError(txtDoFreqUp, "处理频点格式错误!");
  218. return;
  219. }
  220. }
  221. info.TaskState = EnumTaskState.Stopped;
  222. info.TaskName = txtTaskName.Text;
  223. info.PosType = (EnumPosType)txtPosType.SelectedIndex;
  224. info.MainSat = ((SatInfo)txtMainSat.EditValue).SatCode;
  225. if (txtAdja1Sat.EditValue != null)
  226. info.Adja1Sat = ((SatInfo)txtAdja1Sat.EditValue).SatCode;
  227. if (txtAdja2Sat.EditValue != null)
  228. info.Adja2Sat = ((SatInfo)txtAdja2Sat.EditValue).SatCode;
  229. info.SigType = (EnumSigType)txtSignalType.EditValue;
  230. if (info.SigType == EnumSigType.SX)
  231. {
  232. taskDetectionWayList = new List<EnumDetectionWay>();
  233. var res = txtDetectionWay.EditValue.ToString().Split(new string[] { ","}, System.StringSplitOptions.RemoveEmptyEntries).ToList();
  234. foreach (var s in res)
  235. {
  236. taskDetectionWayList.Add((EnumDetectionWay)Enum.Parse(typeof(EnumDetectionWay), s));
  237. }
  238. }
  239. else
  240. {
  241. taskDetectionWayList = null;
  242. }
  243. info.TaskType = (EnumTaskType)txtTaskType.SelectedIndex;
  244. if (info.TaskType == EnumTaskType.Real)
  245. {
  246. info.Freq = (long)(Math.Round(Convert.ToDouble(txtFreq.EditValue),3) * 1e6);
  247. info.CapDir = null;
  248. info.CapDirFormat = null;
  249. info.HistoryFrequpMHz = null;
  250. }
  251. else
  252. {
  253. info.Freq = 0;
  254. info.CapDir = txtCapDir.Text.Trim();
  255. info.CapDirFormat= txtCapDirFormat.Text.Trim();
  256. info.HistoryFrequpMHz = txtDoFreqUp.Text.Replace(",", ",").Replace(";", ",").Replace(";", ",").Trim();
  257. }
  258. this.DialogResult = DialogResult.OK;
  259. }
  260. catch (Exception ex)
  261. {
  262. Serilog.Log.Error(ex, "编辑任务信息出错");
  263. DxHelper.MsgBoxHelper.ShowError("编辑任务信息出错");
  264. }
  265. }
  266. private void txtPosType_EditValueChanged(object sender, EventArgs e)
  267. {
  268. RadioGroup posTypeRadioGroup = sender as RadioGroup;
  269. var posType = (EnumPosType)posTypeRadioGroup.Properties.Items[posTypeRadioGroup.SelectedIndex].Value;
  270. //var description = (EnumPosType)posType.Properties.Items[posType.SelectedIndex].Description;
  271. if (posType == EnumPosType.X1D1CX)
  272. {
  273. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  274. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  275. }
  276. else if (posType == EnumPosType.X2D1)
  277. {
  278. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  279. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  280. this.layoutControlItemAdja1.Text = "邻星";
  281. }
  282. else if (posType == EnumPosType.RH)
  283. {
  284. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  285. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  286. this.layoutControlItemAdja1.Text = "邻星";
  287. }
  288. else if (posType == EnumPosType.X3TwoDto)
  289. {
  290. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  291. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  292. this.layoutControlItemAdja1.Text = "邻星1";
  293. }
  294. else if (posType == EnumPosType.X3TwoDfo)
  295. {
  296. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  297. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  298. this.layoutControlItemAdja1.Text = "邻星1";
  299. }
  300. else if (posType == EnumPosType.X2Dfo)
  301. {
  302. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  303. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  304. this.layoutControlItemAdja1.Text = "邻星";
  305. }
  306. else
  307. {
  308. return;
  309. }
  310. }
  311. private void txtTaskType_SelectedIndexChanged(object sender, EventArgs e)
  312. {
  313. //加载信号类型
  314. txtSignalType.Properties.Items.Clear();
  315. txtSignalType.Properties.Items.Add(new ImageComboBoxItem("请选择", null, -1));
  316. txtSignalType.Properties.Items.AddEnum<EnumSigType>();
  317. if (txtTaskType.SelectedIndex == 0)
  318. {
  319. itemFreqUp.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  320. itemCapDir.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  321. itemCapDirFormat.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  322. itemDoFreqUp.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  323. }
  324. else
  325. {
  326. itemFreqUp.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  327. itemCapDir.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  328. itemCapDirFormat.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  329. itemDoFreqUp.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  330. var normal=txtSignalType.Properties.Items.FirstOrDefault(f =>f.Description.Contains("常规"));
  331. txtSignalType.Properties.Items.Remove(normal);
  332. }
  333. }
  334. private void txtSignalType_SelectedIndexChanged(object sender, EventArgs e)
  335. {
  336. if (txtSignalType.SelectedIndex == 0) return;//请选择项不处理
  337. var selectedEnum = (EnumSigType)Enum.Parse(typeof(EnumSigType), txtSignalType.EditValue.ToString());
  338. if (selectedEnum == EnumSigType.SX)
  339. {
  340. txtDetectionWay.Properties.Items.AddEnum<EnumDetectionWay>();
  341. itemDetectionWay.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  342. }
  343. else {
  344. itemDetectionWay.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  345. }
  346. }
  347. private void txtDetectionWay_CustomDisplayText(object sender, CustomDisplayTextEventArgs e)
  348. {
  349. if (e.Value == null) return;
  350. if (e.Value.ToString() == EnumDetectionWay.ISignal.ToString())
  351. {
  352. e.DisplayText = $"{(long)e.Value / 1e6}MHz";
  353. }
  354. }
  355. }
  356. }