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