SatEditor.cs 2.6 KB

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