lu
2025-05-27 9778339d53c6abbed56e27d1f49c06fa8f569cf2
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
using CefSharp;
using DevExpress.XtraEditors;
using Gs.DevApp.ToolBox;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Net;
using System.Windows.Documents;
using System.Windows.Forms;
 
namespace Gs.DevApp.UserControl
{
    public partial class ShowUp : DevExpress.XtraEditors.XtraForm
    {
 
        /// <summary>
        ///     回调事件
        /// </summary>
        public event EventHandler<UpdateParentEventArgs> UpdateParent;
 
        string parentGuid = "";
 
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="_parentGuid">父亲guid</param>
        /// <param name="isXls">如果是xls,显示相应的说明</param>
        public ShowUp(string _parentGuid, bool isXls = false)
        {
            InitializeComponent();
            this.parentGuid = _parentGuid;
            this.ucUpFile1.parentGuid = _parentGuid;
            ucUpFile1.UpChanged += UcUpFile1_UpChanged;
 
            getBtn();
        }
 
        /// <summary>
        /// 上传后刷新文件列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UcUpFile1_UpChanged(object sender, EventArgs e)
        {
            UpdateParent?.Invoke(this,
             new UpdateParentEventArgs { FilterList = null });
            Close();
        }
 
        private void getBtn()
        {
            List<dynamic> lst = new List<dynamic>();
            lst.Add(new
            {
                btnTxt = "检验工具\nXLS模板",
                xls = "001检验工具.xls"
            });
            lst.Add(new
            {
                btnTxt = "检验项目\nXLS模板",
                xls = "002检验项目.xls"//001
            });
 
            lst.Add(new
            {
                btnTxt = "物料检验项目\nXLS模板",
                xls = "003物料检验项目.xls"
            });
 
            lst.Add(new
            {
                btnTxt = "工单后盖码\nXLS模板",
                xls = "004工单后盖码.xls"
            });
 
            foreach (var obj in lst)
            {
                SimpleButton btn = new DevExpress.XtraEditors.SimpleButton();
                btn.ImageOptions.Image = global::Gs.DevApp.Properties.Resources.printarea_32x32;
                btn.ImageOptions.ImageToTextAlignment = DevExpress.XtraEditors.ImageAlignToText.TopCenter;
                btn.Name = Guid.NewGuid().ToString();
                btn.Size = new System.Drawing.Size(120, 120);
                btn.TabIndex = 1;
                btn.Text = obj.btnTxt;
                btn.Margin = new System.Windows.Forms.Padding(10);
                btn.Tag = obj.xls;
                this.flowLayoutPanel1.Controls.Add(btn);
                btn.Click += Btn_Click;
            }
        }
 
        private void Btn_Click(object sender, EventArgs e)
        {
            string _guid = Guid.NewGuid().ToString();
            SimpleButton btn = (SimpleButton)sender;
            string urlPath = btn.Tag.ToString();//a697b909-5baa-4e74-8df4-87abb1f96240ico.png
            using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
            {
                folderBrowserDialog.Description = "选择导出文件的保存路径";
                DialogResult dialogResult = folderBrowserDialog.ShowDialog();
                if (dialogResult == DialogResult.OK)
                {
                    string _folder = folderBrowserDialog.SelectedPath;
                    string _folderName = _folder + "\\" + urlPath;
                    string _url = ConfigurationManager.AppSettings["WebApiUrl"].ToString() + "upload/" + urlPath;
                    using (WebClient client = new WebClient())
                    {
                        client.DownloadFile(_url, _folderName);
                    }
                    ToolBox.MsgHelper.ShowInformation("下载成功!");
                }
            }
        }
    }
}