TargetEditor.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using DevExpress.XtraBars.Customization;
  2. using DevExpress.XtraEditors;
  3. using ExtensionsDev;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Data.Entity;
  9. using System.Drawing;
  10. using System.Linq;
  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. using XdCxRhDW.Repostory.Model;
  18. namespace XdCxRhDW.App.EditForms
  19. {
  20. public partial class TargetEditor : DevExpress.XtraEditors.XtraForm
  21. {
  22. public TargetInfo info;
  23. List<TargetInfo> infos;
  24. public TargetEditor()
  25. {
  26. InitializeComponent();
  27. this.layoutControl1.UseDefault();
  28. this.Text = "添加目标";
  29. info = new TargetInfo();
  30. this.StartPosition = FormStartPosition.CenterParent;
  31. }
  32. public TargetEditor(TargetInfo info)
  33. : this()
  34. {
  35. this.Text = "编辑目标";
  36. this.info = info;
  37. }
  38. private async void TargetEditor_Load(object sender, EventArgs e)
  39. {
  40. if (this.Text == "编辑目标" && info != null)
  41. {
  42. this.txtTarName.Text = info.TargetName;
  43. }
  44. infos = new List<TargetInfo>();
  45. using (RHDWContext db = new RHDWContext())
  46. {
  47. var res =await db.TargetInfos.ToListAsync();
  48. infos.AddRange(res);
  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. string tarName=txtTarName.Text.Trim();
  60. if (string.IsNullOrWhiteSpace(tarName))
  61. {
  62. DxHelper.MsgBoxHelper.ShowError($"目标名称不能为空!");
  63. return;
  64. }
  65. if (infos.Any(i => i.ID != info.ID && i.TargetName == tarName))
  66. {
  67. DxHelper.MsgBoxHelper.ShowError($"目标名称[{tarName}]已经存在!");
  68. return;
  69. }
  70. info.TargetName = tarName;
  71. this.DialogResult = DialogResult.OK;
  72. }
  73. catch (Exception ex)
  74. {
  75. Serilog.Log.Error(ex,"编辑目标信息出错");
  76. DxHelper.MsgBoxHelper.ShowError("编辑目标信息出错");
  77. }
  78. }
  79. }
  80. }