TaskEditor.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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 = "编辑任务";
  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 == "编辑任务" && 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. List<EnumDetectionWay> deWay = new List<EnumDetectionWay>();
  81. if (info.DetectionWay.Value.HasFlag(EnumDetectionWay.DAMA))
  82. {
  83. deWay.Add( EnumDetectionWay.DAMA);
  84. }
  85. if (info.DetectionWay.Value.HasFlag(EnumDetectionWay.IBS))
  86. {
  87. deWay.Add(EnumDetectionWay.IBS);
  88. }
  89. if (info.DetectionWay.Value.HasFlag(EnumDetectionWay.EnergyDetection))
  90. {
  91. deWay.Add(EnumDetectionWay.EnergyDetection);
  92. }
  93. this.txtDetectionWay.EditValue =string.Join(",", deWay);
  94. this.txtDetectionWay.RefreshEditValue();
  95. this.txtMainSat.EditValue = satMain;
  96. this.txtAdja1Sat.EditValue = satAdja1;
  97. this.txtAdja2Sat.EditValue = satAdja2;
  98. this.txtFreq.EditValue = info.Freq * (decimal)1e-6;
  99. txtCapDir.Text = info.CapDir;
  100. txtCapDirFormat.Text = info.CapDirFormat;
  101. txtDoFreqUp.Text = info.HistoryFrequpMHz;
  102. }
  103. }
  104. }
  105. private void btnSave_Click(object sender, EventArgs e)
  106. {
  107. try
  108. {
  109. dxErrorProvider.ClearErrors();
  110. if (txtTaskName.EditValue == null)
  111. {
  112. dxErrorProvider.SetError(txtTaskName, "请填写任务名");
  113. return;
  114. }
  115. if (txtSignalType.EditValue == null)
  116. {
  117. dxErrorProvider.SetError(txtSignalType, "请选择信号类型");
  118. return;
  119. }
  120. if ((EnumSigType)txtSignalType.EditValue == EnumSigType.SX)
  121. {
  122. if (txtDetectionWay.EditValue == null)
  123. {
  124. dxErrorProvider.SetError(txtDetectionWay, "请选择检测方式");
  125. return;
  126. }
  127. }
  128. if (this.Text == "添加任务")
  129. {
  130. using (RHDWContext db = new RHDWContext())
  131. {
  132. if (db.TaskInfos.Any(p => p.TaskName == txtTaskName.Text))
  133. {
  134. dxErrorProvider.SetError(txtTaskName, "任务名称重复");
  135. return;
  136. }
  137. }
  138. }
  139. else
  140. {
  141. using (RHDWContext db = new RHDWContext())
  142. {
  143. if (db.TaskInfos.Any(p => p.ID != info.ID && p.TaskName == txtTaskName.Text))
  144. {
  145. dxErrorProvider.SetError(txtTaskName, "任务名称重复");
  146. return;
  147. }
  148. }
  149. }
  150. var posType = (EnumPosType)txtPosType.Properties.Items[txtPosType.SelectedIndex].Value;
  151. if (posType == EnumPosType.X1D1CX)
  152. {
  153. if (txtMainSat.EditValue == null)
  154. {
  155. dxErrorProvider.SetError(txtMainSat, "请选择卫星");
  156. return;
  157. }
  158. }
  159. else if (posType == EnumPosType.X2D1 || posType == EnumPosType.RH || posType == EnumPosType.X2Dfo)
  160. {
  161. if (txtMainSat.EditValue == null)
  162. {
  163. dxErrorProvider.SetError(txtMainSat, "请选择主星");
  164. return;
  165. }
  166. if (txtAdja1Sat.EditValue == null)
  167. {
  168. dxErrorProvider.SetError(txtAdja1Sat, "请选择邻星");
  169. return;
  170. }
  171. }
  172. else if (posType == EnumPosType.X3TwoDto || posType == EnumPosType.X3TwoDfo)
  173. {
  174. if (txtMainSat.EditValue == null)
  175. {
  176. dxErrorProvider.SetError(txtMainSat, "请选择主星");
  177. return;
  178. }
  179. if (txtAdja1Sat.EditValue == null)
  180. {
  181. dxErrorProvider.SetError(txtAdja1Sat, "请选择邻星1");
  182. return;
  183. }
  184. if (txtAdja2Sat.EditValue == null)
  185. {
  186. dxErrorProvider.SetError(txtAdja2Sat, "请选择邻星2");
  187. return;
  188. }
  189. }
  190. if (txtTaskType.SelectedIndex == 0)
  191. {
  192. if (txtFreq.EditValue == null)
  193. {
  194. dxErrorProvider.SetError(txtFreq, "请填写频点");
  195. return;
  196. }
  197. }
  198. else
  199. {
  200. if (string.IsNullOrWhiteSpace(txtCapDir.Text))
  201. {
  202. dxErrorProvider.SetError(txtCapDir, "请填写采集文件目录");
  203. return;
  204. }
  205. if (string.IsNullOrWhiteSpace(txtCapDirFormat.Text))
  206. {
  207. dxErrorProvider.SetError(txtCapDirFormat, "请填写目录日期格式");
  208. return;
  209. }
  210. if (string.IsNullOrWhiteSpace(txtDoFreqUp.Text))
  211. {
  212. dxErrorProvider.SetError(txtDoFreqUp, "请填写要处理的频点");
  213. return;
  214. }
  215. try
  216. {
  217. var str = txtDoFreqUp.Text.Replace(",", ",").Replace(";", ",").Replace(";", ",").Trim();
  218. var freqs = str.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  219. List<double> list = new List<double>();
  220. foreach (var item in freqs)
  221. {
  222. double.TryParse(item, out double freqUpMHz);
  223. list.Add(freqUpMHz);
  224. }
  225. txtDoFreqUp.Text = string.Join(",", list.Select(p => p.ToString("f3")));
  226. }
  227. catch
  228. {
  229. dxErrorProvider.SetError(txtDoFreqUp, "处理频点格式错误!");
  230. return;
  231. }
  232. }
  233. info.TaskState = EnumTaskState.Stopped;
  234. info.TaskName = txtTaskName.Text;
  235. info.PosType = (EnumPosType)txtPosType.SelectedIndex;
  236. info.MainSat = ((SatInfo)txtMainSat.EditValue).SatCode;
  237. if (txtAdja1Sat.EditValue != null)
  238. info.Adja1Sat = ((SatInfo)txtAdja1Sat.EditValue).SatCode;
  239. if (txtAdja2Sat.EditValue != null)
  240. info.Adja2Sat = ((SatInfo)txtAdja2Sat.EditValue).SatCode;
  241. info.SigType = (EnumSigType)txtSignalType.EditValue;
  242. if (info.SigType == EnumSigType.SX)
  243. {
  244. var res = txtDetectionWay.EditValue.ToString().Split(new string[] { "," }, System.StringSplitOptions.RemoveEmptyEntries).ToList();
  245. if (res.Count() == 2)
  246. {
  247. info.DetectionWay = (EnumDetectionWay)Enum.Parse(typeof(EnumDetectionWay), res[0])| (EnumDetectionWay)Enum.Parse(typeof(EnumDetectionWay), res[1]);
  248. }
  249. else if (res.Count() == 3)
  250. {
  251. info.DetectionWay = (EnumDetectionWay)Enum.Parse(typeof(EnumDetectionWay), res[0])| (EnumDetectionWay)Enum.Parse(typeof(EnumDetectionWay), res[1])| (EnumDetectionWay)Enum.Parse(typeof(EnumDetectionWay), res[2]);
  252. }
  253. else
  254. {
  255. info.DetectionWay = (EnumDetectionWay)Enum.Parse(typeof(EnumDetectionWay), res[0]);
  256. }
  257. }
  258. else
  259. {
  260. info.DetectionWay = EnumDetectionWay.EnergyDetection;
  261. }
  262. //string strResult = info.DetectionWay.ToString() + " " + ((int)info.DetectionWay);
  263. info.TaskType = (EnumTaskType)txtTaskType.SelectedIndex;
  264. if (info.TaskType == EnumTaskType.Real)
  265. {
  266. info.Freq = (long)(Math.Round(Convert.ToDouble(txtFreq.EditValue),3) * 1e6);
  267. info.CapDir = null;
  268. info.CapDirFormat = null;
  269. info.HistoryFrequpMHz = null;
  270. }
  271. else
  272. {
  273. info.Freq = 0;
  274. info.CapDir = txtCapDir.Text.Trim();
  275. info.CapDirFormat= txtCapDirFormat.Text.Trim();
  276. info.HistoryFrequpMHz = txtDoFreqUp.Text.Replace(",", ",").Replace(";", ",").Replace(";", ",").Trim();
  277. }
  278. this.DialogResult = DialogResult.OK;
  279. }
  280. catch (Exception ex)
  281. {
  282. Serilog.Log.Error(ex, "编辑任务信息出错");
  283. DxHelper.MsgBoxHelper.ShowError("编辑任务信息出错");
  284. }
  285. }
  286. private void txtPosType_EditValueChanged(object sender, EventArgs e)
  287. {
  288. RadioGroup posTypeRadioGroup = sender as RadioGroup;
  289. var posType = (EnumPosType)posTypeRadioGroup.Properties.Items[posTypeRadioGroup.SelectedIndex].Value;
  290. //var description = (EnumPosType)posType.Properties.Items[posType.SelectedIndex].Description;
  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. else
  327. {
  328. return;
  329. }
  330. }
  331. private void txtTaskType_SelectedIndexChanged(object sender, EventArgs e)
  332. {
  333. //加载信号类型
  334. txtSignalType.Properties.Items.Clear();
  335. txtSignalType.Properties.Items.Add(new ImageComboBoxItem("请选择", null, -1));
  336. txtSignalType.Properties.Items.AddEnum<EnumSigType>();
  337. if (txtTaskType.SelectedIndex == 0)
  338. {
  339. itemFreqUp.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  340. itemCapDir.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  341. itemCapDirFormat.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  342. itemDoFreqUp.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  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. }
  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. return;
  360. }
  361. var selectedEnum = (EnumSigType)Enum.Parse(typeof(EnumSigType), txtSignalType.EditValue.ToString());
  362. if (selectedEnum == EnumSigType.SX)
  363. {
  364. txtDetectionWay.Properties.Items.Clear();
  365. txtDetectionWay.Properties.Items.AddEnum<EnumDetectionWay>();
  366. itemDetectionWay.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  367. }
  368. else {
  369. itemDetectionWay.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  370. }
  371. }
  372. }
  373. }