CtrlTx.cs 7.9 KB

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