123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- using DevExpress.XtraEditors;
- 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.Runtime.Remoting.Metadata.W3cXsd2001;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Documents;
- using System.Windows.Forms;
- using XdCxRhDW.Entity;
- using XdCxRhDW.Repostory;
- namespace XdCxRhDW.App.EditForms
- {
- public partial class FixedStationEditor : DevExpress.XtraEditors.XtraForm
- {
- public FixedStation info;
- private List<FixedStation> infos;
- public FixedStationEditor()
- {
- InitializeComponent();
- this.layoutControl1.UseDefault();
- this.Text = "固定站添加";
- info = new FixedStation();
- this.StartPosition = FormStartPosition.CenterParent;
- }
- public FixedStationEditor(FixedStation info)
- : this()
- {
- this.Text = "固定站编辑";
- this.info = info;
- }
- private async void SatEditor_Load(object sender, EventArgs e)
- {
- infos = new List<FixedStation>();
- List<SigInfo> sigs;
- using (RHDWContext db = new RHDWContext())
- {
- var res = await db.FixedStation.ToListAsync();
- infos.AddRange(res);
- sigs = await db.SigInfos.ToListAsync();
- if (sigs == null)
- sigs = new List<SigInfo>();
- this.txtFreqUp.UseDefault().SetData(sigs, nameof(SigInfo.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)
- {
- XdCxRhDW.Framework.LogHelper.Error("编辑固定站信息出错", ex);
- DxHelper.MsgBoxHelper.ShowError("编辑固定站信息出错");
- }
- }
- }
- }
|