CtrlTx.cs 6.5 KB

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