EditorTar.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. this.searchLookUpEdit1.Text = info.TargetName;
  42. }
  43. private void View_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
  44. {
  45. if (e.CellValue == null) return;
  46. if (e.Column.FieldName == nameof(TargetInfo.TargeColor))
  47. {
  48. var clolrRes = ColorTranslator.FromHtml(e.CellValue.ToString());
  49. e.Appearance.BackColor = clolrRes;
  50. }
  51. }
  52. private void btnCancel_Click(object sender, EventArgs e)
  53. {
  54. this.DialogResult = DialogResult.Cancel;
  55. }
  56. private void btnOk_Click(object sender, EventArgs e)
  57. {
  58. try
  59. {
  60. info = new TargetInfo();
  61. var tar = searchLookUpEdit1.EditValue as TargetInfo;
  62. if (tar != null)
  63. {
  64. info.ID = tar.ID;
  65. info.TargetName = tar.TargetName;
  66. info.TargeColor=tar.TargeColor;
  67. }
  68. else
  69. {
  70. info.ID = 0;
  71. info.TargetName = "未知目标";
  72. info.TargeColor = "";
  73. }
  74. this.DialogResult = DialogResult.OK;
  75. }
  76. catch (Exception ex)
  77. {
  78. Serilog.Log.Error(ex, "编辑目标出错");
  79. DxHelper.MsgBoxHelper.ShowError("编辑目标出错");
  80. }
  81. }
  82. }
  83. }