using DevExpress.XtraEditors;
using NPOI.OpenXmlFormats.Dml;
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.Forms;
namespace HStation.WinFrmUI
{
public partial class SetXhsProjectMapDlg : DevExpress.XtraEditors.XtraForm
{
public SetXhsProjectMapDlg()
{
InitializeComponent();
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
this.layoutControl1.SetupLayoutControl();
this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
this.mapSetSimpleMarkerContainer1.LoadCompletedEvent += MapSetSimpleMarkerContainer1_LoadCompletedEvent;
this.mapSetSimpleMarkerContainer1.SetMarkerEvent += MapSetSimpleMarkerContainer1_SetMarkerEvent;
}
///
///
///
public event Action ReloadDataEvent;
private XhsProjectExtensionsVmo _project = null;//项目信息
private Yw.Vmo.MapInfoVmo _mapinfo = null; //地图信息
private Yw.Model.Map.Marker _maker = null; //地图点信息
///
/// 绑定数据
///
public async void SetBindingData(XhsProjectExtensionsVmo project, Yw.Vmo.MapInfoVmo mapInfo)
{
if (project == null)
{
return;
}
_project = project;
_mapinfo = mapInfo;
if (_mapinfo == null)
{
_mapinfo.ObjectType = HStation.Xhs.DataType.XhsProject;
_mapinfo.ObjectID = _project.ID;
_mapinfo.ObjectName = _project.Name;
_mapinfo.Purpose = Yw.Map.Purpose.Location;
_mapinfo.Kind = Yw.Map.Kind.Gaodei;
_mapinfo.Shape = Yw.Map.Shape.Marker;
}
if (mapInfo != null)
{
_maker = Yw.Model.Map.Marker.ToModel(_mapinfo.Position);
}
await this.mapSetSimpleMarkerContainer1.InitialContainer();
this.txtAddress.EditValue = _project.Address;
if (string.IsNullOrEmpty(_project.Address))
{
if (_maker != null)
{
this.txtAddress.EditValue = _maker.Address;
}
}
}
//加载完成事件
private async void MapSetSimpleMarkerContainer1_LoadCompletedEvent()
{
if (_maker != null)
{
await this.mapSetSimpleMarkerContainer1.LoadMarker(_maker);
}
}
//设置
private void MapSetSimpleMarkerContainer1_SetMarkerEvent(Yw.Model.Map.Marker obj)
{
_maker = obj;
if (string.IsNullOrEmpty(this.txtAddress.Text.Trim()))
{
this.txtAddress.EditValue = obj.Address;
}
}
//确定
private async void GeneralOkAndCancelCtrl1_OkEvent()
{
if (_project == null)
{
return;
}
if (_mapinfo == null)
{
return;
}
if (_maker == null)
{
TipFormHelper.ShowWarn("请设置地图位置!");
return;
}
var address = this.txtAddress.Text.Trim();
if (!string.IsNullOrEmpty(address))
{
_project.Address = this.txtAddress.Text.Trim();
var bol = await BLLFactory.Instance.Update(_project);
if (!bol)
{
TipFormHelper.ShowError("地址更新失败!");
return;
}
}
_mapinfo.Position = _maker.ToJson();
if (_mapinfo.ID < 1)
{
_mapinfo.ID = await BLLFactory.Instance.Insert(_mapinfo);
if (_mapinfo.ID < 1)
{
TipFormHelper.ShowError("地图位置设置失败!");
return;
}
}
else
{
var bol = await BLLFactory.Instance.Update(_mapinfo);
if (!bol)
{
TipFormHelper.ShowError("地图位置设置失败!");
return;
}
}
var mapInfo = await BLLFactory.Instance.GetByID(_mapinfo.ID);
this.ReloadDataEvent?.Invoke(_project, mapInfo);
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}