duheng
2024-04-15 154d4c352b9ab06a925451f1fdcea6afd1701e10
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
137
138
139
using DevExpress.Utils.Extensions;
using DevExpress.XtraEditors;
using ISupply.Model;
using ISupply.WinFrm.Main._UserControls;
 
namespace ISupply.WinFrm.Main.Buildings
{
    public partial class EditBuildingForm : DevExpress.XtraEditors.XtraForm
    {
        public EditBuildingForm(Model.Building building)
        {
            InitializeComponent();
            this._building = building;
            LoadForm();
            this.webView.Source = new Uri(AppDomain.CurrentDomain.BaseDirectory + "/web/html/map_select.html");
            this.webView.WebMessageReceived += WebView21_WebMessageReceived;
            this.webView.NavigationCompleted += WebView21_NavigationCompleted;
        }
        private BuildBaseModel _buildBaseModel;
        private BuildWizardForm _buildWizardForm = new BuildWizardForm();
        private HospitalWizardForm _hospitalWizardForm = new HospitalWizardForm();
        private SchoolWizardForm _schoolWizardForm = new SchoolWizardForm();
        private ShopWizardForm _shopWizardForm = new ShopWizardForm();
        private Model.Building _building;
 
        private void LoadForm()
        {
            this.panelControl1.Controls.Clear();
            switch (_building.BuildingTypeID)
            {
                case 5:
                    this._buildWizardForm.Dock = DockStyle.Fill;
                    this.panelControl1.AddControl(this._buildWizardForm);
                    this._buildBaseModel = Yw.JsonHelper.Json2Object<BuildFormModel>(_building.FormJson);
                    this._buildWizardForm.SetData((BuildFormModel)this._buildBaseModel);
                    break;
                case 1:
                    this._shopWizardForm.Dock = DockStyle.Fill;
                    this.panelControl1.AddControl(this._shopWizardForm);
                    this._buildBaseModel = Yw.JsonHelper.Json2Object<ShopFormModel>(_building.FormJson);
                    this._shopWizardForm.SetData((ShopFormModel)this._buildBaseModel);
                    break;
                case 1749326578128654336:
                    this._hospitalWizardForm.Dock = DockStyle.Fill;
                    this.panelControl1.AddControl(this._hospitalWizardForm);
                    this._buildBaseModel = Yw.JsonHelper.Json2Object<HospitalFormModel>(_building.FormJson);
                    this._hospitalWizardForm.SetData((HospitalFormModel)this._buildBaseModel);
                    break;
                case 1749326605509070848:
                    this._schoolWizardForm.Dock = DockStyle.Fill;
                    this.panelControl1.AddControl(this._schoolWizardForm);
                    this._buildBaseModel = Yw.JsonHelper.Json2Object<SchoolFormModel>(_building.FormJson);
                    this._schoolWizardForm.SetData((SchoolFormModel)this._buildBaseModel);
                    break;
            }
            this.TxtMemoEdit.EditValue = this._building.Description;
        }
 
 
 
        private void btnOk_Click(object sender, EventArgs e)
        {
            this.Hide();
            switch (_building.BuildingTypeID)
            {
                case 5:
                    this._buildBaseModel = this._buildWizardForm.GetData();
                    break;
                case 1:
                    this._buildBaseModel = this._shopWizardForm.GetData();
                    break;
                case 1749326578128654336:
 
                    this._buildBaseModel = this._hospitalWizardForm.GetData();
                    break;
                case 1749326605509070848:
 
                    this._buildBaseModel = this._schoolWizardForm.GetData();
                    break;
            }
            this._building.Name = this._buildBaseModel.Name;
            this._building.Address = this._buildBaseModel.Address;
            this._building.FormJson = Yw.JsonHelper.Object2Json(this._buildBaseModel);
            this._building.Description = this.TxtMemoEdit.EditValue.ToString();
            new BLL.Building().Update(this._building);
            XtraMessageBox.Show("修改成功!");
            DialogResult = DialogResult.OK;
        }
 
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
 
        private Model.Building _model = null;
        private void WebView21_WebMessageReceived(object sender, Microsoft.Web.WebView2.Core.CoreWebView2WebMessageReceivedEventArgs e)
        {
            if (_model == null)
                return;
            var j = Yw.JsonHelper.Json2Object<FixationReceivedViewModel>(e.WebMessageAsJson);
            switch (j.Oper)
            {
                case "getLocation":
                    var o = Yw.JsonHelper.Json2Object<AmapLocationViewModel>(j.Json);
                    _model.AmapId = o.id;
                    //      _model.Address = buildWizardForm1.= o.address;
                    _model.Coordinate = o.location.lng + "," + o.location.lat;
                    break;
            }
        }
 
 
        private void WebView21_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
        {
            if (_model == null)
                return;
            try
            {
                var obj = new
                {
                    oper = "setMarker",
                    data = Yw.JsonHelper.Object2Json(new
                    {
                        loc = _model.Coordinate,
                        address = _model.Address,
                        name = _model.Name
                    })
                };
                var json = Yw.JsonHelper.Object2Json(obj);
                webView.CoreWebView2.PostWebMessageAsJson(json);
            }
            catch (Exception error)
            {
                throw error;
            }
        }
 
    }
}