123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- using DevExpress.XtraEditors;
- using ExtensionsDev;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Documents;
- using System.Windows.Forms;
- using DW5S.Entity;
- using DW5S.Repostory;
- using Serilog;
- using DW5S.Service;
- using DW5S.ViewModel;
- namespace DW5S.App.EditForms
- {
- public partial class FixedStationEditor : DevExpress.XtraEditors.XtraForm
- {
- public FixedStationViewModel info;
- private List<FixedStationViewModel> infos;
- public FixedStationEditor()
- {
- InitializeComponent();
- this.layoutControl1.UseDefault();
- this.Text = "固定站添加";
- info = new FixedStationViewModel();
- this.StartPosition = FormStartPosition.CenterParent;
- }
- public FixedStationEditor(FixedStationViewModel info)
- : this()
- {
- this.Text = "固定站编辑";
- this.info = info;
- }
- private async void SatEditor_Load(object sender, EventArgs e)
- {
- infos = new List<FixedStationViewModel>();
- var unitOfWork = IocContainer.UnitOfWork;
- var repsFixed = unitOfWork.Of<FixedStation>();
- var res = await repsFixed.GetAllAsync();
- infos.AddRange(res.To<List<FixedStationViewModel>>());
- var repsSig = unitOfWork.Of<SigInfo>();
- var sigs = await repsSig.GetAllAsync();
- this.txtFreqUp.UseDefault().SetData(sigs.To<List<SigViewModel>>(), displayField: nameof(SigViewModel.FreqUpDis)).UseDoubleClickToSelectAll();
- if (this.Text == "固定站编辑" && info != null)
- {
- this.txtName.Text = info.StationName;
- this.txtLon.Text = info.Lon.ToString();
- this.txtLat.Text = info.Lat.ToString();
- this.txtValue.Text = info.Value.ToString();
- this.txtFreqUp.EditValue = sigs.FirstOrDefault(p => p.FreqUp == info.FreqUpHz);
- this.txtEnable.Checked = info.Enable;
- }
- }
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.DialogResult = DialogResult.Cancel;
- }
- private void btnOk_Click(object sender, EventArgs e)
- {
- try
- {
- var name = txtName.Text.Trim();
- if (infos.Any(i => i.Id != info.Id && i.StationName == name))
- {
- DxHelper.MsgBoxHelper.ShowError($"已经存在名称为[{name}]的固定站!");
- return;
- }
- var freqUpHz = (txtFreqUp.EditValue as SigInfo).FreqUp;
- if (infos.Any(i => i.Id != info.Id && i.FreqUpHz == freqUpHz))
- {
- DxHelper.MsgBoxHelper.ShowError($"已经存在上行频点为[{freqUpHz / 1e6:f3}MHz]的固定站!");
- return;
- }
- if (!double.TryParse(txtLon.Text.Trim(), out double lon))
- {
- DxHelper.MsgBoxHelper.ShowError($"经度不是有效的数字");
- return;
- }
- if (!double.TryParse(txtLat.Text.Trim(), out double lat))
- {
- DxHelper.MsgBoxHelper.ShowError($"纬度不是有效的数字");
- return;
- }
- if (!double.TryParse(txtValue.Text.Trim(), out double value))
- {
- DxHelper.MsgBoxHelper.ShowError($"判定规则不是有效的数字");
- return;
- }
- if (value < 0)
- {
- DxHelper.MsgBoxHelper.ShowError($"判定规则必须大于0秒");
- return;
- }
- info.StationName = name;
- info.Lon = lon;
- info.Lat = lat;
- info.FreqUpHz = freqUpHz;
- info.Value = value;
- info.Enable = txtEnable.Checked;
- this.DialogResult = DialogResult.OK;
- }
- catch (Exception ex)
- {
- string msg = "编辑固定站信息出错";
- IocContainer.Logger.Error(ex, msg);
- DxHelper.MsgBoxHelper.ShowError(msg);
- }
- }
- }
- }
|