using DataSimulation.Repostory; using DataSimulation.Repostory.EFContext; using DataSimulation.Repostory.Model; using DevExpress.Utils.About; using DevExpress.XtraEditors; using DevExpress.XtraEditors.Controls; using DxHelper; using ExtensionsDev; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Entity; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using static DevExpress.Utils.Drawing.Helpers.NativeMethods; namespace DataSimulation.Forms.EditForms { public partial class TaskEditor : DevExpress.XtraEditors.XtraForm { public TaskInfo info; public TaskEditor() { InitializeComponent(); //this.layoutControl1.UseDefault(); this.Text = "添加任务"; info = new TaskInfo(); this.StartPosition = FormStartPosition.CenterParent; List radioGroups = new List(); var values = Enum.GetValues(typeof(EnumSimulationType)); foreach (var item in values) { radioGroups.Add(new RadioGroupItem(Convert.ToInt32(item), ((EnumSimulationType)item).GetEnumDisplayName())); } this.radioSimulationType.Properties.Items.AddRange(radioGroups.ToArray()); this.radioSimulationType.SelectedIndex = 0; } public TaskEditor(TaskInfo info) : this() { this.Text = "编辑任务"; this.info = info; } private async void TaskEditor_Load(object sender, EventArgs e) { mapControl.UseDefalutOptions() .UseClearAll() .UseDistanceLine() .UseMarkDot() .UseExportImg() .UseExportXlsx() .UseExportCsv() //.UseFlightLine(res => //{ // (bool isShowPopup, XtraUserControl frm) = res; // if (isShowPopup) // { // DxHelper.PopupHelper.ShowPopup(frm, mapControl, 400); // } // else // { // DxHelper.PopupHelper.HidePopup(frm); // } //}) .SetMapLayerType(null) .UseDrawRect(rect => { (double startLon, double startLat, double centerLon, double centerLat, double endLon, double endLat, double lonRange, double latRange) = rect; }); var hjList = await SimulationCache.GetAllAsync(); this.txtHj.Properties.DataSource = hjList; this.txtHj.Properties.ValueMember = nameof(SimulationInfo); // this.txtHj.Properties.KeyMember = nameof(SimulationInfo.CreateTime); this.txtHj.Properties.DisplayMember = nameof(SimulationInfo.SimulationName); this.txtHj.SetSearchGridLookUpEditMultiSelected(); using (SimulationContext db = new SimulationContext()) { var sats = await db.SatInfos.ToListAsync(); this.txtMainSat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll(); this.txtAdjaSat1.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll(); this.txtAdjaSat2.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll(); var ants = await db.AntInfos.ToListAsync(); foreach (var item in ants) { this.txtTx.Properties.Items.Add(new ImageComboBoxItem(item.AntName, item.ID)); } var refs = await db.RefInfos.ToListAsync(); foreach (var item in refs) { this.txtRefStation.Properties.Items.Add(new ImageComboBoxItem(item.RefName, item.ID)); } } if (this.Text == "编辑任务" && info != null) { using (SimulationContext db = new SimulationContext()) { var satMain = await db.SatInfos.Where(w => w.SatCode == info.MainSat).FirstOrDefaultAsync(); var satAdja1 = await db.SatInfos.Where(w => w.SatCode == info.Adja1Sat).FirstOrDefaultAsync(); var satAdja2 = await db.SatInfos.Where(w => w.SatCode == info.Adja2Sat).FirstOrDefaultAsync(); this.txtTaskName.Text = info.TaskName; this.radioSimulationType.SelectedIndex = (int)info.SimulationType; this.txtMainSat.EditValue = satMain; this.txtAdjaSat1.EditValue = satAdja1; this.txtAdjaSat2.EditValue = satAdja2; this.txtTx.EditValue = info.AntID; this.txtRefStation.EditValue = info.RefID; this.txtFreqUp.EditValue = info.Freq * (decimal)1e-6; this.txtBand.EditValue = info.Band * (decimal)1e-6; this.txtSpeed.EditValue = info.Speed; } } } /// /// 验证信息 /// private void validation() { try { dxErrorProvider.ClearErrors(); if (txtTaskName.EditValue == null) { dxErrorProvider.SetError(txtTaskName, "请填写任务名"); return; } if (radioSimulationType.SelectedIndex == -1) { dxErrorProvider.SetError(radioSimulationType, "请选择仿真类型"); return; } var posType = (EnumSimulationType)radioSimulationType.Properties.Items[radioSimulationType.SelectedIndex].Value; if (posType == EnumSimulationType.X3TwoDto) { if (txtMainSat.EditValue == null) { dxErrorProvider.SetError(txtMainSat, "请选择主星"); return; } if (txtAdjaSat1.EditValue == null) { dxErrorProvider.SetError(txtAdjaSat1, "请选择邻星1"); return; } if (txtAdjaSat2.EditValue == null) { dxErrorProvider.SetError(txtAdjaSat2, "请选择邻星2"); return; } } if (txtTx.EditValue == null) { dxErrorProvider.SetError(txtTx, "请选择天线"); return; } if (txtRefStation.EditValue == null) { dxErrorProvider.SetError(txtRefStation, "请选择参考站"); return; } if (txtFreqUp.EditValue == null) { dxErrorProvider.SetError(txtFreqUp, "请填写频点"); return; } if (txtBand.EditValue == null) { dxErrorProvider.SetError(txtBand, "请填写带宽"); return; } if (txtSpeed.EditValue == null) { dxErrorProvider.SetError(txtSpeed, "请填写速度"); return; } info.TaskState = EnumTaskState.Stopped; info.TaskName = txtTaskName.Text; info.SimulationType = (EnumSimulationType)radioSimulationType.SelectedIndex; info.MainSat = ((SatInfo)txtMainSat.EditValue).SatCode; if (txtAdjaSat1.EditValue != null) info.Adja1Sat = ((SatInfo)txtAdjaSat1.EditValue).SatCode; if (txtAdjaSat2.EditValue != null) info.Adja2Sat = ((SatInfo)txtAdjaSat2.EditValue).SatCode; info.AntID = Convert.ToInt64(txtTx.EditValue); info.RefID = Convert.ToInt64(txtRefStation.EditValue); info.Freq = (long)(Convert.ToDouble(txtFreqUp.EditValue) * 1e6); info.Band = (long)(Convert.ToDouble(txtBand.EditValue) * 1e6); info.Speed = Convert.ToInt64(txtSpeed.EditValue); info.isHistory = false; this.DialogResult = DialogResult.OK; } catch (Exception ex) { Serilog.Log.Error(ex, "编辑任务信息出错"); DxHelper.MsgBoxHelper.ShowError("编辑任务信息出错"); } } private void btnSave_Click(object sender, EventArgs e) { validation(); } private void btnSaveOther_Click(object sender, EventArgs e) { validation(); } private void txtHj_EditValueChanged(object sender, EventArgs e) { var selectedValue = txtHj.Properties.Tag.MapTo>(); if (selectedValue != null) { List flightInfos = new List(); foreach (var item in selectedValue) { var simulationPonitInfo = SimulationCache.GetAllByIDAsync(item.ID, item.CreateTime).Result; var flinfo = new FlightInfo(item.SimulationName, item.SimulationSpeed); var fpoinits = simulationPonitInfo.Select(s => new FlightData(s.SimulationLon, s.SimulationLat)); flinfo.flights.AddRange(fpoinits); flightInfos.Add(flinfo); } mapControl.SetFlightLine(flightInfos); } } } }