123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- 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.Windows.Forms;
- using DataSimulation.Repostory;
- using DataSimulation.Repostory.EFContext;
- using DataSimulation.Repostory.Model;
- using DxHelper;
- namespace DataSimulation.Forms.EditForms
- {
- public partial class AntEditor : DevExpress.XtraEditors.XtraForm
- {
- public AntInfo info;
- public AntEditor()
- {
- InitializeComponent();
- this.layoutControl1.UseDefault();
- this.Text = "添加天线";
- info = new AntInfo();
- this.StartPosition = FormStartPosition.CenterParent;
- btnOk.ImageOptions.SvgImage = SvgHelper.LoadFromFile("Images\\Ok.svg");
- btnOk.ImageOptions.SvgImageSize = new Size(20, 20);
- btnCancel.ImageOptions.SvgImage = SvgHelper.LoadFromFile("Images\\Cancel.svg");
- btnCancel.ImageOptions.SvgImageSize = new Size(20, 20);
- txtAntLon.EditValueChanged += TxtAntLon_EditValueChanged;
- txtAntLat.EditValueChanged += TxtAntLat_EditValueChanged;
- }
- private void TxtAntLat_EditValueChanged(object sender, EventArgs e)
- {
- txtAntLat.CheckLat(dxErrorProvider, "天线");
- }
- private void TxtAntLon_EditValueChanged(object sender, EventArgs e)
- {
- txtAntLon.CheckLon(dxErrorProvider, "天线");
- }
- public AntEditor(AntInfo info)
- : this()
- {
- this.Text = "编辑天线";
- this.info = info;
- }
- private void AntEditor_Load(object sender, EventArgs e)
- {
- if (this.Text == "编辑天线" && info != null)
- {
- this.txtAntName.Text = info.AntName;
- this.txtAntLon.Text = $"{info.AntLon}";
- this.txtAntLat.Text = $"{info.AntLat}";
- }
- }
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.DialogResult = DialogResult.Cancel;
- }
- private async void btnOk_Click(object sender, EventArgs e)
- {
- if (!txtAntLon.CheckLon(dxErrorProvider, "天线") || !txtAntLat.CheckLat(dxErrorProvider, "天线"))
- {
- return;
- }
- try
- {
- info.AntName = txtAntName.Text.Trim();
- info.AntLon = Convert.ToDouble(txtAntLon.Text);
- info.AntLat = Convert.ToDouble(txtAntLat.Text);
- if (this.Text == "添加天线")
- {
- using (SimulationContext db = new SimulationContext())
- {
- bool isAny = db.AntInfos.Any(s => s.AntName == info.AntName && s.AntLon == info.AntLon && s.AntLat == info.AntLat);
- if (isAny)
- {
- DxHelper.MsgBoxHelper.ShowError($"添加天线信息失败,已经存在天线:{info.Ant}");
- return;
- }
- db.AntInfos.Add(info);
- await db.SaveChangesAsync();
- }
- }
- else
- {
- using (SimulationContext db = new SimulationContext())
- {
- bool isAny = db.AntInfos.Any(s => s.ID != info.ID && s.AntName == info.AntName && s.AntLon == info.AntLon && s.AntLat == info.AntLat);
- if (isAny)
- {
- DxHelper.MsgBoxHelper.ShowError($"编辑卫星信息失败,已经存在天线:{info.Ant}");
- return;
- }
- var find = await db.AntInfos.Where(p => p.ID == info.ID).FirstOrDefaultAsync();
- find.AntName = info.AntName;
- find.AntLon = info.AntLon;
- find.AntLat = info.AntLat;
- await db.SaveChangesAsync();
- }
- }
- this.DialogResult = DialogResult.OK;
- }
- catch (Exception ex)
- {
- Serilog.Log.Error(ex, $"{this.Text}信息出错");
- DxHelper.MsgBoxHelper.ShowError($"{this.Text}信息出错");
- }
- }
- }
- }
|