using DevExpress.Data.Browsing; using DevExpress.Utils.Gesture; using DevExpress.XtraEditors; using DevExpress.XtraTreeList; 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 SigDelayEditor : DevExpress.XtraEditors.XtraForm { public SigDelay info; public int sigId; public SigDelayEditor(int sigId) { InitializeComponent(); this.layoutControl1.UseDefault(); this.Text = "添加转发延迟"; info = new SigDelay(); this.StartPosition = FormStartPosition.CenterParent; this.sigId = sigId; } public SigDelayEditor(SigDelay info, int sigId) : this(sigId) { this.Text = "编辑转发延迟"; this.info = info; this.sigId = sigId; } private async void SatEditor_Load(object sender, EventArgs e) { using (RHDWContext db = new RHDWContext()) { var sats = await db.SatInfos.ToListAsync(); this.txtSat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll(); if (this.Text == "编辑转发延迟" && info != null) { this.txtSat.EditValue = sats.FirstOrDefault(f=>f.SatCode== info.SatInfoSatCode); this.txtDelay.EditValue = info.Delay; } } } private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } private async void btnOk_Click(object sender, EventArgs e) { try { dxErrorProvider.ClearErrors(); if (txtSat.EditValue == null) { dxErrorProvider.SetError(txtSat, "请选择卫星"); return; } if (txtDelay.EditValue == null) { dxErrorProvider.SetError(txtDelay, "请输入转发延迟"); return; } var satInfo = (SatInfo)txtSat.EditValue; using (RHDWContext db = new RHDWContext()) { var list = await db.SigDelays.Where(w => w.SigInfoId == sigId).ToListAsync(); if (list.Where(w => w.ID != info.ID).Any(a => a.SatInfoSatCode == satInfo.SatCode)) { DxHelper.MsgBoxHelper.ShowInfo("已添加该卫星"); return; } } info.SigInfoId = sigId; info.SatInfoSatCode = satInfo.SatCode; info.Sat = $"[{satInfo.SatLon}°]{satInfo.SatName}({satInfo.SatCode})"; info.Delay = Convert.ToDouble(txtDelay.EditValue); this.DialogResult = DialogResult.OK; } catch (Exception ex) { XdCxRhDW.Framework.LogHelper.Error("编辑转发延迟出错", ex); DxHelper.MsgBoxHelper.ShowError("编辑转发延迟出错"); } } } }