TaskEditor.cs 18 KB

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