TaskEditor.cs 18 KB

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