/*********************** * 说明:PDF签名窗口 * 创建人:姜棚 * 创建日期: * 修改人: * 修改日期: * 修改备注: * 版本:1.0.0.0 ***********************/ 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 Lskj.Control; using Lskj.Model; using Lskj.Util; using Lskj.Business.Impl; using Lskj.Data; using System.IO; using Lskj.Control.Model; using Lskj.Business; namespace Lskj.PubPDFViewer { /// /// Class FrmMain. /// public partial class FrmMain : BaseForm { /// /// 系统参数模型 /// public DynamicPdfViewerModel SysModel; /// /// 签名来源 /// private DataTable _signSources; public FrmMain() { InitializeComponent(); } /// /// 说明:加载PDF窗口 /// 创建人:姜棚 /// 创建日期:2018-06-06 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The instance containing the event data. protected override void OnLoad(EventArgs e) { try { this.pdfEditorEx1.InitPdfEditor(); this.InitializeSetting(); this.pdfEditorEx1.OnSaveCallBack += new EventHandler(OnSaveClick); this.pdfEditorEx1.OnDeleteCallBack += new EventHandler(OnDeleteClick); this.pdfEditorEx1.OnSaveAsCallBack += new EventHandler(OnSaveAsClick); //附件下载成功回调 AttachHelper.OnDownLoadSuccess += new EventHandler(AttachHelper_OnDownLoadSuccess); } catch (Exception ex) { LogHelper.Instance.WriteError(ex); MessageUtil.Show(ex.StackTrace); } } /// /// 说明:获取用户签名图片 /// 创建人:姜棚 /// 创建日期:2018-06-06 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void GetSignPic() { DataTable dt = MainImpl.Instance.GetEmployeeList(ERPInfo.Instance.UserId); if (dt.Rows.Count > 0) { byte[] bitMap = dt.Rows[0]["signBmp"] as byte[]; if (bitMap.Length > 0) this.pdfEditorEx1.SignImage = ImageHelper.ReadImage(bitMap); } else { MessageUtil.Show(ResourceKeys.NotSignPic); } } /// /// 说明:获取模板源文件 /// 创建人:姜棚 /// 创建日期:2018-06-06 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void GetPdfTemplet() { DataRow rowItem = AttachImpl.Instance.GetTempletFile(this.SysModel.PdfFileId); if (rowItem != null) { string fileName = rowItem["sName"] + ""; string filePath = PubUtil.FileDownLoadTempPath + fileName; if (fileName.Contains(".pdf")) { this._signSources = AttachImpl.Instance.GetSignSources(this.SysModel.PdfFileId); this.pdfEditorEx1.TempletFilePath = filePath; string tipMsg = string.Empty; if (!File.Exists(filePath)) { if (AttachImpl.Instance.CheckAttachOperation(2, "", this.SysModel.PdfFileId, fileName, 0, out tipMsg) == 1) { string serverPath = Path.Combine(SystemInfo.Instance.ServerAttachPath, BaseModuleImpl.Instance.GetFileServerPath(this.SysModel.PdfFileId)); AttachHelper.DownLoadFile(this.Handle, serverPath); } } else { this.pdfEditorEx1.InitPdfPage(this._signSources); } } } } /// /// 说明:初始化设置 /// 创建人:姜棚 /// 创建日期:2018-06-06 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitializeSetting() { if (this.SysModel.PdfFileId == 0) return; this.GetPdfTemplet(); this.GetSignPic(); } /// /// 说明:添加签名数据 /// 创建人:姜棚 /// 创建日期:2018-06-06 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InsertSignPoint() { try { this.pdfEditorEx1.CurrentId = AttachImpl.Instance.InsertSignPoint(this.SysModel, ImageHelper.ConvertImage(this.pdfEditorEx1.SignImage), this.pdfEditorEx1.SignBoxPoint.X, this.pdfEditorEx1.SignBoxPoint.Y, this.pdfEditorEx1.CurrentPageNo); if (this.pdfEditorEx1.CurrentId == 0) MessageUtil.Show(ResourceKeys.SaveFault); } catch (Exception ex) { LogHelper.Instance.WriteError(ex); } } /// /// 说明:删除 /// 创建人:姜棚 /// 创建日期:2018-06-06 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The o. /// The instance containing the event data. protected void OnDeleteClick(object o, EventArgs e) { this.pdfEditorEx1.Delete(); //如果数据库存在该条记录进行删除 if (this.pdfEditorEx1.CurrentId > 0) { if (AttachImpl.Instance.DeleteSignPoint(this.pdfEditorEx1.CurrentId) > 0) { //删除后重新获取签名集 this._signSources = AttachImpl.Instance.GetSignSources(this.SysModel.PdfFileId); this.pdfEditorEx1.InitPdfPage(this._signSources); } } } /// /// 说明:窗口关闭关闭文档 /// 创建人:姜棚 /// 创建日期:2018-06-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void OnFormClosing(object sender, FormClosingEventArgs e) { this.pdfEditorEx1.Close(); } /// /// 说明:保存 /// 创建人:姜棚 /// 创建日期:2018-06-06 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The o. /// The instance containing the event data. protected void OnSaveClick(object o, EventArgs e) { //根据pic控件显隐判断点击保存前是否操作过 if (this.pdfEditorEx1.PicBox.Visible) { InsertSignPoint(); //插入后记录当前数据主键,方便清除时候用 if (this.pdfEditorEx1.CurrentId > 0) { this.pdfEditorEx1.Save(); } } } /// /// 说明:另存为 /// 创建人:姜棚 /// 创建日期:2018-06-07 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The o. /// The instance containing the event data. protected void OnSaveAsClick(object o, EventArgs e) { bool saveState = this.pdfEditorEx1.SaveAs(); if (saveState) InsertSignPoint(); } /// /// 说明:下载成功 /// 创建人:姜棚 /// 创建日期:2018-06-07 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void AttachHelper_OnDownLoadSuccess(object sender, EventArgs e) { if (AttachHelper.IsDefWndProc(this.Handle, (System.Windows.Forms.Message)sender)) { this.pdfEditorEx1.InitPdfPage(this._signSources); } } /// /// 说明:消息处理 /// 创建人:姜棚 /// 创建日期:2018-06-07 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// 要处理的 Windows。 protected override void DefWndProc(ref Message m) { base.DefWndProc(ref m); if (this.Handle == m.HWnd) AttachHelper.DefWndProc(m); } } }