X2D1PosParamEditor.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. using DevExpress.Mvvm.ModuleInjection.Native;
  2. using DevExpress.XtraEditors;
  3. using DevExpress.XtraEditors.DXErrorProvider;
  4. using ExtensionsDev;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Data.Entity;
  10. using System.Data.Entity.Migrations;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Documents;
  16. using System.Windows.Forms;
  17. using XdDw.App.Api;
  18. using XdDw.App.EFContext;
  19. using XzXdDw.App.Model;
  20. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
  21. namespace XdDw.App.EditForms
  22. {
  23. public partial class X2D1PosParamEditor : DevExpress.XtraEditors.XtraForm
  24. {
  25. public XDPosRes info;
  26. public List<TxInfo> listTx;
  27. private CgRes cgRes;
  28. private double[] PosRes;
  29. private Action callBack;
  30. public X2D1PosParamEditor(XDPosRes info, CgRes cgRes, List<TxInfo> listTx, Action callBack)
  31. {
  32. InitializeComponent();
  33. this.Text = "两星一地定位";
  34. this.info = info;
  35. if (cgRes == null)
  36. {
  37. cgRes = new CgRes();
  38. }
  39. this.cgRes = cgRes;
  40. this.listTx = listTx;
  41. this.callBack = callBack;
  42. this.StartPosition = FormStartPosition.CenterParent;
  43. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  44. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  45. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  46. }
  47. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  48. {
  49. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  50. }
  51. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  52. {
  53. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  54. }
  55. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  56. {
  57. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  58. }
  59. private async void X2D1PosParamEditor_Load(object sender, EventArgs e)
  60. {
  61. List<string> list = new List<string>();
  62. using (RHDWContext db = new RHDWContext())
  63. {
  64. var res = await db.XlInfos.OrderBy(p => p.SatName).ToListAsync();
  65. if (res != null)
  66. list.AddRange(res.Select(p => p.Sat));
  67. }
  68. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  69. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  70. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  71. this.txtsatStation.Text = $"{satTx.Lon},{satTx.Lat}";
  72. this.txtcdbStation.Text = $"{cdbTx.Lon},{cdbTx.Lat}";
  73. this.txtRefLocation.Text = $"{refTx.Lon},{refTx.Lat}";
  74. this.txtDtoSx.Text = $"{cgRes.DtoSx}";
  75. this.txtDtoCdb.Text = $"{cgRes.DtoCdb}";
  76. this.txtYbMain.Text = $"{cgRes.YbMain}";
  77. this.txtYbAdja.Text = $"{cgRes.YbAdja}";
  78. this.sigTime.EditValue = cgRes.SigTime;
  79. this.txtMainX.Text = $"{cgRes.MainX}";
  80. this.txtMainY.Text = $"{cgRes.MainY}";
  81. this.txtMainZ.Text = $"{cgRes.MainZ}";
  82. this.txtAdjaX.Text = $"{cgRes.AdjaX}";
  83. this.txtAdjaY.Text = $"{cgRes.AdjaY}";
  84. this.txtAdjaZ.Text = $"{cgRes.AdjaZ}";
  85. }
  86. private void btnUpdate_Click(object sender, EventArgs e)
  87. {
  88. try
  89. {
  90. if (!CheckParam()) { return; }
  91. if (this.listBox.Items.Count == 0)
  92. {
  93. XtraMessageBox.Show($"两星一地未定位不能更新到数据库中");
  94. return;
  95. }
  96. cgRes.DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  97. cgRes.DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  98. cgRes.YbMain = Convert.ToDouble(this.txtYbMain.Text);
  99. cgRes.YbAdja = Convert.ToDouble(this.txtYbAdja.Text);
  100. cgRes.SigTime = this.sigTime.DateTime;
  101. cgRes.MainX = Convert.ToDouble(this.txtMainX.Text);
  102. cgRes.MainY = Convert.ToDouble(this.txtMainY.Text);
  103. cgRes.MainZ = Convert.ToDouble(this.txtMainZ.Text);
  104. cgRes.AdjaX = Convert.ToDouble(this.txtAdjaX.Text);
  105. cgRes.AdjaY = Convert.ToDouble(this.txtAdjaY.Text);
  106. cgRes.AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text);
  107. string posstr = this.listBox.Items[0].ToString();
  108. var allstrs = posstr.Split(new string[] { ":", "定位经度", "定位纬度", "镜像经度", "镜像纬度" }, StringSplitOptions.RemoveEmptyEntries);
  109. if (allstrs.Length == 4)
  110. {
  111. using (RHDWContext db = new RHDWContext())
  112. {
  113. info.PosLon = Convert.ToDouble(PosRes[0]);
  114. info.PosLat = Convert.ToDouble(PosRes[1]);
  115. info.MirrLon = Convert.ToDouble(PosRes[3]);
  116. info.MirrLat = Convert.ToDouble(PosRes[4]);
  117. db.CgRes.AddOrUpdate(cgRes);//参估结果入库
  118. db.XDPosRes.AddOrUpdate(info);//定位结果入库
  119. db.SaveChangesAsync();
  120. }
  121. callBack?.Invoke();
  122. XtraMessageBox.Show($"两星一地更新数据成功");
  123. }
  124. }
  125. catch (Exception ex)
  126. {
  127. XtraMessageBox.Show($"两星一地更新定位数据失败,失败信息:{ex.Message}");
  128. }
  129. }
  130. public bool CheckParam()
  131. {
  132. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  133. {
  134. return false;
  135. }
  136. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  137. {
  138. return false;
  139. }
  140. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  141. {
  142. return false;
  143. }
  144. return true;
  145. }
  146. private void btnOk_Click(object sender, EventArgs e)
  147. {
  148. listBox.Items.Clear();
  149. if (!CheckParam()) { return; }
  150. try
  151. {
  152. TxInfo satTx = new TxInfo();
  153. satTx.Lon = Convert.ToDouble(txtsatStation.Text.Replace(",", ",").Split(',')[0].Trim());
  154. satTx.Lat = Convert.ToDouble(txtsatStation.Text.Replace(",", ",").Split(',')[1].Trim());
  155. TxInfo cdbTx = new TxInfo();
  156. cdbTx.Lon = Convert.ToDouble(txtcdbStation.Text.Replace(",", ",").Split(',')[0].Trim());
  157. cdbTx.Lat = Convert.ToDouble(txtcdbStation.Text.Replace(",", ",").Split(',')[1].Trim());
  158. TxInfo refTx = new TxInfo();
  159. refTx.Lon = Convert.ToDouble(txtRefLocation.Text.Replace(",", ",").Split(',')[0].Trim());
  160. refTx.Lat = Convert.ToDouble(txtRefLocation.Text.Replace(",", ",").Split(',')[1].Trim());
  161. CgRes cgRes = new CgRes();
  162. cgRes.DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  163. cgRes.DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  164. cgRes.YbMain = Convert.ToDouble(this.txtYbMain.Text);
  165. cgRes.YbAdja = Convert.ToDouble(this.txtYbAdja.Text);
  166. cgRes.SigTime = this.sigTime.DateTime;
  167. cgRes.MainX = Convert.ToDouble(this.txtMainX.Text);
  168. cgRes.MainY = Convert.ToDouble(this.txtMainY.Text);
  169. cgRes.MainZ = Convert.ToDouble(this.txtMainZ.Text);
  170. cgRes.AdjaX = Convert.ToDouble(this.txtAdjaX.Text);
  171. cgRes.AdjaY = Convert.ToDouble(this.txtAdjaY.Text);
  172. cgRes.AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text);
  173. PosRes = PosApi.X2D1_POS(cgRes, satTx, cdbTx, refTx);
  174. listBox.Items.Add($"定位经度:{PosRes[0]:f4} 定位纬度:{PosRes[1]:f4} 镜像经度:{PosRes[3]:f4} 镜像纬度:{PosRes[4]:f4}");
  175. }
  176. catch (Exception ex)
  177. {
  178. XtraMessageBox.Show($"两星一地定位失败,失败信息:{ex.Message}");
  179. }
  180. }
  181. }
  182. }