X2D1PosParamEditor.cs 8.2 KB

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