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.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 Microsoft.Extensions.Logging; using Serilog.Core; namespace DW5S.App.EditForms { public partial class SigDelayEditor : DevExpress.XtraEditors.XtraForm { [Autowired] private readonly ILogger logger; [Autowired] private readonly UnitOfWork unitOfWork; 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) { var repsSat = unitOfWork.Reps(); var sats = await repsSat.GetAllAsync(); 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; var repsSigDelay = unitOfWork.Reps(); var list = await repsSigDelay.FindAsync(w => w.SigInfoId == sigId); 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) { string msg = "编辑转发延迟出错"; logger.LogError(ex, msg); DxHelper.MsgBoxHelper.ShowError(msg); } } } }