123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- using DevExpress.Utils.About;
- using DevExpress.Utils.Extensions;
- using DevExpress.XtraBars.Customization;
- using DevExpress.XtraEditors;
- using DevExpress.XtraEditors.ButtonsPanelControl;
- using DevExpress.XtraEditors.Controls;
- using DevExpress.XtraEditors.DXErrorProvider;
- using DevExpress.XtraPrinting.Native;
- using DxHelper;
- using ExtensionsDev;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.ComponentModel.DataAnnotations;
- using System.Data;
- 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 DW5S.DTO;
- using DW5S.Entity;
- using DW5S.Repostory;
- using Microsoft.Extensions.Logging;
- namespace DW5S.App.EditForms
- {
- public partial class TaskEditor : DevExpress.XtraEditors.XtraForm
- {
- [Autowired]
- private readonly ILogger logger;
- [Autowired]
- private readonly UnitOfWork unitOfWork;
- public TaskInfo info;
- public List<SigInfo> selectedItem = new List<SigInfo>();
- 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<SigInfo> taskSigList)
- : this()
- {
- this.Text = $"编辑任务[{info.TaskName}]";
- this.info = info;
- this.selectedItem = taskSigList;
- }
- private async void TaskEditor_Load(object sender, EventArgs e)
- {
- var repsSat = unitOfWork.Reps<SatInfo>();
- var sats = await repsSat.GetAllAsync();
- 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.StartsWith("编辑任务") && info != null)
- {
- var satMain = sats.FirstOrDefault(w => w.SatCode == info.MainSat);
- var satAdja1 = sats.FirstOrDefault(w => w.SatCode == info.Adja1Sat);
- var satAdja2 = sats.FirstOrDefault(w => w.SatCode == info.Adja2Sat);
- this.txtTaskName.Text = info.TaskName;
- this.txtPosType.SelectedIndex = (int)info.PosType;
- this.txtTaskType.SelectedIndex = (int)info.TaskType;
- this.txtMainSat.EditValue = satMain;
- this.txtAdja1Sat.EditValue = satAdja1;
- this.txtAdja2Sat.EditValue = satAdja2;
- txtCapDir.Text = info.CapDir;
- txtCapDirFormat.Text = info.CapDirFormat;
- }
- }
- private async void btnSave_ClickAsync(object sender, EventArgs e)
- {
- try
- {
- dxErrorProvider.ClearErrors();
- var posType = (EnumPosType)txtPosType.Properties.Items[txtPosType.SelectedIndex].Value;
- if (txtTaskName.EditValue == null)
- {
- dxErrorProvider.SetError(txtTaskName, "请填写任务名");
- return;
- }
- if (!selectedItem.Any())
- {
- DxHelper.MsgBoxHelper.ShowError("请选择信号");
- return;
- }
- if (this.Text == "添加任务")
- {
- var repsTask = unitOfWork.Reps<TaskInfo>();
- if (await repsTask.FirstOrDefaultAsync(p => p.TaskName == txtTaskName.Text) != null)
- {
- dxErrorProvider.SetError(txtTaskName, "任务名称重复");
- return;
- }
- }
- else
- {
- var repsTask = unitOfWork.Reps<TaskInfo>();
- if (await repsTask.FirstOrDefaultAsync(p => p.Id != info.Id && p.TaskName == txtTaskName.Text) != null)
- {
- dxErrorProvider.SetError(txtTaskName, "任务名称重复");
- return;
- }
- }
- 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;
- }
- if (txtMainSat.EditValue == txtAdja1Sat.EditValue)
- {
- 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 (txtMainSat.EditValue == txtAdja1Sat.EditValue)
- {
- dxErrorProvider.SetError(txtAdja1Sat, "邻星1不能和主星一致");
- return;
- }
- if (txtMainSat.EditValue == txtAdja2Sat.EditValue)
- {
- dxErrorProvider.SetError(txtAdja2Sat, "邻星2不能和主星一致");
- return;
- }
- if (txtAdja1Sat.EditValue == txtAdja2Sat.EditValue)
- {
- dxErrorProvider.SetError(txtAdja2Sat, "邻星2不能和邻星1一致");
- return;
- }
- }
- if ((EnumTaskType)txtTaskType.EditValue == EnumTaskType.History)//是历史任务
- {
- if (string.IsNullOrWhiteSpace(txtCapDir.Text))
- {
- dxErrorProvider.SetError(txtCapDir, "请填写采集文件目录");
- 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.TaskType = (EnumTaskType)txtTaskType.SelectedIndex;
- if (info.TaskType == EnumTaskType.Group)
- {
- info.CapDir = null;
- info.CapDirFormat = null;
- }
- else
- {
- info.CapDir = txtCapDir.Text.Trim();
- info.CapDirFormat = txtCapDirFormat.Text.Trim();
- }
- this.DialogResult = DialogResult.OK;
- }
- catch (Exception ex)
- {
- string msg = "编辑任务信息出错";
- logger.LogError(ex, msg);
- DxHelper.MsgBoxHelper.ShowError(msg);
- }
- }
- private void txtPosType_EditValueChanged(object sender, EventArgs e)
- {
- RadioGroup posTypeRadioGroup = sender as RadioGroup;
- var posType = (EnumPosType)posTypeRadioGroup.Properties.Items[posTypeRadioGroup.SelectedIndex].Value;
- 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 = "邻星";
- }
- this.layoutControl1.BestFit();
- }
- private void txtTaskType_SelectedIndexChanged(object sender, EventArgs e)
- {
- if ((EnumTaskType)txtTaskType.EditValue == EnumTaskType.Group)
- {
- itemCapDir.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
- itemCapDirFormat.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
- if (this.Height >= 438)
- this.Height -= 55;
- }
- else
- {
- itemCapDir.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
- itemCapDirFormat.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
- //txtSignalType.Properties.Items.Remove(normal);//不要移除了
- var a = this.Height;
- if (this.Height < 438)
- this.Height += 55;
- }
- this.layoutControl1.BestFit();
- }
- private void btnFreq_Click(object sender, EventArgs e)
- {
- if (this.Text.StartsWith("添加任务"))
- {
- TaskEditorSignal frm = new TaskEditorSignal();
- if (frm.ShowDialog() != DialogResult.OK) return;
- frm.info = info;
- selectedItem.Clear();
- selectedItem = frm.listSigInfoSelected;
- }
- else if (this.Text.StartsWith("编辑任务") && info != null)
- {
- TaskEditorSignal frm = new TaskEditorSignal(info, selectedItem);
- if (frm.ShowDialog() != DialogResult.OK) return;
- selectedItem.Clear();
- selectedItem = frm.listSigInfoSelected;
- }
- }
- }
- }
|