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;
///
/// 分类group
///
public string parentGroup
{
get { return _Group; }
set
{
_Group = value;
this.ucUpFile1.parentGroup = value;
}
}
///
/// 上传后刷新文件列表
///
///
///
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 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);
}
}
///
/// 删除附件
///
///
///
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();
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);
}
}
}
///
/// 浏览附件
///
///
///
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);
}
}
}
///
/// 下载附件
///
///
///
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);
}
}
}
}
}