123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- using DataSimulation.Repostory;
- using DataSimulation.Repostory.EFContext;
- using DataSimulation.Repostory.Model;
- using DevExpress.Utils.About;
- using DevExpress.XtraEditors.Controls;
- using DevExpress.XtraEditors.DXErrorProvider;
- using DxHelper;
- using ExtensionsDev;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.Entity;
- using System.Data.Entity.Migrations;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace DataSimulation.Forms.EditForms
- {
- public partial class FlightEditor : DevExpress.XtraEditors.XtraForm
- {
- public SimulationInfo info;
- private List<SimulationInfo> simulationInfos;
- public FlightEditor(List<SimulationInfo> simulationInfos)
- {
- InitializeComponent();
- this.Text = "添加航迹";
- info = new SimulationInfo();
- this.simulationInfos = simulationInfos;
- this.StartPosition = FormStartPosition.CenterParent;
- }
- public FlightEditor(List<SimulationInfo> simulationInfos,SimulationInfo info)
- : this(simulationInfos)
- {
- this.Text = "编辑航迹";
- this.info = info;
- }
- private void Editor_Load(object sender, EventArgs e)
- {
- mapControl.UseDefalutOptions()
- .UseClearAll()
- .UseDistanceLine()
- .UseMarkDot()
- .UseExportImg()
- .UseExportXlsx()
- .UseExportCsv()
- .SetMapLayerType(null);
- txtFlightName.EditValueChanged += TxtFlightName_EditValueChanged;
- txtSpeed.EditValueChanged += TxtSpeed_EditValueChanged;
- }
- private void TxtSpeed_EditValueChanged(object sender, EventArgs e)
- {
- double speed;
- if (!double.TryParse(txtSpeed.Text, out speed))
- {
- dxErrorProvider.SetError(txtSpeed, "请设置正确的航迹速度(Km/s)");
- return;
- }
- if (speed <= 0)
- {
- dxErrorProvider.SetError(txtSpeed, "航迹速度范围不能小于等于0Km/s");
- return;
- }
- dxErrorProvider.SetError(txtSpeed, string.Empty);
-
- }
- private void TxtFlightName_EditValueChanged(object sender, EventArgs e)
- {
- string Name = txtFlightName.Text.Trim();
- if (string.IsNullOrEmpty(Name))
- {
- dxErrorProvider.SetError(txtFlightName, "请设置航迹名称");
- return;
- }
- if (simulationInfos.Any(m => m.SimulationName == Name))
- {
- dxErrorProvider.SetError(txtFlightName, $"航迹[{Name}]已存在");
- return;
- }
- dxErrorProvider.SetError(txtFlightName, string.Empty);
- }
- private bool Validators()
- {
- dxErrorProvider.ClearErrors();
- string Name = txtFlightName.Text.Trim();
- if (string.IsNullOrEmpty(Name))
- {
- dxErrorProvider.SetError(txtFlightName, "请设置航迹名称");
- return false;
- }
- if (simulationInfos.Any(m => m.SimulationName == Name))
- {
- dxErrorProvider.SetError(txtFlightName, $"航迹[{Name}]已存在");
- return false;
- }
- double speed;
- if (!double.TryParse(txtSpeed.Text, out speed))
- {
- dxErrorProvider.SetError(txtSpeed, "请设置正确的航迹速度(Km/s)");
- return false;
- }
- if (speed <= 0)
- {
- dxErrorProvider.SetError(txtSpeed, "航迹速度范围不能小于等于0Km/s");
- return false;
- }
- return true;
- }
- private async void btnSave_Click(object sender, EventArgs e)
- {
- if (!Validators())
- {
- return;
- }
- try
- {
- var fligths = mapControl.GetFlightLine<FlightInfo>();
- var fligth = fligths.First();
- SimulationInfo simulationInfo = new SimulationInfo();
- simulationInfo.SimulationName = fligth.FlightName;
- simulationInfo.SimulationSpeed = fligth.Speed;
- using (SimulationPartContext db = SimulationPartContext.GetContext(simulationInfo.CreateTime))
- {
- var sinfo = db.SimulationInfos.Add(simulationInfo);
- await db.SaveChangesAsync();
- var points = fligth.flights.Select(f => new SimulationPonit()
- {
- SimulationId = sinfo.ID,
- SimulationLon = f.FlightLon,
- SimulationLat = f.FlightLat,
- });
- db.SimulationPonits.AddRange(points);
- await db.SaveChangesAsync();
- }
- this.DialogResult = DialogResult.OK;
- }
- catch (Exception ex)
- {
- Serilog.Log.Error(ex, $"{this.Text}异常");
- DxHelper.MsgBoxHelper.ShowError($"{this.Text}异常");
- }
- }
- private void btnFlight_Click(object sender, EventArgs e)
- {
- if (!Validators())
- {
- return;
- }
- try
- {
- string Name = txtFlightName.Text.Trim();
- double speed = Convert.ToDouble(txtSpeed.Text);
- mapControl.DrawFlightLine(Name, speed);
- }
- catch (Exception ex)
- {
- Serilog.Log.Error(ex, $"绘制航迹异常");
- DxHelper.MsgBoxHelper.ShowError($"绘制航迹异常");
- }
- }
- }
- }
|