duheng
2024-06-25 43e88ef24c6b3a7988c495d1740e68e33ce52f84
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
using HStation.Dto;
using HStation.WinFrmUI;
using HStation.WinFrmUI.Basic;
using Newtonsoft.Json;
using System.IO.Compression;
 
namespace ISupply.WinFrmUI
{
    public partial class AddProjectDlg : DevExpress.XtraEditors.XtraForm
    {
        public AddProjectDlg()
        {
            InitializeComponent();
        }
 
        public event Func<AddXhsProjectInput, Task<bool>> ReloadEvent;
 
        private AddXhsProjectInput _AddXhsProjectInput = null;
 
        //验证
        private bool Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(this.NameTextEdit.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.NameTextEdit, "必填项");
                return false;
            }
 
            var tagName = this.ModelTextEdit.Text.Trim();
            if (string.IsNullOrEmpty(tagName))
            {
                this.dxErrorProvider1.SetError(this.ModelTextEdit, "重复");
                return false;
            }
 
            return true;
        }
 
        //确定
        private async void btnOk_Click(object sender, EventArgs e)
        {
            if (!Valid())
                return;
            _AddXhsProjectInput = new AddXhsProjectInput();
            _AddXhsProjectInput.Name = this.NameTextEdit.Text.Trim();
            _AddXhsProjectInput.CustomerName = this.CustomerNameTextEdit.Text.Trim();
            _AddXhsProjectInput.CreateTime = DateTime.Now;
            _AddXhsProjectInput.GID = Guid.NewGuid().ToString();
            _AddXhsProjectInput.Description = this.DescriptionTextEdit.Text.Trim();
            if (await this.ReloadEvent.Invoke(_AddXhsProjectInput))
            {
                MessageBoxHelper.ShowSuccess("添加成功!");
            }
            else
            {
                MessageBoxHelper.ShowError("添加失败!");
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 
        //初始化
        private void AddProjectDlg_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<FixationReceivedViewModel>(e.WebMessageAsJson);
            switch (j.Oper)
            {
                case "getLocation":
                    var o = JsonConvert.DeserializeObject<AmapLocationViewModel>(j.Json);
                    if (o == null)
                        break;
                    _AddXhsProjectInput.Address = this.AddressTextEdit.Text = o.address;
                    _AddXhsProjectInput.MapPosition = o.location.lng + "," + o.location.lat;
                    break;
            }
        }
 
        //选择文件
        private void BtnFileChoice_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "ZIP Files (*.zip)|*.zip";
            openFileDialog.FilterIndex = 1;
            string selectedFilePath = null;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                selectedFilePath = openFileDialog.FileName;
                string newFileName = selectedFilePath.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)
       ? selectedFilePath.Substring(0, selectedFilePath.Length - 4) + ".hsr"
       : selectedFilePath;
                this.BtnFileChoice.Text = newFileName;
            }
            //   string extractPath = @"C:\Users\ZKC\Desktop\sss";
            //  ZipFile.ExtractToDirectory(extractPath, selectedFilePath);
        }
    }
}