CDBSatEditor.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.Entity;
  16. using XdCxRhDW.Repostory;
  17. namespace XdCxRhDW.App.EditForms
  18. {
  19. public partial class CDBSatEditor : DevExpress.XtraEditors.XtraForm
  20. {
  21. public CDBSatInfo info;
  22. private List<CDBSatInfo> infos;
  23. public CDBSatEditor()
  24. {
  25. InitializeComponent();
  26. this.layoutControl1.UseDefault();
  27. this.Text = "添加超短波卫星";
  28. info = new CDBSatInfo();
  29. this.StartPosition = FormStartPosition.CenterParent;
  30. }
  31. public CDBSatEditor(CDBSatInfo info)
  32. : this()
  33. {
  34. this.Text = "编辑超短波卫星";
  35. this.info = info;
  36. }
  37. private async void SatEditor_Load(object sender, EventArgs e)
  38. {
  39. infos = new List<CDBSatInfo>();
  40. using (RHDWContext db = new RHDWContext())
  41. {
  42. var res = await db.CDBSatInfos.ToListAsync();
  43. infos.AddRange(res);
  44. }
  45. if (this.Text == "编辑超短波卫星" && info != null)
  46. {
  47. this.txtSatName.Text = info.SatName;
  48. this.txtSatCode.EditValue = info.SatCode;
  49. }
  50. }
  51. private void btnCancel_Click(object sender, EventArgs e)
  52. {
  53. this.DialogResult = DialogResult.Cancel;
  54. }
  55. private void btnOk_Click(object sender, EventArgs e)
  56. {
  57. try
  58. {
  59. var satCode = Convert.ToInt32(txtSatCode.Text);
  60. if (infos.Any(i => i.ID != info.ID && i.SatCode == satCode))
  61. {
  62. DxHelper.MsgBoxHelper.ShowError($"超短波卫星[{satCode}]已经存在!");
  63. return;
  64. }
  65. info.SatCode = satCode;
  66. info.SatName = txtSatName.Text.Trim();
  67. this.DialogResult = DialogResult.OK;
  68. }
  69. catch (Exception ex)
  70. {
  71. XdCxRhDW.Framework.LogHelper.Error( "编辑超短波卫星信息出错", ex);
  72. DxHelper.MsgBoxHelper.ShowError("编辑超短波卫星信息出错");
  73. }
  74. }
  75. }
  76. }