TaskEditor.cs 18 KB

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