using DevExpress.Utils.About; using DevExpress.Utils.Extensions; using DevExpress.XtraBars.Customization; using DevExpress.XtraEditors; using DevExpress.XtraEditors.Controls; using DevExpress.XtraEditors.DXErrorProvider; using DPP_YH_Core.Extensions; using DxHelper; using ExtensionsDev; using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Data; using System.Data.Entity; using System.Drawing; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Documents; using System.Windows.Forms; using XdCxRhDW.Dto; using XdCxRhDW.Entity; using XdCxRhDW.Repostory; namespace XdCxRhDW.App.EditForms { public partial class TaskEditor : DevExpress.XtraEditors.XtraForm { public TaskInfo info; public List taskDetectionWayList; public TaskEditor() { InitializeComponent(); this.layoutControl1.UseDefault(); this.Text = "添加任务"; info = new TaskInfo(); this.StartPosition = FormStartPosition.CenterParent; //加载DW类型 var values = Enum.GetValues(typeof(EnumPosType)); foreach (var item in values) { this.txtPosType.Properties.Items.Add(new RadioGroupItem(Convert.ToInt32(item), ((EnumPosType)item).GetEnumDisplayName())); } values = Enum.GetValues(typeof(EnumTaskType)); foreach (var item in values) { this.txtTaskType.Properties.Items.Add(new RadioGroupItem(Convert.ToInt32(item), ((EnumTaskType)item).GetEnumDisplayName())); } this.txtTaskType.SelectedIndex = 0; this.txtTaskType_SelectedIndexChanged(this, EventArgs.Empty); } public TaskEditor(TaskInfo info,List taskDetectionWayList) : this() { this.Text = "编辑任务"; this.info = info; this.taskDetectionWayList = taskDetectionWayList; } private async void TaskEditor_Load(object sender, EventArgs e) { using (RHDWContext db = new RHDWContext()) { var sats = await db.SatInfos.ToListAsync(); this.txtMainSat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll(); this.txtAdja1Sat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll(); this.txtAdja2Sat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll(); } if (this.Text == "编辑任务" && info != null) { using (RHDWContext db = new RHDWContext()) { 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.txtPosType.SelectedIndex = (int)info.PosType; this.txtTaskType.SelectedIndex = (int)info.TaskType; this.txtSignalType.EditValue = info.SigType; this.txtDetectionWay.EditValue = string.Join(",", taskDetectionWayList); this.txtDetectionWay.RefreshEditValue(); this.txtMainSat.EditValue = satMain; this.txtAdja1Sat.EditValue = satAdja1; this.txtAdja2Sat.EditValue = satAdja2; this.txtFreq.EditValue = info.Freq * (decimal)1e-6; txtCapDir.Text = info.CapDir; txtCapDirFormat.Text = info.CapDirFormat; txtDoFreqUp.Text = info.HistoryFrequpMHz; } } } private void btnSave_Click(object sender, EventArgs e) { try { dxErrorProvider.ClearErrors(); if (txtTaskName.EditValue == null) { dxErrorProvider.SetError(txtTaskName, "请填写任务名"); return; } if (txtSignalType.EditValue == null) { dxErrorProvider.SetError(txtSignalType, "请选择信号类型"); return; } if ((EnumSigType)txtSignalType.EditValue == EnumSigType.SX) { if (txtDetectionWay.EditValue == null) { dxErrorProvider.SetError(txtDetectionWay, "请选择检测方式"); return; } } if (this.Text == "添加任务") { using (RHDWContext db = new RHDWContext()) { if (db.TaskInfos.Any(p => p.TaskName == txtTaskName.Text)) { dxErrorProvider.SetError(txtTaskName, "任务名称重复"); return; } } } else { using (RHDWContext db = new RHDWContext()) { if (db.TaskInfos.Any(p => p.ID != info.ID && p.TaskName == txtTaskName.Text)) { dxErrorProvider.SetError(txtTaskName, "任务名称重复"); return; } } } var posType = (EnumPosType)txtPosType.Properties.Items[txtPosType.SelectedIndex].Value; if (posType == EnumPosType.X1D1CX) { if (txtMainSat.EditValue == null) { dxErrorProvider.SetError(txtMainSat, "请选择卫星"); return; } } else if (posType == EnumPosType.X2D1 || posType == EnumPosType.RH || posType == EnumPosType.X2Dfo) { if (txtMainSat.EditValue == null) { dxErrorProvider.SetError(txtMainSat, "请选择主星"); return; } if (txtAdja1Sat.EditValue == null) { dxErrorProvider.SetError(txtAdja1Sat, "请选择邻星"); return; } } else if (posType == EnumPosType.X3TwoDto || posType == EnumPosType.X3TwoDfo) { if (txtMainSat.EditValue == null) { dxErrorProvider.SetError(txtMainSat, "请选择主星"); return; } if (txtAdja1Sat.EditValue == null) { dxErrorProvider.SetError(txtAdja1Sat, "请选择邻星1"); return; } if (txtAdja2Sat.EditValue == null) { dxErrorProvider.SetError(txtAdja2Sat, "请选择邻星2"); return; } } if (txtTaskType.SelectedIndex == 0) { if (txtFreq.EditValue == null) { dxErrorProvider.SetError(txtFreq, "请填写频点"); return; } } else { if (string.IsNullOrWhiteSpace(txtCapDir.Text)) { dxErrorProvider.SetError(txtCapDir, "请填写采集文件目录"); return; } if (string.IsNullOrWhiteSpace(txtCapDirFormat.Text)) { dxErrorProvider.SetError(txtCapDirFormat, "请填写目录日期格式"); return; } if (string.IsNullOrWhiteSpace(txtDoFreqUp.Text)) { dxErrorProvider.SetError(txtDoFreqUp, "请填写要处理的频点"); return; } try { var str = txtDoFreqUp.Text.Replace(",", ",").Replace(";", ",").Replace(";", ",").Trim(); var freqs = str.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); List list = new List(); foreach (var item in freqs) { double.TryParse(item, out double freqUpMHz); list.Add(freqUpMHz); } txtDoFreqUp.Text = string.Join(",", list.Select(p => p.ToString("f3"))); } catch { dxErrorProvider.SetError(txtDoFreqUp, "处理频点格式错误!"); return; } } info.TaskState = EnumTaskState.Stopped; info.TaskName = txtTaskName.Text; info.PosType = (EnumPosType)txtPosType.SelectedIndex; info.MainSat = ((SatInfo)txtMainSat.EditValue).SatCode; if (txtAdja1Sat.EditValue != null) info.Adja1Sat = ((SatInfo)txtAdja1Sat.EditValue).SatCode; if (txtAdja2Sat.EditValue != null) info.Adja2Sat = ((SatInfo)txtAdja2Sat.EditValue).SatCode; info.SigType = (EnumSigType)txtSignalType.EditValue; if (info.SigType == EnumSigType.SX) { taskDetectionWayList = new List(); var res = txtDetectionWay.EditValue.ToString().Split(new string[] { ","}, System.StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (var s in res) { taskDetectionWayList.Add((EnumDetectionWay)Enum.Parse(typeof(EnumDetectionWay), s)); } } else { taskDetectionWayList = null; } info.TaskType = (EnumTaskType)txtTaskType.SelectedIndex; if (info.TaskType == EnumTaskType.Real) { info.Freq = (long)(Math.Round(Convert.ToDouble(txtFreq.EditValue),3) * 1e6); info.CapDir = null; info.CapDirFormat = null; info.HistoryFrequpMHz = null; } else { info.Freq = 0; info.CapDir = txtCapDir.Text.Trim(); info.CapDirFormat= txtCapDirFormat.Text.Trim(); info.HistoryFrequpMHz = txtDoFreqUp.Text.Replace(",", ",").Replace(";", ",").Replace(";", ",").Trim(); } this.DialogResult = DialogResult.OK; } catch (Exception ex) { Serilog.Log.Error(ex, "编辑任务信息出错"); DxHelper.MsgBoxHelper.ShowError("编辑任务信息出错"); } } private void txtPosType_EditValueChanged(object sender, EventArgs e) { RadioGroup posTypeRadioGroup = sender as RadioGroup; var posType = (EnumPosType)posTypeRadioGroup.Properties.Items[posTypeRadioGroup.SelectedIndex].Value; //var description = (EnumPosType)posType.Properties.Items[posType.SelectedIndex].Description; if (posType == EnumPosType.X1D1CX) { layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; } else if (posType == EnumPosType.X2D1) { layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; this.layoutControlItemAdja1.Text = "邻星"; } else if (posType == EnumPosType.RH) { layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; this.layoutControlItemAdja1.Text = "邻星"; } else if (posType == EnumPosType.X3TwoDto) { layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; this.layoutControlItemAdja1.Text = "邻星1"; } else if (posType == EnumPosType.X3TwoDfo) { layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; this.layoutControlItemAdja1.Text = "邻星1"; } else if (posType == EnumPosType.X2Dfo) { layoutControlItemAdja1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; layoutControlItemAdja2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; this.layoutControlItemAdja1.Text = "邻星"; } else { return; } } private void txtTaskType_SelectedIndexChanged(object sender, EventArgs e) { //加载信号类型 txtSignalType.Properties.Items.Clear(); txtSignalType.Properties.Items.Add(new ImageComboBoxItem("请选择", null, -1)); txtSignalType.Properties.Items.AddEnum(); if (txtTaskType.SelectedIndex == 0) { itemFreqUp.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; itemCapDir.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; itemCapDirFormat.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; itemDoFreqUp.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; } else { itemFreqUp.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; itemCapDir.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; itemCapDirFormat.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; itemDoFreqUp.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; var normal=txtSignalType.Properties.Items.FirstOrDefault(f =>f.Description.Contains("常规")); txtSignalType.Properties.Items.Remove(normal); } } private void txtSignalType_SelectedIndexChanged(object sender, EventArgs e) { if (txtSignalType.SelectedIndex == 0) return;//请选择项不处理 var selectedEnum = (EnumSigType)Enum.Parse(typeof(EnumSigType), txtSignalType.EditValue.ToString()); if (selectedEnum == EnumSigType.SX) { txtDetectionWay.Properties.Items.AddEnum(); itemDetectionWay.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; } else { itemDetectionWay.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; } } private void txtDetectionWay_CustomDisplayText(object sender, CustomDisplayTextEventArgs e) { if (e.Value == null) return; if (e.Value.ToString() == EnumDetectionWay.ISignal.ToString()) { e.DisplayText = $"{(long)e.Value / 1e6}MHz"; } } } }