1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using DevExpress.XtraEditors;
- using ExtensionsDev;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.Entity;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Documents;
- using System.Windows.Forms;
- using XdCxRhDW.Entity;
- using XdCxRhDW.Repostory;
- namespace XdCxRhDW.App.EditForms
- {
- public partial class EditorTar : DevExpress.XtraEditors.XtraForm
- {
- public TargetInfo info;
- List<TargetInfo> infos;
- public EditorTar(TargetInfo info)
- {
- InitializeComponent();
- this.layoutControl1.UseDefault();
- this.Text = "编辑目标";
- this.info = info;
- this.StartPosition = FormStartPosition.CenterParent;
- }
- private async void SatEditor_Load(object sender, EventArgs e)
- {
- infos = new List<TargetInfo>();
- using (RHDWContext db = new RHDWContext())
- {
- var res = await db.TargetInfos.OrderBy(p => p.TargetName).ToListAsync();
- infos.AddRange(res);
- }
- this.searchLookUpEdit1.UseDefault().SetData(infos,nameof(TargetInfo.TargetName)).UseDoubleClickToSelectAll();
- this.searchLookUpEdit1.Properties.View.RowCellStyle += View_RowCellStyle;
- if (info != null)
- {
- this.searchLookUpEdit1.Text = info.TargetName;
- }
- }
- private void View_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
- {
- if (e.CellValue == null) return;
- if (e.Column.FieldName == nameof(TargetInfo.TargeColor))
- {
- var clolrRes = ColorTranslator.FromHtml(e.CellValue.ToString());
- e.Appearance.BackColor = clolrRes;
- }
- }
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.DialogResult = DialogResult.Cancel;
- }
- private void btnOk_Click(object sender, EventArgs e)
- {
- try
- {
- info = new TargetInfo();
- var tar = searchLookUpEdit1.EditValue as TargetInfo;
- if (tar != null)
- {
- info.ID = tar.ID;
- info.TargetName = tar.TargetName;
- info.TargeColor=tar.TargeColor;
- }
- else
- {
- info.ID = 0;
- info.TargetName = "未知目标";
- info.TargeColor = "";
- }
- this.DialogResult = DialogResult.OK;
- }
- catch (Exception ex)
- {
- XdCxRhDW.Framework.LogHelper.Error("编辑目标出错", ex);
- DxHelper.MsgBoxHelper.ShowError("编辑目标出错");
- }
- }
- }
- }
|