CtrlTx.cs 6.3 KB

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