TaskEditorSignal.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.XtraGrid;
  8. using DevExpress.XtraPrinting.Native;
  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.Drawing;
  17. using System.Linq;
  18. using System.Reflection;
  19. using System.Runtime.InteropServices;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. using System.Windows.Documents;
  23. using System.Windows.Forms;
  24. using DW5S.DTO;
  25. using DW5S.Entity;
  26. using DW5S.Repostory;
  27. using Microsoft.Extensions.Logging;
  28. using Serilog.Core;
  29. using Microsoft.EntityFrameworkCore;
  30. namespace DW5S.App.EditForms
  31. {
  32. public partial class TaskEditorSignal : DevExpress.XtraEditors.XtraForm
  33. {
  34. [Autowired]
  35. private readonly ILogger logger;
  36. [Autowired]
  37. private readonly UnitOfWork unitOfWork;
  38. public TaskInfo info;
  39. public List<SigInfo> listSigInfo = new List<SigInfo>();
  40. public List<SigInfo> listSigInfoSelected = new List<SigInfo>();
  41. public TaskEditorSignal()
  42. {
  43. InitializeComponent();
  44. this.Text = "任务信号选择";
  45. info = new TaskInfo();
  46. this.StartPosition = FormStartPosition.CenterParent;
  47. }
  48. public TaskEditorSignal(TaskInfo info, List<SigInfo> listSigInfoSelected)
  49. : this()
  50. {
  51. this.Text = $"任务[{info.TaskName}]信号选择";
  52. this.info = info;
  53. this.listSigInfoSelected = listSigInfoSelected.Skip(0).ToList();
  54. }
  55. private async void TaskEditorSignal_Load(object sender, EventArgs e)
  56. {
  57. try
  58. {
  59. gridTaskSignal.UseDefault(listSigInfo).UseMultiSelect().UseRowNumber().DrawGridColumnHeaderCheckBox();
  60. var repsFixed= unitOfWork.Reps<FixedStation>();
  61. var fixedStations = await repsFixed.FindAsync(p => p.Enable);
  62. var repsSig = unitOfWork.Reps<SigInfo>();
  63. var items = await repsSig.GetAllAsync(p => p.FreqUp);
  64. listSigInfo.AddRange(items);
  65. foreach (var item in listSigInfo)
  66. {
  67. if (fixedStations.Any(p => p.FreqUpHz == item.FreqUp))
  68. item.IsFixedStationFreq = "✔";
  69. else
  70. item.IsFixedStationFreq = "✖";
  71. }
  72. foreach (var item in listSigInfoSelected)
  73. {
  74. var selectedIdx = listSigInfo.FindIndex(p => p.Id == item.Id);
  75. if (selectedIdx >= 0)
  76. this.gridViewTaskSignal.SelectRow(selectedIdx);
  77. }
  78. gridViewTaskSignal.BestFitColumns();
  79. }
  80. catch (Exception ex)
  81. {
  82. var msg = "查询信号信息异常";
  83. logger.LogError(ex, msg);
  84. DxHelper.MsgBoxHelper.ShowError(msg);
  85. }
  86. }
  87. private void btnCancle_Click(object sender, EventArgs e)
  88. {
  89. this.DialogResult = DialogResult.Cancel;
  90. }
  91. private void btnOk_Click(object sender, EventArgs e)
  92. {
  93. var selectedRows = gridViewTaskSignal.GetSelectedRows();
  94. listSigInfoSelected.Clear();
  95. for (int i = 0; i < selectedRows.Count(); i++)
  96. {
  97. var res = gridViewTaskSignal.GetRow(selectedRows[i]) as SigInfo;
  98. listSigInfoSelected.Add(res);
  99. }
  100. int count = listSigInfoSelected.Count(s => s.IsFixedStationFreq.Trim() == "✔".Trim());
  101. if (count >= 2)
  102. {
  103. DxHelper.MsgBoxHelper.ShowError("只支持一个固定站频点");
  104. return;
  105. }
  106. this.DialogResult = DialogResult.OK;
  107. }
  108. }
  109. }