ab56a9bcf7
SVN-Revision: r240
292 lines
11 KiB
C#
292 lines
11 KiB
C#
/******************************
|
|
* 说明:附件管理类
|
|
* 创建人:龚宇超
|
|
* 创建日期:2018-01-17
|
|
* 修改人:
|
|
* 修改日期:
|
|
* 修改备注:
|
|
* 版本:1.0.0.0
|
|
******************************/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Drawing;
|
|
using Lskj.Model;
|
|
using System.IO;
|
|
using Lskj.Util;
|
|
using Lskj.Data;
|
|
|
|
namespace Lskj.Control.Model
|
|
{
|
|
/// <summary>
|
|
/// 附件管理类
|
|
/// </summary>
|
|
public class AttachHelper
|
|
{
|
|
/// <summary>
|
|
/// 附件窗口宽度
|
|
/// </summary>
|
|
private const int FORM_WIDTH = 800;
|
|
/// <summary>
|
|
/// 附件窗口高度
|
|
/// </summary>
|
|
private const int FORM_HEIGHT = 500;
|
|
|
|
/// <summary>
|
|
/// 上传成功后调用
|
|
/// </summary>
|
|
public static event EventHandler OnUploadSuccess;
|
|
/// <summary>
|
|
/// 下载成功后调用
|
|
/// </summary>
|
|
public static event EventHandler OnDownLoadSuccess;
|
|
/// <summary>
|
|
/// 下载失败后调用
|
|
/// </summary>
|
|
public static event EventHandler OnDownLoadFault;
|
|
/// <summary>
|
|
/// 删除成功后调用
|
|
/// </summary>
|
|
public static event EventHandler OnDeleteSuccess;
|
|
/// <summary>
|
|
/// 删除失败后调用
|
|
/// </summary>
|
|
public static event EventHandler OnDeleteFault;
|
|
|
|
/// <summary>
|
|
/// <para>说明:批量下载附件需显示窗口</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-01-17 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="fileIds">The file ids.</param>
|
|
/// <param name="parentId">The parent identifier.</param>
|
|
/// <param name="formSize">Size of the form.</param>
|
|
public static void DownLoadFile(IntPtr handle, string fileIds, string parentId)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(fileIds) || string.IsNullOrWhiteSpace(parentId)) return;
|
|
|
|
string param = string.Format("paramsCount=9|userId={0}|type={1}|left={2}|top={3}|width={4}|height={5}|directoryId={6}|fileIds={7}|mainHandle={8}|",
|
|
ERPInfo.Instance.UserId, (int)AttachType.DownLoadByFileIds, 100, 100, FORM_WIDTH, FORM_HEIGHT, parentId, fileIds.Trim(','), handle);
|
|
|
|
WinHelper.WinExec(PubUtil.AbsolutelyFileUploadPath + " " + param, 9);
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:后台下载附件不显示窗口</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-01-17 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="handle">The handle.</param>
|
|
/// <param name="filePath">The file path.</param>
|
|
public static void DownLoadFile(IntPtr handle, string filePath)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(filePath))
|
|
{
|
|
MessageUtil.Show(ResourceKeys.DownFileNotNull);
|
|
}
|
|
else
|
|
{
|
|
string param = string.Format("paramsCount=2|downloadPath={0}|mainHandle={1}|", filePath.Replace(' ', '*'), handle);
|
|
|
|
WinHelper.WinExec(PubUtil.AbsolutelyFileUploadPath + " " + param, 2);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:上传附件需要显示窗口</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-01-17 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="handle">The handle.</param>
|
|
/// <param name="fileIds">The file ids.</param>
|
|
/// <param name="parentId">The parent identifier.</param>
|
|
/// <param name="speciesNo">The spcies no.</param>
|
|
/// <param name="fileNum">The file number.</param>
|
|
/// <param name="formSize">Size of the form.</param>
|
|
public static void UpLoadFile(IntPtr handle, string parentId, string speciesNo, string fileNum)
|
|
{
|
|
string param = string.Format("paramsCount=11|userId={0}|type={1}|left={2}|top={3}|width={4}|height={5}|directoryId={6}|fileIds={7}|mainHandle={8}|fileNumber={9}|specieNo={10}|",
|
|
ERPInfo.Instance.UserId, (int)AttachType.UpLoadByParentId, 100, 100, FORM_WIDTH, FORM_HEIGHT, parentId, "", handle, fileNum ?? "001", speciesNo);
|
|
|
|
WinHelper.WinExec(PubUtil.AbsolutelyFileUploadPath + " " + param, 9);
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:上传附件不显示窗口</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-01-17 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="handle">The handle.</param>
|
|
/// <param name="parentId">The parent identifier.</param>
|
|
/// <param name="speciesNo">The species no.</param>
|
|
/// <param name="fileNum">The file number.</param>
|
|
/// <param name="filePath">文件路径</param>
|
|
public static void UpLoadFile(IntPtr handle, string parentId, string speciesNo, string fileNum, string filePath)
|
|
{
|
|
if (!File.Exists(filePath))
|
|
{
|
|
MessageUtil.Show(ResourceKeys.FileNotFound);
|
|
}
|
|
else
|
|
{
|
|
string param = string.Format("paramsCount=12|userId={0}|type={1}|left={2}|top={3}|width={4}|height={5}|directoryId={6}|fileIds={7}|mainHandle={8}|fileNumber={9}|specieNo={10}|filePath={11}|",
|
|
ERPInfo.Instance.UserId, (int)AttachType.UpLoadByParentId, 100, 100, FORM_WIDTH, FORM_HEIGHT, parentId, "", handle, fileNum ?? "001", speciesNo, filePath);
|
|
|
|
WinHelper.WinExec(PubUtil.AbsolutelyFileUploadPath + " " + param, 12);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:删除附件</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-01-17 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="handle">The handle.</param>
|
|
/// <param name="fileIds">文件以逗号隔开</param>
|
|
public static void DeleteFile(IntPtr handle, string fileIds)
|
|
{
|
|
string param = string.Format("paramsCount=4|classType=deleteFile|userId={0}|mainHandle={1}|fileIds={2}", ERPInfo.Instance.UserId, handle, fileIds);
|
|
|
|
WinHelper.WinExec(PubUtil.AbsolutelyFileUploadPath + " " + param, 9);
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:附件消息处理</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-22 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="m">The MSG.</param>
|
|
public static void DefWndProc(System.Windows.Forms.Message m)
|
|
{
|
|
switch (m.Msg)
|
|
{
|
|
case AttachCallBackWinMsg.BATCH_UPLOAD_COMPLETED:
|
|
if(OnUploadSuccess != null) OnUploadSuccess(m, null); // 上传成功
|
|
break;
|
|
case AttachCallBackWinMsg.DOWNLOADCOMPLETED:
|
|
if(OnDownLoadSuccess != null) OnDownLoadSuccess(m, null); // 下载成功
|
|
break;
|
|
case AttachCallBackWinMsg.DOWNLOADERROR:
|
|
if(OnDownLoadFault != null) OnDownLoadFault(m, null); // 下载失败
|
|
break;
|
|
case AttachCallBackWinMsg.DELETECOMPLETED: // 删除附件完成
|
|
if (OnDeleteSuccess != null) OnDeleteSuccess(m, null);
|
|
break;
|
|
case AttachCallBackWinMsg.DELETEERROR: // 删除文件失败
|
|
if (OnDeleteFault != null) OnDeleteFault(m, null);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:是否为当前消息</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-23 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="handle">The handle.</param>
|
|
/// <param name="m">The m.</param>
|
|
/// <returns><c>true</c> if [is definition WND proc] [the specified handle]; otherwise, <c>false</c>.</returns>
|
|
public static bool IsDefWndProc(IntPtr handle,System.Windows.Forms.Message m)
|
|
{
|
|
if (m == null) return false;
|
|
|
|
return handle == m.HWnd;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 附件回调消息
|
|
/// </summary>
|
|
public struct AttachCallBackWinMsg
|
|
{
|
|
/// <summary>
|
|
/// 自定义消息
|
|
/// </summary>
|
|
private const int CUSTOM_MESSAGE = 0X9000;
|
|
/// <summary>
|
|
/// 自定义客户端消息
|
|
/// </summary>
|
|
private const int WM_USER = 0x400;
|
|
/// <summary>
|
|
/// 附件客户端连接被关闭消息
|
|
/// </summary>
|
|
public const int REV_CLIENT_SOCKET_CLOSED = CUSTOM_MESSAGE + 8;
|
|
/// <summary>
|
|
/// 批量上传关闭窗体之前的通知消息
|
|
/// </summary>
|
|
public const int BATCH_UPLOAD_COMPLETED = CUSTOM_MESSAGE + 9;
|
|
/// <summary>
|
|
/// 下载完成通知消息
|
|
/// </summary>
|
|
public const int DOWNLOADCOMPLETED = CUSTOM_MESSAGE + 10;
|
|
/// <summary>
|
|
/// 下载失败通知消息
|
|
/// </summary>
|
|
public const int DOWNLOADERROR = CUSTOM_MESSAGE + 11;
|
|
/// <summary>
|
|
/// 删除成功
|
|
/// </summary>
|
|
public const int DELETECOMPLETED = CUSTOM_MESSAGE + 12;
|
|
/// <summary>
|
|
/// 删除失败
|
|
/// </summary>
|
|
public const int DELETEERROR = CUSTOM_MESSAGE + 13;
|
|
/// <summary>
|
|
/// 接收到客户端发来的窗体句柄
|
|
/// </summary>
|
|
public const int REV_CLIENT_WINDOW_HANDLE = WM_USER + 0x112;
|
|
/// <summary>
|
|
/// 接收到客户端处理错误消息
|
|
/// </summary>
|
|
public const int REV_CLIENT_DEAL_ERROR = WM_USER + 0x119;
|
|
/// <summary>
|
|
/// 接收到客户端处理ok消息
|
|
/// </summary>
|
|
public const int REV_CLIENT_DEAL_OK = WM_USER + 0x120;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 附件类型
|
|
/// </summary>
|
|
public enum AttachType
|
|
{
|
|
/// <summary>
|
|
/// 根据父目录最后一层id上传批量文件
|
|
/// </summary>
|
|
UpLoadByParentId,
|
|
/// <summary>
|
|
/// 根据父目录id批量下载
|
|
/// </summary>
|
|
DownLoadByParentId,
|
|
/// <summary>
|
|
/// 根据多个文件id下载
|
|
/// </summary>
|
|
DownLoadByFileIds
|
|
}
|
|
}
|