基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
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;
|
||||
|
||||
namespace Lskj.Control.BrowserSetting
|
||||
{
|
||||
public class BsDownloadHandler : CefDownloadHandler
|
||||
{
|
||||
private BsClient BsClient;
|
||||
public BsDownloadHandler(BsClient bsClient)
|
||||
{
|
||||
BsClient = bsClient;
|
||||
}
|
||||
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 (string.IsNullOrWhiteSpace(downloadItem.SuggestedFileName))
|
||||
{
|
||||
if (BsClient != null && BsClient.frmWebBrowser != null)
|
||||
{
|
||||
BsClient.frmWebBrowser.Invoke(new Action(() =>
|
||||
{
|
||||
MessageUtil.Show("当前文档类型不支持预览");
|
||||
}));
|
||||
}
|
||||
if (BsClient != null && BsClient.frmWebBrowser != null && BsClient.frmWebBrowser.Parent != null && BsClient.frmWebBrowser.Parent.Name.Equals("previewFrm"))
|
||||
{
|
||||
browser.GetHost().CloseBrowser();
|
||||
}
|
||||
else if (BsClient != null && BsClient.frmWebBrowser != null)
|
||||
{
|
||||
BsClient.frmWebBrowser.LoadUrl("file:///C:/Users/asus/Desktop/errorFileNotFound.html");//加载错误异常,文件不存在
|
||||
}
|
||||
return;
|
||||
}
|
||||
string[] webpaths = Regex.Split(downloadItem.Url, "fileRoot/", RegexOptions.IgnoreCase);
|
||||
string webpath = webpaths[webpaths.Length-1];
|
||||
|
||||
|
||||
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, webpath);
|
||||
string topname = downloadItem.SuggestedFileName.Substring(0, downloadItem.SuggestedFileName.LastIndexOf(".") - 1);
|
||||
bool isMultipleLoad = downloadItem.Url.Contains("downLoadTemp") && Regex.IsMatch(topname, @"^[+-]?\d*[.]?\d*$");
|
||||
if (downloadItem.Url.StartsWith("blob"))
|
||||
{
|
||||
callback.Continue(string.Empty, true);
|
||||
//Download(downloadItem.Url, fileTitle);
|
||||
//return;
|
||||
}
|
||||
else if (rowItem != null || isMultipleLoad)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool success = rowItem != null ? AttachImpl.CheckAttachOperation(2, "", Convert.ToInt32(rowItem["fileId"]), "", 0, out tipMsg) == 1 : isMultipleLoad;
|
||||
if (success)
|
||||
{
|
||||
Download(downloadItem.Url, fileTitle);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show(tipMsg);
|
||||
//MessageUtil.Show(tipMsg);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("下载失败!\r\n" + ex.Message);
|
||||
//MessageUtil.Show("下载失败!\r\n" + ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("未找到下载项");
|
||||
}
|
||||
//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();
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user