489 lines
19 KiB
C#
489 lines
19 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using CommonLib.data;
|
|
using CommonLib;
|
|
using Lskj.PubUtils;
|
|
using System.IO;
|
|
using System.Xml;
|
|
using DevExpress.XtraEditors;
|
|
using System.Data.SqlClient;
|
|
using System.Runtime.Serialization.Formatters.Binary;
|
|
using System.Drawing.Imaging;
|
|
using Lskj.Common;
|
|
|
|
|
|
namespace Lskj.PubPDFViewer
|
|
{
|
|
public partial class FrmMain : FormBase
|
|
{
|
|
/// <summary>
|
|
/// 当前文档主键
|
|
/// </summary>
|
|
public string BillDocumentId;
|
|
/// <summary>
|
|
/// 单据明细ID
|
|
/// </summary>
|
|
public string BillDeatilId;
|
|
/// <summary>
|
|
/// 步骤
|
|
/// </summary>
|
|
public string StepCode;
|
|
/// <summary>
|
|
/// 图片来源
|
|
/// </summary>
|
|
public string PicSourceField;
|
|
/// <summary>
|
|
/// pdf文件主键值
|
|
/// </summary>
|
|
public string PdfFileId;
|
|
|
|
|
|
/// <summary>
|
|
/// pdf源文件目录
|
|
/// </summary>
|
|
private string _dicPath = PubUtil.AbsolutelyPath + "tempfiles/";
|
|
/// <summary>
|
|
/// 服务器地址
|
|
/// </summary>
|
|
private string _serverPath = string.Empty;
|
|
/// <summary>
|
|
/// 签名图片流
|
|
/// </summary>
|
|
private byte[] _imageStream;
|
|
/// <summary>
|
|
/// 签名数据源
|
|
/// </summary>
|
|
private DataTable _signList;
|
|
/// <summary>
|
|
/// The m_ client test handle
|
|
/// </summary>
|
|
private IntPtr _mClientTestHandle = IntPtr.Zero;
|
|
|
|
public FrmMain()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:窗口加载</para>
|
|
/// <para>创建人:姜棚</para>
|
|
/// <para>创建日期:2018-06-01 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//Image image = Image.FromFile(@"C:\Users\84900\Desktop\YOULIKE公章-透明.jpg");
|
|
//Image image = System.Drawing.Image.FromFile(@"C:\Users\84900\Desktop\测试.png");
|
|
//Bitmap pbitmap = new Bitmap(image);
|
|
//pbitmap.MakeTransparent(Color.Transparent);
|
|
//string sqlValue2 = string.Format("update P_EmployeeTab set signBmp=@fs where employeeid='{0}'", 1);
|
|
//SqlHelper.ExecuteSqlInsertImg(sqlValue2, PubClass.ConvertImage(image));
|
|
|
|
this.pdfSignEx.InitPdfEditor();
|
|
this.InitializeSetting();
|
|
this.pdfSignEx.OnSaveCallBack += new EventHandler(OnSavePdfView);
|
|
this.pdfSignEx.OnSaveAsCallBack += new EventHandler(OnSaveAsPdfView);
|
|
this.pdfSignEx.OnDeleteCallBack += new EventHandler(OnDeletePdfView);
|
|
this.pdfSignEx.OnOpenFileCallBack += new EventHandler(OnOpenFile);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
PubUtil.WriteLog(ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:初始化属性值</para>
|
|
/// <para>创建人:姜棚</para>
|
|
/// <para>创建日期:2018-06-01 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void InitializeSetting()
|
|
{
|
|
if (string.IsNullOrEmpty(this.PdfFileId)) return;
|
|
this.GetServerPath();
|
|
this.GetTempletFile();
|
|
this.GetSignPic();
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:获取签名图片</para>
|
|
/// <para>创建人:姜棚</para>
|
|
/// <para>创建日期:2018-06-04 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void GetSignPic()
|
|
{
|
|
string sqlValue = string.Format("select * from P_EmployeeTab where employeeid='{0}'", OperatorId);
|
|
DataTable dt = SqlHelper.ExecuteDataTable(sqlValue);
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
this._imageStream = (byte[])dt.Rows[0]["signBmp"];
|
|
this.pdfSignEx.SignImage = PubClass.ReadImage(this._imageStream); ;
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("没有配置签名字段");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:获取该pdf文件的签名来源</para>
|
|
/// <para>创建人:姜棚</para>
|
|
/// <para>创建日期:2018-06-01 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void GetSignsSource()
|
|
{
|
|
string sqlValue = string.Format("select * from P_PDFSignTab where BillId='{0}' and FileId='{1}'", this.BillDocumentId, this.PdfFileId);
|
|
this._signList = SqlHelper.ExecuteDataTable(sqlValue);
|
|
}
|
|
/// <summary>
|
|
///<para>说明:获取源pdf文件</para>
|
|
///<para>创建人:姜棚</para>
|
|
///<para>创建日期:2018-06-01 </para>
|
|
///<para>修改人:</para>
|
|
///<para>修改日期:</para>
|
|
///<para>修改备注:</para>
|
|
///<para>版本:1.0</para>
|
|
/// </summary>
|
|
private void GetTempletFile()
|
|
{
|
|
string fileSource = string.Format("select * from P_fm_FileTab where fileId='{0}'", this.PdfFileId);
|
|
DataTable dt = SqlHelper.ExecuteDataTable(fileSource);
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
string fileName = dt.Rows[0]["sName"] + "";
|
|
string filePath = _dicPath + fileName;
|
|
if (fileName.Contains(".pdf"))
|
|
{
|
|
this.GetSignsSource();
|
|
this.pdfSignEx.TempletFilePath = filePath;
|
|
if (!File.Exists(filePath))
|
|
{
|
|
DownFiles(this.PdfFileId, fileName); //下载
|
|
}
|
|
else
|
|
{
|
|
//初始化描点
|
|
this.pdfSignEx.InitPdfPage(_signList);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:获取服务地址</para>
|
|
/// <para>创建人:姜棚</para>
|
|
/// <para>创建日期:2018-06-01 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <returns>System.String.</returns>
|
|
private void GetServerPath()
|
|
{
|
|
DataTable dtSystemTable = SqlHelper.ExecuteDataTable("select * from p_systemtab");
|
|
if (dtSystemTable.Columns.Contains("serverattachpath"))
|
|
{
|
|
_serverPath = dtSystemTable.Rows[0]["serverattachpath"] + "";
|
|
}
|
|
else
|
|
{
|
|
XmlDocument xmlDoc = new XmlDocument();
|
|
xmlDoc.Load(PubUtil.AbsolutelyPath + "/LSClientConfig.xml");
|
|
XmlNodeList list = xmlDoc.DocumentElement.SelectNodes("/Root/ClientSettings/rootPath");
|
|
foreach (XmlNode rootPath in list)
|
|
_serverPath = rootPath.InnerText;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:下载</para>
|
|
/// <para>创建人:姜棚</para>
|
|
/// <para>创建日期:2018-06-01 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="filedvalue">The filedvalue.</param>
|
|
/// <param name="filedname">The filedname.</param>
|
|
private void DownFiles(string filedvalue, string filedname)
|
|
{
|
|
if (string.IsNullOrEmpty(_serverPath))
|
|
{
|
|
XtraMessageBox.Show("下载附件路径未配置.");
|
|
return;
|
|
}
|
|
if (AttachOperation(2, Convert.ToInt32(OperatorId), OperatorName, "", Convert.ToInt32(filedvalue), "", 0))
|
|
{
|
|
TParamsData pd = new TParamsData(this.Handle);
|
|
string sql = "select dbo.fun_fm_getAbsolutePath(" + filedvalue + ");";
|
|
string path = SqlHelper.ExecuteScalar(CommandType.Text, sql) + "";
|
|
pd.CallDownload(_serverPath + path);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:向数据库插入数据</para>
|
|
/// <para>创建人:姜棚</para>
|
|
/// <para>创建日期:2018-06-01 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void InsertPoint()
|
|
{
|
|
try
|
|
{
|
|
if (_imageStream != null && this.pdfSignEx.SignPoint.X != 0 && this.pdfSignEx.SignPoint.Y != 0)
|
|
{
|
|
string sqlValue = string.Format(@"insert into P_PDFSignTab (FileId,BillId,BillDetailId,StepCode,OperatorId,OperateDate,Image,ImageX,ImageY,Page)
|
|
VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','','{6}','{7}','{8}');Select @@IDENTITY;", this.PdfFileId, this.BillDocumentId, this.BillDeatilId, this.StepCode, ERPInfo.Instance.EmployeeId, DateTime.Now, this.pdfSignEx.SignPoint.X, this.pdfSignEx.SignPoint.Y, this.pdfSignEx.CurrentPageNo);
|
|
this.pdfSignEx.CurrentId = Convert.ToInt32(SqlHelper.ExecuteScalar(CommandType.Text, sqlValue));
|
|
if (this.pdfSignEx.CurrentId > 0)
|
|
{
|
|
string sqlValue2 = string.Format("update P_PDFSignTab set Image=@fs where id='{0}'", this.pdfSignEx.CurrentId);
|
|
SqlHelper.ExecuteSqlInsertImg(sqlValue2, PubClass.ConvertImage(this.pdfSignEx.SignImage));
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show("保存失败:" + ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:附件验证</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-09-28 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="operType">1=上传,2=下载,3=删除,4=锁定,5=解除锁定 必填</param>
|
|
/// <param name="userId">The user identifier.</param>
|
|
/// <param name="userName">Name of the user.</param>
|
|
/// <param name="fileSpecisNo">The file specis no.</param>
|
|
/// <param name="filename">The filename.</param>
|
|
/// <param name="filesize">The filesize.</param>
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
|
private bool AttachOperation(int operType, int userId, string userName, string fileSpecisNo, int fileid, string filename, int filesize)
|
|
{
|
|
try
|
|
{
|
|
SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000);
|
|
pMsg.Direction = ParameterDirection.Output;
|
|
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
|
|
returnValue.Direction = ParameterDirection.ReturnValue;
|
|
SqlParameter[] param =
|
|
{
|
|
new SqlParameter("@opertype",SqlDbType.Int),
|
|
new SqlParameter("@operatorid",SqlDbType.Int),
|
|
new SqlParameter("@operatorname",SqlDbType.VarChar,50),
|
|
new SqlParameter("@fileSpecisNo",SqlDbType.VarChar,50),
|
|
new SqlParameter("@fileid",SqlDbType.Int),
|
|
new SqlParameter("@filename",SqlDbType.VarChar,200),
|
|
new SqlParameter("@filesize",SqlDbType.Int),
|
|
pMsg,
|
|
returnValue
|
|
};
|
|
param[0].Value = operType;
|
|
param[1].Value = userId;
|
|
param[2].Value = userName;
|
|
param[3].Value = fileSpecisNo;
|
|
param[4].Value = fileid;
|
|
param[5].Value = filename;
|
|
param[6].Value = filesize;
|
|
DataSet ds = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "p_SystemAttachOperation", "attach", param);
|
|
string msg = pMsg.Value.ToString();
|
|
int rVaule = Convert.ToInt32(returnValue.Value + "");
|
|
|
|
if (rVaule != 1)
|
|
{
|
|
MessageBox.Show(msg);
|
|
}
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
return true;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:下载消息处理</para>
|
|
/// <para>创建人:姜棚</para>
|
|
/// <para>创建日期:2018-06-01 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="m">要处理的 Windows<see cref="T:System.Windows.Forms.Message" />。</param>
|
|
protected override void DefWndProc(ref Message m)
|
|
{
|
|
try
|
|
{
|
|
switch (m.Msg)
|
|
{
|
|
//接收到客户端发来的窗体句柄
|
|
case LSCustomWinMsg.REV_CLIENT_WINDOW_HANDLE:
|
|
{
|
|
_mClientTestHandle = m.WParam;
|
|
break;
|
|
}
|
|
//接收到客户端处理错误消息
|
|
case LSCustomWinMsg.REV_CLIENT_DEAL_ERROR:
|
|
{
|
|
MessageBox.Show("通讯客户端处理出错了");
|
|
break;
|
|
}
|
|
//接收到客户端处理ok消息
|
|
case LSCustomWinMsg.REV_CLIENT_DEAL_OK:
|
|
{
|
|
//this.pdfSignEx.InitPdfPage(_signList);
|
|
break;
|
|
}
|
|
case LSCustomWinMsg.DOWNLOADCOMPLETED:
|
|
{
|
|
this.pdfSignEx.InitPdfPage(_signList);
|
|
break;
|
|
}
|
|
//批量上传关闭窗体之前的通知消息
|
|
case LSCustomWinMsg.BATCH_UPLOAD_COMPLETED:
|
|
{
|
|
//MessageBox.Show("删除完毕");
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
base.DefWndProc(ref m);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
PubUtil.WriteLog(ex.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:保存</para>
|
|
/// <para>创建人:姜棚</para>
|
|
/// <para>创建日期:2018-06-01 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
protected void OnSavePdfView(object o, EventArgs e)
|
|
{
|
|
if (this.pdfSignEx.PicBox.Visible)
|
|
{
|
|
InsertPoint();
|
|
//插入后记录当前数据的ID 方便删除
|
|
if (this.pdfSignEx.CurrentId > 0)
|
|
{
|
|
this.pdfSignEx.Save();
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:另存为</para>
|
|
/// <para>创建人:姜棚</para>
|
|
/// <para>创建日期:2018-06-01 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="o">The o.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
protected void OnSaveAsPdfView(object o, EventArgs e)
|
|
{
|
|
//另存成功后
|
|
bool saveSate = this.pdfSignEx.SaveAs();
|
|
if (saveSate)
|
|
InsertPoint();
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:删除</para>
|
|
/// <para>创建人:姜棚</para>
|
|
/// <para>创建日期:2018-06-01 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="o">The o.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
protected void OnDeletePdfView(object o, EventArgs e)
|
|
{
|
|
this.pdfSignEx.Delete();
|
|
if (this.pdfSignEx.CurrentId != 0)
|
|
{
|
|
string sqlValue = string.Format("delete from P_PDFSignTab where id='{0}'", this.pdfSignEx.CurrentId);
|
|
int result = SqlHelper.ExecuteNonQuery(sqlValue);
|
|
if (result > 0)
|
|
{
|
|
GetSignsSource();
|
|
this.pdfSignEx.InitPdfPage(this._signList);
|
|
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:打开文件(先屏蔽)</para>
|
|
/// <para>创建人:姜棚</para>
|
|
/// <para>创建日期:2018-06-01 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
protected void OnOpenFile(object o, EventArgs e)
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:关闭</para>
|
|
/// <para>创建人:姜棚</para>
|
|
/// <para>创建日期:2018-06-08 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="FormClosingEventArgs"/> instance containing the event data.</param>
|
|
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
this.pdfSignEx.ClosePDFViewer();
|
|
}
|
|
}
|
|
}
|