CtrlTx.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using DevExpress.XtraEditors;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Data.Entity;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using DevExpress.XtraEditors.Controls;
  13. using ExtensionsDev;
  14. using XdCxRhDW.Entity;
  15. using XdCxRhDW.Repostory;
  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. }
  29. private async void CtrlTx_Load(object sender, EventArgs e)
  30. {
  31. try
  32. {
  33. using (RHDWContext db = new RHDWContext())
  34. {
  35. list = await db.TxInfos.ToListAsync();
  36. var recTx = list.Find(p => p.TxType == EnumTxType.Rec);
  37. var cdbTx = list.Find(p => p.TxType == EnumTxType.Cdb);
  38. var cxTx = list.Find(p => p.TxType == EnumTxType.Cx);
  39. var refLoc = list.Find(p => p.TxType == EnumTxType.Ref);
  40. if (recTx != null)
  41. {
  42. this.txtMainTxName.Text = recTx.Name;
  43. this.txtMainTxLon.Text = recTx.Lon.ToString();
  44. this.txtMainTxLat.Text = recTx.Lat.ToString();
  45. }
  46. if (cdbTx != null)
  47. {
  48. this.txtCdbName.Text = cdbTx.Name;
  49. this.txtCdbLon.Text = cdbTx.Lon.ToString();
  50. this.txtCdbLat.Text = cdbTx.Lat.ToString();
  51. }
  52. if (cxTx != null)
  53. {
  54. this.txtCxName.Text = cxTx.Name;
  55. this.txtCxLon.Text = cxTx.Lon.ToString();
  56. this.txtCxLat.Text = cxTx.Lat.ToString();
  57. }
  58. if (refLoc != null)
  59. {
  60. this.txtRefName.Text = refLoc.Name;
  61. this.txtRefLon.Text = refLoc.Lon.ToString();
  62. this.txtRefLat.Text = refLoc.Lat.ToString();
  63. }
  64. }
  65. }
  66. catch (Exception ex)
  67. {
  68. Serilog.Log.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. using (RHDWContext db = new RHDWContext())
  122. {
  123. foreach (var item in tmp)
  124. {
  125. var find = await db.TxInfos.Where(p => p.ID == item.ID).FirstOrDefaultAsync();
  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. }
  133. else
  134. {
  135. db.TxInfos.Add(item);
  136. }
  137. await db.SaveChangesAsync();
  138. }
  139. }
  140. DxHelper.MsgBoxHelper.ShowInfo("保存成功!");
  141. }
  142. catch (Exception ex)
  143. {
  144. Serilog.Log.Error(ex, "保存天线信息异常");
  145. DxHelper.MsgBoxHelper.ShowError($"保存天线信息异常.{ex.Message}");
  146. }
  147. }
  148. }
  149. }