lu
2025-04-14 ecb7a60de1639f520712ce95f99414b0dd2c9713
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Net;
using System.Windows.Forms;
 
namespace Gs.DevApp.UserControl
{
    public partial class UCUpFileList : DevExpress.XtraEditors.XtraUserControl
    {
 
        public UCUpFileList()
        {
            InitializeComponent();
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMx4);
            ucUpFile1.UpChanged += UcUpFile1_UpChanged;
        }
 
        private string _val;
        public string pGuid
        {
            get { return _val; }
            set
            {
                _val = value;
                this.ucUpFile1.parentGuid = value;
            }
        }
 
 
        private string _Group;
        /// <summary>
        /// 分类group
        /// </summary>
        public string parentGroup
        {
            get { return _Group; }
            set
            {
                _Group = value;
                this.ucUpFile1.parentGroup = value;
            }
        }
 
        /// <summary>
        /// 上传后刷新文件列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UcUpFile1_UpChanged(object sender, EventArgs e)
        {
            getFileList();
        }
        public void getFileList()
        {
            gcMx4.DataSource = null;
            if (string.IsNullOrEmpty(pGuid))
                return;
            if (pGuid.Length <= 10)
                return;
            System.Text.StringBuilder _sbSqlWhere = new System.Text.StringBuilder();
            _sbSqlWhere.Append(" and parent_Guid='" + pGuid.Trim() + "'");
            if (!string.IsNullOrEmpty(parentGroup))
                _sbSqlWhere.Append(" and file_Group='" + parentGroup + "'");
            PageQueryModel pgq = new PageQueryModel(1, 100, "create_date", "asc", "", _sbSqlWhere.ToString());
            string json = JsonConvert.SerializeObject(pgq);
            try
            {
                string strReturn = UtilityHelper.HttpPost("", "MesFile/GetListPage", json);
                ReturnModel<PageListModel> dd = UtilityHelper.ReturnToTablePage(strReturn);
                if (dd.rtnCode > 0)
                {
                    DataTable dt = dd.rtnData.list;
                    gcMx4.BindingContext = new BindingContext();
                    gcMx4.DataSource = dt;
                    gcMx4.ForceInitialize();
                    gvMx4.BestFitColumns();
                }
                else
                {
                    ToolBox.MsgHelper.ShowError("提示:" + dd.rtnMsg);
                }
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        /// <summary>
        /// 删除附件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            var rowhandle = gvMx4.FocusedRowHandle;
            if (rowhandle < 0)
                return;
            if (e.Button.Index == 0)
            {
                var dr = gvMx4.GetDataRow(rowhandle);
                var mxGuid = dr["guid"].ToString();
                if (!MsgHelper.AskQuestion("你选择了1条数据,确定删除吗?"))
                    return;
                var strJson = "";
                var lst = new List<string>();
                lst.Add(mxGuid);
                try
                {
                    strJson = UtilityHelper.HttpPost("", "MesFile/DeleteModel",
                        JsonConvert.SerializeObject(lst));
                    var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                    if (_rtn.rtnCode > 0) gvMx4.DeleteRow(rowhandle);
                    MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                }
                catch (Exception ex)
                {
                    MsgHelper.Warning("提示:" + ex.Message);
                }
            }
        }
 
        /// <summary>
        /// 浏览附件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void repositoryItemButtonEdit2_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            var rowhandle = gvMx4.FocusedRowHandle;
            if (rowhandle < 0)
                return;
            if (e.Button.Index == 0)
            {
                try
                {
                    var dr = gvMx4.GetDataRow(rowhandle);
                    var urlPath = dr["urlPath"].ToString();
                    Gs.DevApp.UserControl.ShowFile frm = new ShowFile(urlPath);
                    frm.ShowDialog();
                }
                catch (Exception ex)
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError(ex.Message);
                }
 
            }
        }
        /// <summary>
        /// 下载附件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void repositoryItemButtonEdit3_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            var rowhandle = gvMx4.FocusedRowHandle;
            if (rowhandle < 0)
                return;
            if (e.Button.Index == 0)
            {
                try
                {
                    var dr = gvMx4.GetDataRow(rowhandle);
                    var urlPath = dr["urlPath"].ToString();
                    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("下载成功!");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError(ex.Message);
                }
            }
        }
 
    }
}