CtrlTx.cs 7.4 KB

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