EditorTar.cs 3.0 KB

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