X2D1DTOParamEditor.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using DevExpress.Mvvm.ModuleInjection.Native;
  2. using DevExpress.XtraEditors;
  3. using DevExpress.XtraEditors.DXErrorProvider;
  4. using DevExpress.XtraLayout;
  5. using DevExpress.XtraMap;
  6. using DevExpress.XtraTreeList.Data;
  7. using DxHelper;
  8. using ExtensionsDev;
  9. using System;
  10. using System.CodeDom;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Data;
  14. using System.Data.Entity;
  15. using System.Data.Entity.Migrations;
  16. using System.Drawing;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using System.Windows.Documents;
  21. using System.Windows.Forms;
  22. using XdCxRhDW.Core.Api;
  23. using XdCxRhDW.Repostory.EFContext;
  24. using XdCxRhDW.Repostory.Model;
  25. namespace XdCxRhDW.App.EditForms
  26. {
  27. public partial class X2D1DTOParamEditor : DevExpress.XtraEditors.XtraForm
  28. {
  29. private MapControl mapControl1;
  30. private PosRes info;
  31. private CgRes cg;
  32. private List<SatInfo> listSat;
  33. public X2D1DTOParamEditor(PosRes info, MapControl mapControl)
  34. {
  35. InitializeComponent();
  36. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  37. this.info = info;
  38. this.listSat = new List<SatInfo>();
  39. this.mapControl1 = mapControl;
  40. this.StartPosition = FormStartPosition.CenterParent;
  41. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  42. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  43. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  44. }
  45. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  46. {
  47. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  48. }
  49. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  50. {
  51. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  52. }
  53. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  54. {
  55. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  56. }
  57. private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
  58. {
  59. StationRes station;
  60. using (RHDWContext db = new RHDWContext())
  61. {
  62. listSat = await db.SatInfos.ToListAsync();
  63. }
  64. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  65. {
  66. cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  67. station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  68. }
  69. if (cg != null)
  70. {
  71. this.txtDtoSx.Text = $"{cg.Dto1.Value}";
  72. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value}";
  73. if (info.PosResType == EnumPosResType.X2D1)
  74. {
  75. this.txtYbMain.Text = $"{cg.YbMainDto.Value}";
  76. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value}";
  77. }
  78. this.sigTime.EditValue = info.SigTime;
  79. this.txtMainX.Text = $"{cg.MainX.Value}";
  80. this.txtMainY.Text = $"{cg.MainY.Value}";
  81. this.txtMainZ.Text = $"{cg.MainZ.Value}";
  82. this.txtAdjaX.Text = $"{cg.Adja1X.Value}";
  83. this.txtAdjaY.Text = $"{cg.Adja1Y.Value}";
  84. this.txtAdjaZ.Text = $"{cg.Adja1Z.Value}";
  85. }
  86. if (info.PosResType == EnumPosResType.X2D1NoRef)
  87. {
  88. txtYbMain.Properties.ReadOnly = true;
  89. txtYbAdja.Properties.ReadOnly = true;
  90. layoutControlItem10.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  91. }
  92. if (station != null)
  93. {
  94. this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}";
  95. this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  96. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  97. }
  98. }
  99. public bool CheckParam()
  100. {
  101. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  102. {
  103. return false;
  104. }
  105. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  106. {
  107. return false;
  108. }
  109. if (info.PosResType == EnumPosResType.X2D1 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  110. {
  111. return false;
  112. }
  113. return true;
  114. }
  115. private void btnOk_Click(object sender, EventArgs e)
  116. {
  117. if (!CheckParam()) { return; }
  118. try
  119. {
  120. var MsAnt = txtsatStation.GetLonLat();
  121. var CDBAnt = txtcdbStation.GetLonLat();
  122. var RefGeod = info.PosResType == EnumPosResType.X2D1 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  123. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  124. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  125. var YbMainDto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  126. var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  127. var MainX = Convert.ToDouble(this.txtMainX.Text);
  128. var MainY = Convert.ToDouble(this.txtMainY.Text);
  129. var MainZ = Convert.ToDouble(this.txtMainZ.Text);
  130. var AdjaX = Convert.ToDouble(this.txtAdjaX.Text);
  131. var AdjaY = Convert.ToDouble(this.txtAdjaY.Text);
  132. var AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text);
  133. double[] msEph = new double[] { MainX, MainY, MainZ, 0, 0, 0 };
  134. double[] NsEph = new double[] { AdjaX, AdjaY, AdjaZ, 0, 0, 0 };
  135. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  136. dtoLineXd.MsEph = msEph;
  137. dtoLineXd.MsAnt = MsAnt;
  138. dtoLineXd.CDBAnt = CDBAnt;
  139. dtoLineXd.RefGeod = RefGeod;
  140. dtoLineXd.xdDto = DtoCdb;
  141. dtoLineXd.RefDto = YbMainDto;
  142. dtoLineXd.PosLon = info.PosLon;
  143. dtoLineXd.PosLat = info.PosLat;
  144. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  145. twoStartOption.MsEph = msEph;
  146. twoStartOption.NsEph = NsEph;
  147. twoStartOption.MsAnt = MsAnt;
  148. twoStartOption.NsAnt = MsAnt;
  149. twoStartOption.RefGeod = RefGeod;
  150. twoStartOption.TargetDto = DtoSx;
  151. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  152. twoStartOption.PosLon = info.PosLon;
  153. twoStartOption.PosLat = info.PosLat;
  154. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  155. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  156. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  157. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString();
  158. if (info.PosResType == EnumPosResType.X2D1)
  159. {
  160. var xdDtoLine = DrawDtoLineHelper.DtoLineXd(dtoLineXd);
  161. mapControl1.DrawDtoPonit($"[{msat},超短{CDBAnt[0]}°]时差线", xdDtoLine);
  162. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  163. mapControl1.DrawDtoPonit($"[{msat},{nsat}]时差线", tsDtoLine);
  164. }
  165. else
  166. {
  167. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNoRef(dtoLineXd);
  168. mapControl1.DrawDtoPonit($"[{msat},超短{CDBAnt[0]}°]时差线", xdDtoLine);
  169. var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  170. mapControl1.DrawDtoPonit($"[{msat},{nsat}]时差线", tsDtoLine);
  171. }
  172. }
  173. catch (Exception ex)
  174. {
  175. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  176. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败");
  177. }
  178. }
  179. }
  180. }