SatEditor.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.Windows.Forms;
  11. using DataSimulation.Repostory;
  12. using DataSimulation.Repostory.EFContext;
  13. using DataSimulation.Repostory.Model;
  14. namespace DataSimulation.Forms.EditForms
  15. {
  16. public partial class SatEditor : DevExpress.XtraEditors.XtraForm
  17. {
  18. public SatInfo info;
  19. public SatEditor()
  20. {
  21. InitializeComponent();
  22. this.layoutControl1.UseDefault();
  23. this.Text = "添加卫星";
  24. info = new SatInfo();
  25. this.StartPosition = FormStartPosition.CenterParent;
  26. }
  27. public SatEditor(SatInfo info)
  28. : this()
  29. {
  30. this.Text = "编辑卫星";
  31. this.info = info;
  32. }
  33. private async void SatEditor_Load(object sender, EventArgs e)
  34. {
  35. var listXl = await XlCache.GetAllAsync();
  36. this.searchLookUpEdit1.UseDefault().SetStringData(listXl.Select(p=>p.Sat)).UseDoubleClickToSelectAll();
  37. if (this.Text == "编辑卫星" && info != null)
  38. {
  39. this.txtSatName.Text = info.SatName;
  40. this.txtSatLon.Text = info.SatLon.ToString();
  41. }
  42. }
  43. private void btnCancel_Click(object sender, EventArgs e)
  44. {
  45. this.DialogResult = DialogResult.Cancel;
  46. }
  47. private void btnOk_Click(object sender, EventArgs e)
  48. {
  49. try
  50. {
  51. var sat = searchLookUpEdit1.Text;
  52. var idx = sat.LastIndexOf('(');
  53. var satCodeStr = sat.Substring(idx + 1, sat.Length - idx - 2);
  54. info.SatCode = Convert.ToInt32(satCodeStr);
  55. info.SatName = txtSatName.Text.Trim();
  56. if (!string.IsNullOrWhiteSpace(txtSatLon.Text))
  57. info.SatLon = Convert.ToDouble(txtSatLon.Text);
  58. this.DialogResult = DialogResult.OK;
  59. }
  60. catch (Exception ex)
  61. {
  62. Serilog.Log.Error(ex, "编辑卫星信息出错");
  63. DxHelper.MsgBoxHelper.ShowError("编辑卫星信息出错");
  64. }
  65. }
  66. }
  67. }