ningshuxia
2025-03-26 6171f94b5ca6c804ac2892d214943ff0ac400d26
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public event Action<XhsProjectExtensionsVmo, Yw.Vmo.MapInfoVmo> ReloadDataEvent;
 
        private XhsProjectExtensionsVmo _project = null;//项目信息
        private Yw.Vmo.MapInfoVmo _mapinfo = null; //地图信息
        private Yw.Model.Map.Marker _maker = null; //地图点信息
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        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<HStation.BLL.XhsProjectExtensions>.Instance.Update(_project);
                if (!bol)
                {
                    TipFormHelper.ShowError("地址更新失败!");
                    return;
                }
            }
 
            _mapinfo.Position = _maker.ToJson();
            if (_mapinfo.ID < 1)
            {
                _mapinfo.ID = await BLLFactory<Yw.BLL.MapInfo>.Instance.Insert(_mapinfo);
                if (_mapinfo.ID < 1)
                {
                    TipFormHelper.ShowError("地图位置设置失败!");
                    return;
                }
            }
            else
            {
                var bol = await BLLFactory<Yw.BLL.MapInfo>.Instance.Update(_mapinfo);
                if (!bol)
                {
                    TipFormHelper.ShowError("地图位置设置失败!");
                    return;
                }
            }
 
            var mapInfo = await BLLFactory<Yw.BLL.MapInfo>.Instance.GetByID(_mapinfo.ID);
            this.ReloadDataEvent?.Invoke(_project, mapInfo);
 
            this.DialogResult = DialogResult.OK;
            this.Close();
 
        }
 
    }
}