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 { /// /// 当前文档主键 /// public string BillDocumentId; /// /// 单据明细ID /// public string BillDeatilId; /// /// 步骤 /// public string StepCode; /// /// 图片来源 /// public string PicSourceField; /// /// pdf文件主键值 /// public string PdfFileId; /// /// pdf源文件目录 /// private string _dicPath = PubUtil.AbsolutelyPath + "tempfiles/"; /// /// 服务器地址 /// private string _serverPath = string.Empty; /// /// 签名图片流 /// private byte[] _imageStream; /// /// 签名数据源 /// private DataTable _signList; /// /// The m_ client test handle /// private IntPtr _mClientTestHandle = IntPtr.Zero; public FrmMain() { InitializeComponent(); } /// /// 说明:窗口加载 /// 创建人:姜棚 /// 创建日期:2018-06-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The instance containing the event data. 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); } } /// /// 说明:初始化属性值 /// 创建人:姜棚 /// 创建日期:2018-06-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitializeSetting() { if (string.IsNullOrEmpty(this.PdfFileId)) return; this.GetServerPath(); this.GetTempletFile(); this.GetSignPic(); } /// /// 说明:获取签名图片 /// 创建人:姜棚 /// 创建日期:2018-06-04 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// 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("没有配置签名字段"); } } /// /// 说明:获取该pdf文件的签名来源 /// 创建人:姜棚 /// 创建日期:2018-06-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// 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); } /// ///说明:获取源pdf文件 ///创建人:姜棚 ///创建日期:2018-06-01 ///修改人: ///修改日期: ///修改备注: ///版本:1.0 /// 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); } } } } /// /// 说明:获取服务地址 /// 创建人:姜棚 /// 创建日期:2018-06-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.String. 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; } } /// /// 说明:下载 /// 创建人:姜棚 /// 创建日期:2018-06-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The filedvalue. /// The filedname. 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); } } /// /// 说明:向数据库插入数据 /// 创建人:姜棚 /// 创建日期:2018-06-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// 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); } } /// /// 说明:附件验证 /// 创建人:龚宇超 /// 创建日期:2017-09-28 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// 1=上传,2=下载,3=删除,4=锁定,5=解除锁定 必填 /// The user identifier. /// Name of the user. /// The file specis no. /// The filename. /// The filesize. /// true if XXXX, false otherwise. 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; } /// /// 说明:下载消息处理 /// 创建人:姜棚 /// 创建日期:2018-06-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// 要处理的 Windows。 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); } } /// /// 说明:保存 /// 创建人:姜棚 /// 创建日期:2018-06-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// protected void OnSavePdfView(object o, EventArgs e) { if (this.pdfSignEx.PicBox.Visible) { InsertPoint(); //插入后记录当前数据的ID 方便删除 if (this.pdfSignEx.CurrentId > 0) { this.pdfSignEx.Save(); } } } /// /// 说明:另存为 /// 创建人:姜棚 /// 创建日期:2018-06-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The o. /// The instance containing the event data. protected void OnSaveAsPdfView(object o, EventArgs e) { //另存成功后 bool saveSate = this.pdfSignEx.SaveAs(); if (saveSate) InsertPoint(); } /// /// 说明:删除 /// 创建人:姜棚 /// 创建日期:2018-06-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The o. /// The instance containing the event data. 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); } } } /// /// 说明:打开文件(先屏蔽) /// 创建人:姜棚 /// 创建日期:2018-06-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// protected void OnOpenFile(object o, EventArgs e) { } /// /// 说明:关闭 /// 创建人:姜棚 /// 创建日期:2018-06-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void FrmMain_FormClosing(object sender, FormClosingEventArgs e) { this.pdfSignEx.ClosePDFViewer(); } } }