/******************************
* 说明:附件管理类
* 创建人:龚宇超
* 创建日期: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
{
///
/// 附件管理类
///
public class AttachHelper
{
///
/// 附件窗口宽度
///
private const int FORM_WIDTH = 800;
///
/// 附件窗口高度
///
private const int FORM_HEIGHT = 500;
///
/// 上传成功后调用
///
public static event EventHandler OnUploadSuccess;
///
/// 下载成功后调用
///
public static event EventHandler OnDownLoadSuccess;
///
/// 下载失败后调用
///
public static event EventHandler OnDownLoadFault;
///
/// 删除成功后调用
///
public static event EventHandler OnDeleteSuccess;
///
/// 删除失败后调用
///
public static event EventHandler OnDeleteFault;
///
/// 说明:批量下载附件需显示窗口
/// 创建人:龚宇超
/// 创建日期:2018-01-17
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The file ids.
/// The parent identifier.
/// Size of the form.
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);
}
///
/// 说明:后台下载附件不显示窗口
/// 创建人:龚宇超
/// 创建日期:2018-01-17
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The handle.
/// The file path.
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);
}
}
///
/// 说明:上传附件需要显示窗口
/// 创建人:龚宇超
/// 创建日期:2018-01-17
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The handle.
/// The file ids.
/// The parent identifier.
/// The spcies no.
/// The file number.
/// Size of the form.
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);
}
///
/// 说明:上传附件不显示窗口
/// 创建人:龚宇超
/// 创建日期:2018-01-17
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The handle.
/// The parent identifier.
/// The species no.
/// The file number.
/// 文件路径
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);
}
}
///
/// 说明:删除附件
/// 创建人:龚宇超
/// 创建日期:2018-01-17
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The handle.
/// 文件以逗号隔开
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);
}
///
/// 说明:附件消息处理
/// 创建人:龚宇超
/// 创建日期:2018-03-22
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The MSG.
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;
}
}
///
/// 说明:是否为当前消息
/// 创建人:龚宇超
/// 创建日期:2018-03-23
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The handle.
/// The m.
/// true if [is definition WND proc] [the specified handle]; otherwise, false.
public static bool IsDefWndProc(IntPtr handle,System.Windows.Forms.Message m)
{
if (m == null) return false;
return handle == m.HWnd;
}
}
///
/// 附件回调消息
///
public struct AttachCallBackWinMsg
{
///
/// 自定义消息
///
private const int CUSTOM_MESSAGE = 0X9000;
///
/// 自定义客户端消息
///
private const int WM_USER = 0x400;
///
/// 附件客户端连接被关闭消息
///
public const int REV_CLIENT_SOCKET_CLOSED = CUSTOM_MESSAGE + 8;
///
/// 批量上传关闭窗体之前的通知消息
///
public const int BATCH_UPLOAD_COMPLETED = CUSTOM_MESSAGE + 9;
///
/// 下载完成通知消息
///
public const int DOWNLOADCOMPLETED = CUSTOM_MESSAGE + 10;
///
/// 下载失败通知消息
///
public const int DOWNLOADERROR = CUSTOM_MESSAGE + 11;
///
/// 删除成功
///
public const int DELETECOMPLETED = CUSTOM_MESSAGE + 12;
///
/// 删除失败
///
public const int DELETEERROR = CUSTOM_MESSAGE + 13;
///
/// 接收到客户端发来的窗体句柄
///
public const int REV_CLIENT_WINDOW_HANDLE = WM_USER + 0x112;
///
/// 接收到客户端处理错误消息
///
public const int REV_CLIENT_DEAL_ERROR = WM_USER + 0x119;
///
/// 接收到客户端处理ok消息
///
public const int REV_CLIENT_DEAL_OK = WM_USER + 0x120;
}
///
/// 附件类型
///
public enum AttachType
{
///
/// 根据父目录最后一层id上传批量文件
///
UpLoadByParentId,
///
/// 根据父目录id批量下载
///
DownLoadByParentId,
///
/// 根据多个文件id下载
///
DownLoadByFileIds
}
}