CtrlTx.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using DevExpress.XtraEditors;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using DevExpress.XtraEditors.Controls;
  12. using ExtensionsDev;
  13. using DW5S.Entity;
  14. using DW5S.Repostory;
  15. using Microsoft.Extensions.Logging;
  16. namespace DW5S.App.UserControl
  17. {
  18. public partial class CtrlTx : DevExpress.XtraEditors.XtraUserControl
  19. {
  20. [Autowired]
  21. private readonly ILogger logger;
  22. [Autowired]
  23. private readonly UnitOfWork unitOfWork;
  24. List<TxInfo> list = new List<TxInfo>();
  25. public CtrlTx()
  26. {
  27. InitializeComponent();
  28. this.layoutControl1.UseDefault();
  29. this.layoutControl2.UseDefault();
  30. this.layoutControl3.UseDefault();
  31. this.layoutControl4.UseDefault();
  32. }
  33. private async void CtrlTx_Load(object sender, EventArgs e)
  34. {
  35. try
  36. {
  37. var repsSys = unitOfWork.Of<TxInfo>();
  38. list = (await repsSys.GetAllAsync()).ToList();
  39. var recTx = list.Find(p => p.TxType == EnumTxType.Rec);
  40. var cdbTx = list.Find(p => p.TxType == EnumTxType.Cdb);
  41. var cxTx = list.Find(p => p.TxType == EnumTxType.Cx);
  42. var refLoc = list.Find(p => p.TxType == EnumTxType.Ref);
  43. if (recTx != null)
  44. {
  45. this.txtMainTxName.Text = recTx.Name;
  46. this.txtMainTxLon.Text = recTx.Lon.ToString();
  47. this.txtMainTxLat.Text = recTx.Lat.ToString();
  48. }
  49. if (cdbTx != null)
  50. {
  51. this.txtCdbName.Text = cdbTx.Name;
  52. this.txtCdbLon.Text = cdbTx.Lon.ToString();
  53. this.txtCdbLat.Text = cdbTx.Lat.ToString();
  54. }
  55. if (cxTx != null)
  56. {
  57. this.txtCxName.Text = cxTx.Name;
  58. this.txtCxLon.Text = cxTx.Lon.ToString();
  59. this.txtCxLat.Text = cxTx.Lat.ToString();
  60. }
  61. if (refLoc != null)
  62. {
  63. this.txtRefName.Text = refLoc.Name;
  64. this.txtRefLon.Text = refLoc.Lon.ToString();
  65. this.txtRefLat.Text = refLoc.Lat.ToString();
  66. }
  67. }
  68. catch (Exception ex)
  69. {
  70. logger.LogError("加载天线信息异常", ex);
  71. DxHelper.MsgBoxHelper.ShowError("加载天线信息异常");
  72. }
  73. }
  74. private async void btnSave_Click(object sender, EventArgs e)
  75. {
  76. try
  77. {
  78. TxInfo txRec = list.Find(p => p.TxType == EnumTxType.Rec);
  79. TxInfo txCdb = list.Find(p => p.TxType == EnumTxType.Cdb);
  80. TxInfo txCx = list.Find(p => p.TxType == EnumTxType.Cx);
  81. TxInfo txRef = list.Find(p => p.TxType == EnumTxType.Ref);
  82. if (txRec == null) txRec = new TxInfo();
  83. if (txCdb == null) txCdb = new TxInfo();
  84. if (txCx == null) txCx = new TxInfo();
  85. if (txRef == null) txRef = new TxInfo();
  86. List<TxInfo> tmp = new List<TxInfo>();
  87. txRec.Name = txtMainTxName.Text;
  88. txRec.TxType = EnumTxType.Rec;
  89. if (!double.TryParse(txtMainTxLon.Text.Trim(), out double lon))
  90. throw new Exception("接收站天线经度格式错误!");
  91. if (!double.TryParse(txtMainTxLat.Text.Trim(), out double lat))
  92. throw new Exception("接收站天线纬度格式错误!");
  93. txRec.Lon = lon;
  94. txRec.Lat = lat;
  95. tmp.Add(txRec);
  96. txCdb.Name = txtCdbName.Text;
  97. txCdb.TxType = EnumTxType.Cdb;
  98. if (!double.TryParse(txtCdbLon.Text.Trim(), out double cdbLon))
  99. throw new Exception("超短站位置经度格式错误!");
  100. if (!double.TryParse(txtCdbLat.Text.Trim(), out double cdbLat))
  101. throw new Exception("超短站位置纬度格式错误!");
  102. txCdb.Lon = cdbLon;
  103. txCdb.Lat = cdbLat;
  104. tmp.Add(txCdb);
  105. txCx.Name = txtCxName.Text;
  106. txCx.TxType = EnumTxType.Cx;
  107. if (!double.TryParse(txtCxLon.Text.Trim(), out double cxLon))
  108. throw new Exception("测向站位置经度格式错误!");
  109. if (!double.TryParse(txtCxLat.Text.Trim(), out double cxLat))
  110. throw new Exception("测向站位置纬度格式错误!");
  111. txCx.Lon = cxLon;
  112. txCx.Lat = cxLat;
  113. tmp.Add(txCx);
  114. txRef.Name = txtRefName.Text;
  115. txRef.TxType = EnumTxType.Ref;
  116. if (!double.TryParse(txtRefLon.Text.Trim(), out double refLon))
  117. throw new Exception("参考站位置经度格式错误!");
  118. if (!double.TryParse(txtRefLat.Text.Trim(), out double refLat))
  119. throw new Exception("参考站位置纬度格式错误!");
  120. txRef.Lon = refLon;
  121. txRef.Lat = refLat;
  122. tmp.Add(txRef);
  123. var repsSys = unitOfWork.Of<TxInfo>();
  124. foreach (var item in tmp)
  125. {
  126. var find = await repsSys.FirstOrDefaultAsync(p => p.Id == item.Id);
  127. if (find != null)
  128. {
  129. find.Name = item.Name;
  130. find.Lon = item.Lon;
  131. find.Lat = item.Lat;
  132. find.SatInfoID = item.SatInfoID;
  133. find.UpdateTime = DateTime.Now;
  134. await repsSys.AddOrUpdateAsync(find);
  135. }
  136. }
  137. await unitOfWork.SaveAsync();
  138. DxHelper.MsgBoxHelper.ShowInfo("保存成功!");
  139. }
  140. catch (Exception ex)
  141. {
  142. logger.LogError(ex,"保存天线信息异常");
  143. DxHelper.MsgBoxHelper.ShowError($"保存天线信息异常.{ex.Message}");
  144. }
  145. }
  146. }
  147. }