Files
lserp_cs_6.0/插件库/Lskj.Control/BrowserSetting2/BsDownloadHandler.cs
cyf ab56a9bcf7 基线 SVN r240
SVN-Revision: r240
2025-02-06 06:46:06 +00:00

203 lines
8.6 KiB
C#

using Lskj.Business.Impl;
using Lskj.Control;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using System.Windows.Forms;
using Xilium.CefGlue;
using Lskj.Control.Model;
using Lskj.Data;
using Lskj.Business;
using Lskj.Model;
using DevExpress.XtraTab;
using Lskj.Util;
using System.Diagnostics;
using DevExpress.Utils;
namespace Lskj.Control.BrowserSetting2
{
public class BsDownloadHandler : CefDownloadHandler
{
private bool allowDownload;
public BsDownloadHandler(bool AllowDownload = true)
{
this.allowDownload = AllowDownload;
}
protected override void OnBeforeDownload(CefBrowser browser, CefDownloadItem downloadItem, string suggestedName, CefBeforeDownloadCallback callback)
{
if (this.allowDownload)
{
callback.Continue(string.Empty, true);
//开头为 ^ 符号,根据参数打开模块
//if (downloadItem.Url.StartsWith("^"))
//{
// string url = downloadItem.Url.Remove(0,0);
// List<string> paramList = url.Split('^').ToList();
// //OpenModule();
//}
}
else
{
return;
}
}
protected override void OnDownloadUpdated(CefBrowser browser, CefDownloadItem downloadItem, CefDownloadItemCallback callback)
{
if (downloadItem.IsComplete)
{
MessageBox.Show("下载成功");
if (browser.IsPopup && !browser.HasDocument)
{
//browser.GetHost().ParentWindowWillClose();
browser.GetHost().CloseBrowser();
}
}
}
//public bool isfirstDownLoad = true;
//protected override void OnBeforeDownload(CefBrowser browser, CefDownloadItem downloadItem, string suggestedName, CefBeforeDownloadCallback callback)
//{
// //callback.Continue(string.Empty, true);
// try
// {
// string tipMsg = string.Empty; int vsNum = 0;
// //if (downloadItem.Url.Contains("http://110.185.210.70"))
// //{
// // string Filename = downloadItem.Url.Substring(downloadItem.Url.LastIndexOf('/') + 1);//简单处理文件名,实际中还需要单独处理,这里有BUG
// // string FileName = HttpUtility.UrlDecode(Filename);
// // string[] names = FileName.Split('/');
// // string fname = names[names.Length - 1];
// // Download(downloadItem.Url, fname);
// // browser.GetHost().CloseBrowser();
// // return;
// //}
// string szFilename = downloadItem.Url.Substring(downloadItem.Url.LastIndexOf('/') + 1);//简单处理文件名,实际中还需要单独处理,这里有BUG
// string SzFileName = HttpUtility.UrlDecode(szFilename);
// string[] szName = SzFileName.Split('/');
// string fileTitle = szName[szName.Length - 1];
// //downfile(e.Url, e.Filename, tempPath);
// if (fileTitle.Contains("?")) fileTitle = fileTitle.Substring(0, fileTitle.LastIndexOf('?'));
// DataRow rowItem = AttachImpl.GetTempletFile(fileTitle);
// //string topname = downloadItem.SuggestedFileName.Substring(0, downloadItem.SuggestedFileName.LastIndexOf(".") - 1);
// //topname = suggestedName;
// //bool isMultipleLoad = downloadItem.Url.Contains("downLoadTemp") && Regex.IsMatch(topname, @"^[+-]?\d*[.]?\d*$");
// try
// {
// Download(downloadItem.Url, fileTitle);
// browser.GetHost().CloseBrowser();
// return;
// }
// catch (Exception ex)
// {
// MessageBox.Show("下载失败!\r\n" + ex.Message);
// browser.GetHost().CloseBrowser();
// }
// }
// catch (Exception ex)
// {
// MessageBox.Show(ex.Message);
// }
//}
//protected override void OnDownloadUpdated(CefBrowser browser, CefDownloadItem downloadItem, CefDownloadItemCallback callback)
//{
// //if (downloadItem.IsComplete)
// //{
// // MessageBox.Show("下载成功");
// // if (browser.IsPopup && !browser.HasDocument)
// // {
// // //browser.GetHost().ParentWindowWillClose();
// // browser.GetHost().CloseBrowser();
// // }
// //}
// //downloadItem.IsComplete
// //if (downloadItem.IsComplete) {
// // string tipMsg = string.Empty; int vsNum = 0;
// // DataRow rowItem = AttachImpl.GetTempletFile(downloadItem.SuggestedFileName);
// // string topname = downloadItem.SuggestedFileName.Substring(0, downloadItem.SuggestedFileName.LastIndexOf(".") - 1);
// // bool isMultipleLoad = downloadItem.Url.Contains("downLoadTemp") && Regex.IsMatch(topname, @"^[+-]?\d*[.]?\d*$");
// // if (rowItem != null || isMultipleLoad)
// // {
// // try
// // {
// // bool success = rowItem != null ? AttachImpl.CheckAttachOperation(2, "", Convert.ToInt32(rowItem["fileId"]), "", 0, out tipMsg) == 1 : isMultipleLoad;
// // if (success)
// // {
// // string szFilename = downloadItem.Url.Substring(downloadItem.Url.LastIndexOf('/') + 1);//简单处理文件名,实际中还需要单独处理,这里有BUG
// // string SzFileName = HttpUtility.UrlDecode(szFilename);
// // string[] szName = SzFileName.Split('/');
// // //downfile(e.Url, e.Filename, tempPath);
// // Download(downloadItem.Url, szName[szName.Length - 1]);
// // return;
// // }
// // else
// // {
// // MessageUtil.Show(tipMsg);
// // }
// // }
// // catch (Exception ex)
// // {
// // MessageUtil.Show("下载失败!\r\n" + ex.Message);
// // }
// // }
// // else
// // {
// // MessageUtil.Show("未找到下载项");
// // }
// // //browser.GetHost().CloseBrowser();
// //}
//}
///// <summary>
///// <para>说明:定义服务器文件地址,含文件名。客户端接收地址及文件名由客户端自行定义</para>
///// <para>创建人:王一帆</para>
///// <para>创建日期: </para>
///// <para>修改人:</para>
///// <para>修改日期:</para>
///// <para>修改备注:</para>
///// <para>版本:1.0</para>
///// </summary>
///// <param name="URL">The URL.</param>
///// <param name="FileName">Name of the file.</param>
//public static void Download(string URL, string FileName)
//{
// FrmSelectDownload frmSelectDownload = new FrmSelectDownload();
// frmSelectDownload.URL = URL;
// frmSelectDownload.FileName = FileName;
// frmSelectDownload.Show();
// //SaveFileDialog saveFileDialog = new SaveFileDialog();
// //saveFileDialog.FileName = FileName;
// //saveFileDialog.Title = "下载模板文件到";
// //saveFileDialog.RestoreDirectory = true;
// ////点了保存按钮进入
// //if (saveFileDialog.ShowDialog() == DialogResult.OK)
// //{
// // string localFilePath = System.IO.Path.GetFullPath(saveFileDialog.FileName);//获得文件路径,含文件名
// // string fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1);//获取文件名,不带路径
// // string FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));//获取文件路径,不带文件名
// // FrmDownload frm = new FrmDownload(URL, FileName, localFilePath);
// // frm.Show();
// //}
//}
}
}