1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- 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.Text;
- using System.Threading.Tasks;
- using System.Windows.Documents;
- using System.Windows.Forms;
- using XdDw.App.EFContext;
- using XzXdDw.App.Model;
- namespace XdDw.App.EditForms
- {
- public partial class SatEditor : DevExpress.XtraEditors.XtraForm
- {
- public SatInfo info;
- public SatEditor()
- {
- InitializeComponent();
- this.Text = "添加卫星";
- info = new SatInfo();
- this.StartPosition = FormStartPosition.CenterParent;
- }
- public SatEditor(SatInfo info)
- : this()
- {
- this.Text = "编辑卫星";
- this.info = info;
- }
- private async void SatEditor_Load(object sender, EventArgs e)
- {
- List<string> list = new List<string>();
- using (RHDWContext db = new RHDWContext())
- {
- var res = await db.XlInfos.OrderBy(p => p.SatName).ToListAsync();
- if (res != null)
- list.AddRange(res.Select(p=>p.Sat));
- }
- this.searchLookUpEdit1.UseDefault().SetStringData(list).UseDoubleClickToSelectAll();
- if (this.Text == "编辑卫星" && info != null)
- {
- this.txtSatName.Text = info.SatName;
- this.txtSatLon.Text = info.SatLon.ToString();
- }
- }
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.DialogResult = DialogResult.Cancel;
- }
- private void btnOk_Click(object sender, EventArgs e)
- {
- try
- {
- var sat = searchLookUpEdit1.Text;
- var idx = sat.LastIndexOf('(');
- var satCodeStr = sat.Substring(idx+1, sat.Length - idx - 2);
- info.SatCode = Convert.ToInt32(satCodeStr);
- info.SatName = txtSatName.Text.Trim();
- if (!string.IsNullOrWhiteSpace(txtSatLon.Text))
- info.SatLon = Convert.ToDouble(txtSatLon.Text);
- this.DialogResult = DialogResult.OK;
- }
- catch (Exception ex)
- {
- XtraMessageBox.Show(ex.Message);
- }
- }
- }
- }
|