EditorTar.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Documents;
  12. using System.Windows.Forms;
  13. using DW5S.Entity;
  14. using DW5S.Repostory;
  15. namespace DW5S.App.EditForms
  16. {
  17. public partial class EditorTar : DevExpress.XtraEditors.XtraForm
  18. {
  19. public TargetInfo info;
  20. List<TargetInfo> infos;
  21. public EditorTar(TargetInfo info)
  22. {
  23. InitializeComponent();
  24. this.layoutControl1.UseDefault();
  25. this.Text = "编辑目标";
  26. this.info = info;
  27. this.StartPosition = FormStartPosition.CenterParent;
  28. }
  29. private async void SatEditor_Load(object sender, EventArgs e)
  30. {
  31. infos = new List<TargetInfo>();
  32. using (RHDWContext db = new RHDWContext())
  33. {
  34. var res = await db.TargetInfos.OrderBy(p => p.TargetName).ToListAsync();
  35. infos.AddRange(res);
  36. }
  37. this.searchLookUpEdit1.UseDefault().SetData(infos,nameof(TargetInfo.TargetName)).UseDoubleClickToSelectAll();
  38. this.searchLookUpEdit1.Properties.View.RowCellStyle += View_RowCellStyle;
  39. if (info != null)
  40. {
  41. this.searchLookUpEdit1.Text = info.TargetName;
  42. }
  43. }
  44. private void View_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
  45. {
  46. if (e.CellValue == null) return;
  47. if (e.Column.FieldName == nameof(TargetInfo.TargeColor))
  48. {
  49. var clolrRes = ColorTranslator.FromHtml(e.CellValue.ToString());
  50. e.Appearance.BackColor = clolrRes;
  51. }
  52. }
  53. private void btnCancel_Click(object sender, EventArgs e)
  54. {
  55. this.DialogResult = DialogResult.Cancel;
  56. }
  57. private void btnOk_Click(object sender, EventArgs e)
  58. {
  59. try
  60. {
  61. info = new TargetInfo();
  62. var tar = searchLookUpEdit1.EditValue as TargetInfo;
  63. if (tar != null)
  64. {
  65. info.ID = tar.ID;
  66. info.TargetName = tar.TargetName;
  67. info.TargeColor=tar.TargeColor;
  68. }
  69. else
  70. {
  71. info.ID = 0;
  72. info.TargetName = "未知目标";
  73. info.TargeColor = "";
  74. }
  75. this.DialogResult = DialogResult.OK;
  76. }
  77. catch (Exception ex)
  78. {
  79. DW5S.Framework.LogHelper.Error("编辑目标出错", ex);
  80. DxHelper.MsgBoxHelper.ShowError("编辑目标出错");
  81. }
  82. }
  83. }
  84. }