AdChannelEditor.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using DevExpress.Utils.About;
  2. using DW5S.Entity;
  3. using DW5S.Repostory;
  4. using DW5S.Service;
  5. using DW5S.ViewModel;
  6. using ExtensionsDev;
  7. using Serilog;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows.Forms;
  17. using XdCxRhDW5S.ViewModel;
  18. namespace DW5S.App.EditForms
  19. {
  20. public partial class AdChannelEditor : DevExpress.XtraEditors.XtraForm
  21. {
  22. public AdChannelViewModel info;
  23. private List<AdChannelViewModel> infos;
  24. public AdChannelEditor()
  25. {
  26. InitializeComponent();
  27. this.layoutControl1.UseDefault();
  28. this.Text = "添加采集通道";
  29. info = new AdChannelViewModel();
  30. infos = new List<AdChannelViewModel>();
  31. this.StartPosition = FormStartPosition.CenterParent;
  32. }
  33. public AdChannelEditor(AdChannelViewModel info, List<AdChannelViewModel> infos)
  34. : this()
  35. {
  36. this.Text = "编辑采集通道";
  37. this.info = info;
  38. this.infos = infos;
  39. }
  40. private async void CxEditor_Load(object sender, EventArgs e)
  41. {
  42. var unitOfWork = IocContainer.UnitOfWork;
  43. var sats = await unitOfWork.Of<SatInfo>().GetAllAsync();
  44. var satList = sats.To<List<SatViewModel>>();
  45. //启用的天线才可以选择
  46. var txs = await unitOfWork.Of<TxInfo>().GetAllAsync(m => m.Enable);
  47. var txList = txs.To<List<RecTxViewModel>>();
  48. this.txtSat.UseDefault().SetData(satList, displayField: nameof(SatViewModel.Sat)).UseDoubleClickToSelectAll();
  49. this.txtAnt.UseDefault().SetData(txList, displayField: nameof(RecTxViewModel.Name)).UseDoubleClickToSelectAll();
  50. if (this.Text == "编辑采集通道" && info != null)
  51. {
  52. var sat = satList.FirstOrDefault(s => s.Id == info.SatInfoID);
  53. var ant = txList.FirstOrDefault(a => a.Id == info.TxInfoID);
  54. this.txtChannel.EditValue = info.ChNum;
  55. this.txtCenterFreq.EditValue = info.CenterFreq;
  56. this.txtSat.EditValue = sat;
  57. this.txtAnt.EditValue = ant;
  58. this.checkEdit.EditValue = info.Enable;
  59. }
  60. }
  61. private void btnOk_Click(object sender, EventArgs e)
  62. {
  63. try
  64. {
  65. if (!int.TryParse(txtChannel.Text, out int chNum))
  66. {
  67. DxHelper.MsgBoxHelper.ShowError($"通道号非有效整形数字");
  68. return;
  69. }
  70. if (infos.Any(i => i.Id != info.Id && i.ChNum == chNum))
  71. {
  72. DxHelper.MsgBoxHelper.ShowError($"通道号[{txtChannel.Text}]已经存在!");
  73. return;
  74. }
  75. if (!double.TryParse(txtCenterFreq.Text, out double centerFreq))
  76. {
  77. DxHelper.MsgBoxHelper.ShowError($"中心频点非有效数字");
  78. return;
  79. }
  80. if (txtSat.EditValue == null)
  81. {
  82. DxHelper.MsgBoxHelper.ShowError($"卫星不能为空");
  83. return;
  84. }
  85. if (txtAnt.EditValue == null)
  86. {
  87. DxHelper.MsgBoxHelper.ShowError($"天线不能为空");
  88. return;
  89. }
  90. info.ChNum = chNum;
  91. info.CenterFreq = centerFreq;
  92. info.SatInfoID = ((SatViewModel)txtSat.EditValue).Id;
  93. info.TxInfoID = ((RecTxViewModel)txtAnt.EditValue).Id;
  94. info.Enable = (bool)checkEdit.EditValue;
  95. this.DialogResult = DialogResult.OK;
  96. }
  97. catch (Exception ex)
  98. {
  99. string msg = "编辑采集通道信息出错";
  100. IocContainer.Logger.Error(ex, msg);
  101. DxHelper.MsgBoxHelper.ShowError(msg);
  102. }
  103. }
  104. private void btnCancle_Click(object sender, EventArgs e)
  105. {
  106. this.DialogResult = DialogResult.Cancel;
  107. }
  108. }
  109. }