TargetEditor.cs 2.5 KB

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