TargetEditor.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.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 DW5S.Entity;
  15. using DW5S.Repostory;
  16. namespace DW5S.App.EditForms
  17. {
  18. public partial class TargetEditor : DevExpress.XtraEditors.XtraForm
  19. {
  20. public TargetInfo info;
  21. List<TargetInfo> infos;
  22. public TargetEditor()
  23. {
  24. InitializeComponent();
  25. this.layoutControl1.UseDefault();
  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. var clolrRes = ColorTranslator.FromHtml(info.TargeColor);
  42. this.txtTarColor.EditValue = clolrRes;
  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. info.TargeColor=ColorTranslator.ToHtml(txtTarColor.Color);
  72. this.DialogResult = DialogResult.OK;
  73. }
  74. catch (Exception ex)
  75. {
  76. DW5S.Framework.LogHelper.Error("编辑目标信息出错", ex);
  77. DxHelper.MsgBoxHelper.ShowError("编辑目标信息出错");
  78. }
  79. }
  80. }
  81. }