SatEditor.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using DevExpress.XtraEditors;
  2. using ExtensionsDev;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Data.Entity;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Documents;
  13. using System.Windows.Forms;
  14. using XdDw.App.EFContext;
  15. using XzXdDw.App.Model;
  16. namespace XdDw.App.EditForms
  17. {
  18. public partial class SatEditor : DevExpress.XtraEditors.XtraForm
  19. {
  20. public SatInfo info;
  21. public SatEditor()
  22. {
  23. InitializeComponent();
  24. this.Text = "添加卫星";
  25. info = new SatInfo();
  26. this.StartPosition = FormStartPosition.CenterParent;
  27. }
  28. public SatEditor(SatInfo info)
  29. : this()
  30. {
  31. this.Text = "编辑卫星";
  32. this.info = info;
  33. }
  34. private async void SatEditor_Load(object sender, EventArgs e)
  35. {
  36. List<string> list = new List<string>();
  37. using (RHDWContext db = new RHDWContext())
  38. {
  39. var res = await db.XlInfos.OrderBy(p => p.SatName).ToListAsync();
  40. if (res != null)
  41. list.AddRange(res.Select(p=>p.Sat));
  42. }
  43. this.searchLookUpEdit1.UseDefault().SetStringData(list).UseDoubleClickToSelectAll();
  44. if (this.Text == "编辑卫星" && info != null)
  45. {
  46. this.txtSatName.Text = info.SatName;
  47. this.txtSatLon.Text = info.SatLon.ToString();
  48. }
  49. }
  50. private void btnCancel_Click(object sender, EventArgs e)
  51. {
  52. this.DialogResult = DialogResult.Cancel;
  53. }
  54. private void btnOk_Click(object sender, EventArgs e)
  55. {
  56. try
  57. {
  58. var sat = searchLookUpEdit1.Text;
  59. var idx = sat.LastIndexOf('(');
  60. var satCodeStr = sat.Substring(idx+1, sat.Length - idx - 2);
  61. info.SatCode = Convert.ToInt32(satCodeStr);
  62. info.SatName = txtSatName.Text.Trim();
  63. if (!string.IsNullOrWhiteSpace(txtSatLon.Text))
  64. info.SatLon = Convert.ToDouble(txtSatLon.Text);
  65. this.DialogResult = DialogResult.OK;
  66. }
  67. catch (Exception ex)
  68. {
  69. XtraMessageBox.Show(ex.Message);
  70. }
  71. }
  72. }
  73. }