using HStation.Dto; using HStation.WinFrmUI.Basic; using Mapster; using Newtonsoft.Json; using Yw.Dto; namespace HStation.WinFrmUI { public partial class EditProjectDlg : DevExpress.XtraEditors.XtraForm { public EditProjectDlg() { InitializeComponent(); } private UpdateXhsProjectInput _updatePrj = null; private UpdateXhsProjectItemInput _UpdateItem = null; public event Func> ReloadEvent = null; public async void SetBindingData(long ID) { var model = await new BLL.XhsProject().GetByID(ID); _updatePrj = model.Adapt(); this.NameTextEdit.Text = _updatePrj.Name; this.TagNameText.Text = _updatePrj.TagName; this.CustomerNameTextEdit.Text = _updatePrj.CustomerName; this.DescriptionTextEdit.Text = _updatePrj.Description; if (string.IsNullOrEmpty(_updatePrj.Address)) { this.dxErrorProvider1.SetError(this.AddressTextEdit, "地址为空"); } this.AddressTextEdit.Text = _updatePrj.Address; } //验证 private bool Valid() { this.dxErrorProvider1.ClearErrors(); if (string.IsNullOrEmpty(this.NameTextEdit.Text.Trim())) { this.dxErrorProvider1.SetError(this.NameTextEdit, "必填项"); return false; } return true; } //确定 private async void btnOk_Click(object sender, EventArgs e) { if (!Valid()) return; _updatePrj.Name = this.NameTextEdit.Text.Trim(); _updatePrj.TagName = this.TagNameText.Text.Trim(); _updatePrj.CustomerName = this.CustomerNameTextEdit.Text.Trim(); _updatePrj.Description = this.DescriptionTextEdit.Text.Trim(); _updatePrj.Address = this.AddressTextEdit.Text.Trim(); var itemDto = await new BLL.XhsProjectItem().GetByPrjID(_updatePrj.ID); _UpdateItem = itemDto.Adapt(); _UpdateItem.Name = _updatePrj.Name; _UpdateItem.TagName = _updatePrj.TagName; _UpdateItem.UseStatus = _updatePrj.UseStatus; if (await this.ReloadEvent.Invoke(_updatePrj, _UpdateItem)) { MessageBoxHelper.ShowSuccess("编辑成功!"); } else { MessageBoxHelper.ShowError("编辑失败!"); } this.DialogResult = DialogResult.OK; this.Close(); } private void EditProjectDlg_Load(object sender, EventArgs e) { this.webView21.Source = new Uri(AppDomain.CurrentDomain.BaseDirectory + "data/web/html/map_select.html"); } private void webView21_WebMessageReceived(object sender, Microsoft.Web.WebView2.Core.CoreWebView2WebMessageReceivedEventArgs e) { var j = JsonConvert.DeserializeObject(e.WebMessageAsJson); switch (j.Oper) { case "getLocation": var o = JsonConvert.DeserializeObject(j.Json); if (o == null) break; this.AddressTextEdit.Text = o.address; _updatePrj.Address = o.address; _updatePrj.MapPosition = o.location.lng + "," + o.location.lat; break; } } private void SetMaker() { try { var message = new { oper = "setMarker", data = JsonConvert.SerializeObject(new { loc = _updatePrj.MapPosition, name = _updatePrj.Address }) }; var json = JsonConvert.SerializeObject(message); webView21.CoreWebView2.PostWebMessageAsJson(json); } catch (Exception error) { throw error; } } private void webView21_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e) { SetMaker(); } } }