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
{
///
/// 回调事件
///
public event EventHandler UpdateParent;
string parentGuid = "";
///
///
///
/// 父亲guid
/// 如果是xls,显示相应的说明
public ShowUp(string _parentGuid, bool isXls = false)
{
InitializeComponent();
this.parentGuid = _parentGuid;
this.ucUpFile1.parentGuid = _parentGuid;
ucUpFile1.UpChanged += UcUpFile1_UpChanged;
getBtn();
}
///
/// 上传后刷新文件列表
///
///
///
private void UcUpFile1_UpChanged(object sender, EventArgs e)
{
UpdateParent?.Invoke(this,
new UpdateParentEventArgs { FilterList = null });
Close();
}
private void getBtn()
{
List lst = new List();
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("下载成功!");
}
}
}
}
}