TargetEditor.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.App.EFContext;
  16. using XdCxRhDW.App.Model;
  17. namespace XdCxRhDW.App.EditForms
  18. {
  19. public partial class TargetEditor : DevExpress.XtraEditors.XtraForm
  20. {
  21. public TargetInfo info;
  22. List<TargetInfo> infos;
  23. public TargetEditor()
  24. {
  25. InitializeComponent();
  26. this.Text = "添加目标";
  27. info = new TargetInfo();
  28. this.StartPosition = FormStartPosition.CenterParent;
  29. }
  30. public TargetEditor(TargetInfo info)
  31. : this()
  32. {
  33. this.Text = "编辑目标";
  34. this.info = info;
  35. }
  36. private async void TargetEditor_Load(object sender, EventArgs e)
  37. {
  38. if (this.Text == "编辑目标" && info != null)
  39. {
  40. this.txtTarName.Text = info.TargetName;
  41. }
  42. infos = new List<TargetInfo>();
  43. using (RHDWContext db = new RHDWContext())
  44. {
  45. var res =await db.TargetInfos.ToListAsync();
  46. infos.AddRange(res);
  47. }
  48. }
  49. private void btnCancel_Click(object sender, EventArgs e)
  50. {
  51. this.DialogResult = DialogResult.Cancel;
  52. }
  53. private void btnOk_Click(object sender, EventArgs e)
  54. {
  55. try
  56. {
  57. string tarName=txtTarName.Text.Trim();
  58. if (string.IsNullOrWhiteSpace(tarName))
  59. {
  60. DxHelper.MsgBoxHelper.ShowError($"目标名称不能为空!");
  61. return;
  62. }
  63. if (infos.Any(i => i.ID != info.ID && i.TargetName == tarName))
  64. {
  65. DxHelper.MsgBoxHelper.ShowError($"目标名称[{tarName}]已经存在!");
  66. return;
  67. }
  68. info.TargetName = tarName;
  69. this.DialogResult = DialogResult.OK;
  70. }
  71. catch (Exception ex)
  72. {
  73. Serilog.Log.Error(ex,"编辑目标信息出错");
  74. DxHelper.MsgBoxHelper.ShowError("编辑目标信息出错");
  75. }
  76. }
  77. }
  78. }