using DevExpress.XtraBars.Customization; using DevExpress.XtraEditors; using ExtensionsDev; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Documents; using System.Windows.Forms; using DW5S.Entity; using DW5S.Repostory; using Serilog; using DW5S.Service; using DW5S.ViewModel; namespace DW5S.App.EditForms { public partial class TargetEditor : DevExpress.XtraEditors.XtraForm { public TargetViewModel info; List infos; public TargetEditor() { InitializeComponent(); this.layoutControl1.UseDefault(); this.Text = "添加目标"; info = new TargetViewModel(); this.StartPosition = FormStartPosition.CenterParent; } public TargetEditor(TargetViewModel info) : this() { this.Text = "编辑目标"; this.info = info; } private async void TargetEditor_Load(object sender, EventArgs e) { if (this.Text == "编辑目标" && info != null) { this.txtTarName.Text = info.TargetName; var clolrRes = ColorTranslator.FromHtml(info.TargeColor); this.txtTarColor.EditValue = clolrRes; } infos = new List(); var unitOfWork = IocContainer.UnitOfWork; var repsTarget = unitOfWork.Of(); var res = await repsTarget.GetAllAsync(); infos.AddRange(res.To>()); } private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } private void btnOk_Click(object sender, EventArgs e) { try { string tarName = txtTarName.Text.Trim(); if (string.IsNullOrWhiteSpace(tarName)) { DxHelper.MsgBoxHelper.ShowError($"目标名称不能为空!"); return; } if (infos.Any(i => i.Id != info.Id && i.TargetName == tarName)) { DxHelper.MsgBoxHelper.ShowError($"目标名称[{tarName}]已经存在!"); return; } info.TargetName = tarName; info.TargeColor = ColorTranslator.ToHtml(txtTarColor.Color); this.DialogResult = DialogResult.OK; } catch (Exception ex) { string msg = "编辑目标信息出错"; IocContainer.Logger.Error(ex, msg); DxHelper.MsgBoxHelper.ShowError(msg); } } } }