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 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(); var unitOfWork = IocContainer.UnitOfWork; var repsFixed = unitOfWork.Of(); var res = await repsFixed.GetAllAsync(); infos.AddRange(res.To>()); var repsSig = unitOfWork.Of(); var sigs = await repsSig.GetAllAsync(); var sigsData = sigs.To>(); this.txtFreqUp.UseDefault().SetData(sigsData, 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 = sigsData.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 SigViewModel).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); } } } }