EditorTar.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 XdCxRhDW.Entity;
  15. using XdCxRhDW.Repostory;
  16. namespace XdCxRhDW.App.EditForms
  17. {
  18. public partial class EditorTar : DevExpress.XtraEditors.XtraForm
  19. {
  20. public TargetInfo info;
  21. List<TargetInfo> infos;
  22. public EditorTar(TargetInfo info)
  23. {
  24. InitializeComponent();
  25. this.layoutControl1.UseDefault();
  26. this.Text = "编辑目标";
  27. this.info = info;
  28. this.StartPosition = FormStartPosition.CenterParent;
  29. }
  30. private async void SatEditor_Load(object sender, EventArgs e)
  31. {
  32. infos = new List<TargetInfo>();
  33. using (RHDWContext db = new RHDWContext())
  34. {
  35. var res = await db.TargetInfos.OrderBy(p => p.TargetName).ToListAsync();
  36. infos.AddRange(res);
  37. }
  38. this.searchLookUpEdit1.UseDefault().SetData(infos,nameof(TargetInfo.TargetName)).UseDoubleClickToSelectAll();
  39. if (info != null)
  40. this.searchLookUpEdit1.Text = info.TargetName;
  41. }
  42. private void btnCancel_Click(object sender, EventArgs e)
  43. {
  44. this.DialogResult = DialogResult.Cancel;
  45. }
  46. private void btnOk_Click(object sender, EventArgs e)
  47. {
  48. try
  49. {
  50. info = new TargetInfo();
  51. var tar = searchLookUpEdit1.EditValue as TargetInfo;
  52. if (tar != null)
  53. {
  54. info.ID = tar.ID;
  55. info.TargetName = tar.TargetName;
  56. }
  57. else
  58. {
  59. info.ID = 0;
  60. info.TargetName = "未知目标";
  61. }
  62. this.DialogResult = DialogResult.OK;
  63. }
  64. catch (Exception ex)
  65. {
  66. Serilog.Log.Error(ex, "编辑目标出错");
  67. DxHelper.MsgBoxHelper.ShowError("编辑目标出错");
  68. }
  69. }
  70. }
  71. }