TaskEditor.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. }
  183. else if (posType == EnumPosType.X3TwoDto || posType == EnumPosType.X3TwoDfo)
  184. {
  185. if (txtMainSat.EditValue == null)
  186. {
  187. dxErrorProvider.SetError(txtMainSat, "请选择主星");
  188. return;
  189. }
  190. if (txtAdja1Sat.EditValue == null)
  191. {
  192. dxErrorProvider.SetError(txtAdja1Sat, "请选择邻星1");
  193. return;
  194. }
  195. if (txtAdja2Sat.EditValue == null)
  196. {
  197. dxErrorProvider.SetError(txtAdja2Sat, "请选择邻星2");
  198. return;
  199. }
  200. }
  201. if (txtTaskType.SelectedIndex == 0)
  202. {
  203. if (txtFreq.EditValue == null)
  204. {
  205. dxErrorProvider.SetError(txtFreq, "请填写频点");
  206. return;
  207. }
  208. }
  209. else
  210. {
  211. if (string.IsNullOrWhiteSpace(txtCapDir.Text))
  212. {
  213. dxErrorProvider.SetError(txtCapDir, "请填写采集文件目录");
  214. return;
  215. }
  216. try
  217. {
  218. var str = txtDoFreqUp.Text.Replace(",", ",").Replace(";", ",").Replace(";", ",").Trim();
  219. var freqs = str.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  220. List<double> list = new List<double>();
  221. foreach (var item in freqs)
  222. {
  223. double.TryParse(item, out double freqUpMHz);
  224. list.Add(freqUpMHz);
  225. }
  226. txtDoFreqUp.Text = string.Join(",", list.Select(p => p.ToString("f3")));
  227. }
  228. catch
  229. {
  230. dxErrorProvider.SetError(txtDoFreqUp, "处理频点格式错误!");
  231. return;
  232. }
  233. }
  234. info.TaskState = EnumTaskState.Stopped;
  235. info.TaskName = txtTaskName.Text;
  236. info.PosType = (EnumPosType)txtPosType.SelectedIndex;
  237. info.MainSat = ((SatInfo)txtMainSat.EditValue).SatCode;
  238. if (txtAdja1Sat.EditValue != null)
  239. info.Adja1Sat = ((SatInfo)txtAdja1Sat.EditValue).SatCode;
  240. if (txtAdja2Sat.EditValue != null)
  241. info.Adja2Sat = ((SatInfo)txtAdja2Sat.EditValue).SatCode;
  242. info.SigType = (EnumSigType)txtSignalType.EditValue;
  243. if (info.SigType == EnumSigType.SX)
  244. {
  245. var res = txtDetectionWay.EditValue.ToString().Split(new string[] { "," }, System.StringSplitOptions.RemoveEmptyEntries).ToList();
  246. if (res.Count() == 2)
  247. {
  248. info.DetectionWay = (EnumTaskCheckType)Enum.Parse(typeof(EnumTaskCheckType), res[0]) | (EnumTaskCheckType)Enum.Parse(typeof(EnumTaskCheckType), res[1]);
  249. }
  250. else if (res.Count() == 3)
  251. {
  252. info.DetectionWay = (EnumTaskCheckType)Enum.Parse(typeof(EnumTaskCheckType), res[0]) | (EnumTaskCheckType)Enum.Parse(typeof(EnumTaskCheckType), res[1]) | (EnumTaskCheckType)Enum.Parse(typeof(EnumTaskCheckType), res[2]);
  253. }
  254. else
  255. {
  256. info.DetectionWay = (EnumTaskCheckType)Enum.Parse(typeof(EnumTaskCheckType), res[0]);
  257. }
  258. }
  259. else
  260. {
  261. info.DetectionWay = null;
  262. }
  263. //string strResult = info.DetectionWay.ToString() + " " + ((int)info.DetectionWay);
  264. info.TaskType = (EnumTaskType)txtTaskType.SelectedIndex;
  265. if (info.TaskType == EnumTaskType.Real)
  266. {
  267. info.Freq = (long)(Math.Round(Convert.ToDouble(txtFreq.EditValue), 3) * 1e6);
  268. info.CapDir = null;
  269. info.CapDirFormat = null;
  270. info.HistoryFrequpMHz = null;
  271. }
  272. else
  273. {
  274. info.Freq = 0;
  275. info.CapDir = txtCapDir.Text.Trim();
  276. info.CapDirFormat = txtCapDirFormat.Text.Trim();
  277. info.HistoryFrequpMHz = txtDoFreqUp.Text.Replace(",", ",").Replace(";", ",").Replace(";", ",").Trim();
  278. }
  279. this.DialogResult = DialogResult.OK;
  280. }
  281. catch (Exception ex)
  282. {
  283. Serilog.Log.Error(ex, "编辑任务信息出错");
  284. DxHelper.MsgBoxHelper.ShowError("编辑任务信息出错");
  285. }
  286. }
  287. private void txtPosType_EditValueChanged(object sender, EventArgs e)
  288. {
  289. RadioGroup posTypeRadioGroup = sender as RadioGroup;
  290. var posType = (EnumPosType)posTypeRadioGroup.Properties.Items[posTypeRadioGroup.SelectedIndex].Value;
  291. if (posType == EnumPosType.X1D1CX)
  292. {
  293. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  294. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  295. }
  296. else if (posType == EnumPosType.X2D1)
  297. {
  298. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  299. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  300. this.layoutControlItemAdja1.Text = "邻星";
  301. }
  302. else if (posType == EnumPosType.RH)
  303. {
  304. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  305. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  306. this.layoutControlItemAdja1.Text = "邻星";
  307. }
  308. else if (posType == EnumPosType.X3TwoDto)
  309. {
  310. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  311. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  312. this.layoutControlItemAdja1.Text = "邻星1";
  313. }
  314. else if (posType == EnumPosType.X3TwoDfo)
  315. {
  316. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  317. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  318. this.layoutControlItemAdja1.Text = "邻星1";
  319. }
  320. else if (posType == EnumPosType.X2Dfo)
  321. {
  322. layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  323. layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  324. this.layoutControlItemAdja1.Text = "邻星";
  325. }
  326. this.layoutControl1.BestFit();
  327. }
  328. private void txtTaskType_SelectedIndexChanged(object sender, EventArgs e)
  329. {
  330. //加载信号类型
  331. txtSignalType.Properties.Items.Clear();
  332. txtSignalType.Properties.Items.Add(new ImageComboBoxItem("请选择", null, -1));
  333. txtSignalType.Properties.Items.AddEnum<EnumSigType>();
  334. if (txtTaskType.SelectedIndex == 0)
  335. {
  336. itemFreqUp.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  337. itemCapDir.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  338. itemCapDirFormat.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  339. itemDoFreqUp.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  340. this.Height -= 55;
  341. }
  342. else
  343. {
  344. itemFreqUp.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  345. itemCapDir.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  346. itemCapDirFormat.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  347. itemDoFreqUp.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  348. var normal = txtSignalType.Properties.Items.FirstOrDefault(f => f.Description.Contains("常规"));
  349. //txtSignalType.Properties.Items.Remove(normal);//不要移除了
  350. this.Height += 55;
  351. }
  352. this.layoutControl1.BestFit();
  353. }
  354. private void txtSignalType_SelectedIndexChanged(object sender, EventArgs e)
  355. {
  356. if (txtSignalType.SelectedIndex == 0)
  357. {
  358. itemDetectionWay.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  359. }
  360. else
  361. {
  362. var selectedEnum = (EnumSigType)Enum.Parse(typeof(EnumSigType), txtSignalType.EditValue.ToString());
  363. if (selectedEnum == EnumSigType.SX)
  364. {
  365. txtDetectionWay.Properties.Items.Clear();
  366. txtDetectionWay.Properties.Items.AddEnum<EnumTaskCheckType>();
  367. itemDetectionWay.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  368. }
  369. else
  370. {
  371. itemDetectionWay.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  372. }
  373. }
  374. this.layoutControl1.BestFit();
  375. }
  376. }
  377. }