123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- 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.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.Repostory.EFContext;
- using XdCxRhDW.Repostory.Model;
- namespace XdCxRhDW.App.EditForms
- {
- public partial class TaskEditor : DevExpress.XtraEditors.XtraForm
- {
- public TaskInfo info;
- public TaskEditor()
- {
- InitializeComponent();
- this.Text = "添加任务";
- info = new TaskInfo();
- this.StartPosition = FormStartPosition.CenterParent;
- //加载DW类型
- List<RadioGroupItem> radioGroups = new List<RadioGroupItem>();
- var values = Enum.GetValues(typeof(EnumPosType));
- foreach (var item in values)
- {
- radioGroups.Add(new RadioGroupItem(Convert.ToInt32(item), ((EnumPosType)item).GetEnumDisplayName()));
- }
- this.txtPosType.Properties.Items.AddRange(radioGroups.ToArray());
- }
- public TaskEditor(TaskInfo info)
- : this()
- {
- this.Text = "编辑任务";
- this.info = info;
- }
- 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.txtMainSat.EditValue = satMain;
- this.txtAdja1Sat.EditValue = satAdja1;
- this.txtAdja2Sat.EditValue = satAdja2;
- this.txtFreq.EditValue = info.Freq * 1e-6;
- this.txtBand.EditValue = info.Band * 1e-6;
- }
- }
- }
- private void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- if (txtTaskName.EditValue == null)
- {
- DxHelper.MsgBoxHelper.ShowError("请填写任务名");
- return;
- }
- if (txtPosType.SelectedIndex== -1)
- {
- DxHelper.MsgBoxHelper.ShowError("请选择定位类型");
- return;
- }
- var posType = (EnumPosType)txtPosType.Properties.Items[txtPosType.SelectedIndex].Value;
- if (posType == EnumPosType.X1D1CX)
- {
- if (txtMainSat.EditValue == null)
- {
- DxHelper.MsgBoxHelper.ShowError("请选择卫星");
- return;
- }
- }
- else if (posType == EnumPosType.X2D1|| posType == EnumPosType.RH|| posType == EnumPosType.X2Dfo)
- {
- if (txtMainSat.EditValue == null)
- {
- DxHelper.MsgBoxHelper.ShowError("请选择主星");
- return;
- }
- if (txtAdja1Sat.EditValue == null)
- {
- DxHelper.MsgBoxHelper.ShowError("请选择邻星");
- return;
- }
- }
- else if (posType == EnumPosType.X3TwoDto|| posType == EnumPosType.X3TwoDfo)
- {
- if (txtMainSat.EditValue == null)
- {
- DxHelper.MsgBoxHelper.ShowError("请选择主星");
- return;
- }
- if (txtAdja1Sat.EditValue == null)
- {
- DxHelper.MsgBoxHelper.ShowError("请选择邻星1");
- return;
- }
- if (txtAdja2Sat.EditValue == null)
- {
- DxHelper.MsgBoxHelper.ShowError("请选择邻星2");
- return;
- }
-
- }
- if (txtFreq.EditValue == null)
- {
- DxHelper.MsgBoxHelper.ShowError("请填写频点");
- return;
- }
- if (txtBand.EditValue == null)
- {
- DxHelper.MsgBoxHelper.ShowError("请填写带宽");
- 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.Freq = (long)(Convert.ToDouble(txtFreq.EditValue) * 1e6);
- info.Band = (int)(Convert.ToDouble(txtBand.EditValue) * 1e6);
- 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;
- }
- }
- }
- }
|