CtrlTx.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using DevExpress.XtraEditors;
  2. using XdCxRhDW.Repostory.EFContext;
  3. using XdCxRhDW.Repostory.Model;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Data.Entity;
  9. using System.Drawing;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. using DevExpress.XtraEditors.Controls;
  15. namespace XdCxRhDW.App.UserControl
  16. {
  17. public partial class CtrlTx : DevExpress.XtraEditors.XtraUserControl
  18. {
  19. List<TxInfo> list = new List<TxInfo>();
  20. public CtrlTx()
  21. {
  22. InitializeComponent();
  23. }
  24. private async void CtrlTx_Load(object sender, EventArgs e)
  25. {
  26. try
  27. {
  28. using (RHDWContext db = new RHDWContext())
  29. {
  30. list = await db.TxInfos.ToListAsync();
  31. var mainTx = list.Find(p => p.TxType == EnumTxType.MainSat);
  32. var adjaTx = list.Find(p => p.TxType == EnumTxType.AdjaSat);
  33. var cdbTx = list.Find(p => p.TxType == EnumTxType.Cdb);
  34. var cxTx = list.Find(p => p.TxType == EnumTxType.Cx);
  35. var refLoc = list.Find(p => p.TxType == EnumTxType.Ref);
  36. if (mainTx != null)
  37. {
  38. this.txtMainTxName.Text = mainTx.Name;
  39. this.txtMainTxLon.Text = mainTx.Lon.ToString();
  40. this.txtMainTxLat.Text = mainTx.Lat.ToString();
  41. }
  42. if (adjaTx != null)
  43. {
  44. this.txtAdjaTxName.Text = adjaTx.Name;
  45. this.txtAdjaTxLon.Text = adjaTx.Lon.ToString();
  46. this.txtAdjaTxLat.Text = adjaTx.Lat.ToString();
  47. }
  48. if (cdbTx != null)
  49. {
  50. this.txtCdbName.Text = cdbTx.Name;
  51. this.txtCdbLon.Text = cdbTx.Lon.ToString();
  52. this.txtCdbLat.Text = cdbTx.Lat.ToString();
  53. }
  54. if (cxTx != null)
  55. {
  56. this.txtCxName.Text = cxTx.Name;
  57. this.txtCxLon.Text = cxTx.Lon.ToString();
  58. this.txtCxLat.Text = cxTx.Lat.ToString();
  59. }
  60. if (refLoc != null)
  61. {
  62. this.txtRefLon.Text = refLoc.Lon.ToString();
  63. this.txtRefLat.Text = refLoc.Lat.ToString();
  64. }
  65. }
  66. }
  67. catch (Exception ex)
  68. {
  69. Serilog.Log.Error(ex,"加载天线信息异常");
  70. DxHelper.MsgBoxHelper.ShowError("加载天线信息异常");
  71. }
  72. }
  73. private async void btnSave_Click(object sender, EventArgs e)
  74. {
  75. try
  76. {
  77. TxInfo txMain = list.Find(p => p.TxType == EnumTxType.MainSat);
  78. TxInfo txAdja = list.Find(p => p.TxType == EnumTxType.AdjaSat);
  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 (txMain == null) txMain = new TxInfo();
  83. if (txAdja == null) txAdja = new TxInfo();
  84. if (txCdb == null) txCdb = new TxInfo();
  85. if (txCx == null) txCx = new TxInfo();
  86. if (txRef == null) txRef = new TxInfo();
  87. List<TxInfo> tmp = new List<TxInfo>();
  88. txMain.Name = txtMainTxName.Text;
  89. txMain.TxType = EnumTxType.MainSat;
  90. if (!double.TryParse(txtMainTxLon.Text.Trim(), out double lon))
  91. throw new Exception("主星天线经度格式错误!");
  92. if (!double.TryParse(txtMainTxLat.Text.Trim(), out double lat))
  93. throw new Exception("主星天线纬度格式错误!");
  94. txMain.Lon = lon;
  95. txMain.Lat = lat;
  96. tmp.Add(txMain);
  97. txAdja.Name = txtAdjaTxName.Text;
  98. txAdja.TxType = EnumTxType.AdjaSat;
  99. if (!double.TryParse(txtAdjaTxLon.Text.Trim(), out double adjaLon))
  100. throw new Exception("邻星天线经度格式错误!");
  101. if (!double.TryParse(txtAdjaTxLat.Text.Trim(), out double adjaLat))
  102. throw new Exception("邻星天线纬度格式错误!");
  103. txAdja.Lon = adjaLon;
  104. txAdja.Lat = adjaLat;
  105. tmp.Add(txAdja);
  106. txCdb.Name = txtCdbName.Text;
  107. txCdb.TxType = EnumTxType.Cdb;
  108. if (!double.TryParse(txtCdbLon.Text.Trim(), out double cdbLon))
  109. throw new Exception("超短站位置经度格式错误!");
  110. if (!double.TryParse(txtCdbLat.Text.Trim(), out double cdbLat))
  111. throw new Exception("超短站位置纬度格式错误!");
  112. txCdb.Lon = cdbLon;
  113. txCdb.Lat = cdbLat;
  114. tmp.Add(txCdb);
  115. txCx.Name = txtCxName.Text;
  116. txCx.TxType = EnumTxType.Cx;
  117. if (!double.TryParse(txtCxLon.Text.Trim(), out double cxLon))
  118. throw new Exception("测向站位置经度格式错误!");
  119. if (!double.TryParse(txtCxLat.Text.Trim(), out double cxLat))
  120. throw new Exception("测向站位置纬度格式错误!");
  121. txCx.Lon = cxLon;
  122. txCx.Lat = cxLat;
  123. tmp.Add(txCx);
  124. txRef.TxType = EnumTxType.Ref;
  125. if (!double.TryParse(txtRefLon.Text.Trim(), out double refLon))
  126. throw new Exception("参考站位置经度格式错误!");
  127. if (!double.TryParse(txtRefLat.Text.Trim(), out double refLat))
  128. throw new Exception("参考站位置纬度格式错误!");
  129. txRef.Lon = refLon;
  130. txRef.Lat = refLat;
  131. tmp.Add(txRef);
  132. using (RHDWContext db = new RHDWContext())
  133. {
  134. foreach (var item in tmp)
  135. {
  136. var find = await db.TxInfos.Where(p => p.ID == item.ID).FirstOrDefaultAsync();
  137. if (find != null)
  138. {
  139. find.Name = item.Name;
  140. find.Lon = item.Lon;
  141. find.Lat = item.Lat;
  142. find.SatInfoID = item.SatInfoID;
  143. }
  144. else
  145. {
  146. db.TxInfos.Add(item);
  147. }
  148. await db.SaveChangesAsync();
  149. }
  150. }
  151. DxHelper.MsgBoxHelper.ShowInfo("保存成功!");
  152. }
  153. catch (Exception ex)
  154. {
  155. Serilog.Log.Error(ex, "保存天线信息异常");
  156. DxHelper.MsgBoxHelper.ShowError($"保存天线信息异常.{ex.Message}");
  157. }
  158. }
  159. }
  160. }