汉王签批板ESP370U与C#窗体系统对接

来源:互联网 发布:远程教育软件 编辑:程序博客网 时间:2024/04/30 12:32

汉王签批板ESP370U与C#窗体系统对接,所见即所得的签名方式。

1,

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;namespace HanWangSM.汉王ESP370签批板{    /// <summary>    /// Form签批板    /// author CYTD Young    /// 2017-01-16 14:28:17    /// music: Stan Getz - Stan Getz & Kenny Barron - First Song (For Ruth)    /// book: 张爱玲 - 多少恨    /// </summary>    public partial class Form签批板 : Form    {        //inform message definition        static int complete_msg = 0x7ffe;        static int cancel_msg = 0x7ffd;        //return value of interface function        /// <summary>        /// 成功        /// </summary>        static int HW_eOk = 0;      //success        /// <summary>        /// 未找到对应的汉王手写设备        /// </summary>        static int HW_eDeviceNotFound = -1;     //no device        /// <summary>        /// 手写模块加载失败        /// </summary>        static int HW_eFailedLoadModule = -2;   //failed to load module        /// <summary>        /// 手写模块初始化失败        /// </summary>        static int HW_eFailedInitModule = -3;   //failed to inti module         /// <summary>        /// 不支持的图片格式        /// </summary>        static int HW_eWrongImageFormat = -4;   //do not support this image format        /// <summary>        /// 没有签名数据        /// </summary>        static int HW_eNoSignData = -5;         //no sign data        /// <summary>        /// 无效输入参数        /// </summary>        static int HW_eInvalidInput = -6;       //invalid input parameter        /// <summary>        /// 保存路径及文件名        /// </summary>        static string savePath = "";        /// <summary>        /// 签名的图片对象        /// </summary>        public Bitmap SavedBitmap;        public Form签批板()        {            InitializeComponent();            axHWPenSign1.HWSetBkColor(0xE0F8E0);            //axHWPenSign1.HWSetBkColor((uint)ColorTranslator.ToWin32(Color.Transparent));            //axHWPenSign1.HWSetBkColor((uint)ColorTranslator.ToWin32(Color.White));            axHWPenSign1.HWSetCtlFrame(2, 0x000000);            savePath = Application.StartupPath + "\\image\\hwsign\\Sign" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".bmp";            axHWPenSign1.HWSetFilePath(savePath);            axHWPenSign1.HWSetExtWndHandle(this.Handle.ToInt32());            this.NewMethod打开设备();        }        protected override void WndProc(ref Message m)        {            if (m.Msg == complete_msg)            {                //MessageBox.Show("Confirm Sign");                //SavedBitmap = new Bitmap(savePath);                //this.DialogResult = DialogResult.OK;                //this.Close();                this.NewMethod保存();                this.NewMethod关闭设备();            }            else if (m.Msg == cancel_msg)            {                //MessageBox.Show("Clear Sign");            }            base.WndProc(ref m);        }        /// <summary>        /// 打开设备        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button打开设备_Click(object sender, EventArgs e)        {            NewMethod打开设备();        }        /// <summary>        /// 打开设备        /// </summary>        private void NewMethod打开设备()        {            int res = axHWPenSign1.HWInitialize();            if (res != HW_eOk)            {                MessageBox.Show("Failed to open device");            }        }        /// <summary>        /// 关闭设备        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button关闭设备_Click(object sender, EventArgs e)        {            NewMethod关闭设备();        }        /// <summary>        /// 关闭设备        /// </summary>        private void NewMethod关闭设备()        {            axHWPenSign1.HWFinalize();        }        /// <summary>        /// 清除        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button清除_Click(object sender, EventArgs e)        {            NewMethod清除();        }        private void NewMethod清除()        {            axHWPenSign1.HWClearPenSign();        }        /// <summary>        /// 保存        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button保存图像_Click(object sender, EventArgs e)        {            NewMethod保存();        }        /// <summary>        /// 保存        /// </summary>        private void NewMethod保存()        {            axHWPenSign1.HWSaveFile();            SavedBitmap = new Bitmap(savePath);            this.DialogResult = DialogResult.OK;            this.Close();        }        /// <summary>        /// 传当前需要签名的名字进来,防止签错别人的名字        /// </summary>        /// <param name="signName"></param>        public void setSignName(string signName)        {            if (string.IsNullOrWhiteSpace(signName)) { }            else            {                this.button保存图像.Text = string.Format("保存{0}的签名", signName);                this.button清除.Text = string.Format("重写{0}的签名", signName);                this.Text += string.Format("  --  {0} ", signName);            }        }        private void button关闭_Click(object sender, EventArgs e)        {            this.NewMethod关闭设备();            NewMethod关闭();        }        /// <summary>        /// 关闭        /// </summary>        private void NewMethod关闭()        {            this.DialogResult = DialogResult.Cancel;            this.Close();        }        private void Form签批板_KeyUp(object sender, KeyEventArgs e)        {            if (e.KeyCode == Keys.Enter)            {//保存                 this.NewMethod保存();                this.NewMethod关闭设备();            }            else if (e.KeyCode == Keys.Escape)            {//退出                this.NewMethod关闭设备();                this.NewMethod关闭();            }            else if (e.KeyCode == Keys.Delete)            {//清空                this.NewMethod清除();            }        }    }}


2,

namespace HanWangSM.汉王ESP370签批板{    partial class Form签批板    {        /// <summary>        /// 必需的设计器变量。        /// </summary>        private System.ComponentModel.IContainer components = null;        /// <summary>        /// 清理所有正在使用的资源。        /// </summary>        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>        protected override void Dispose(bool disposing)        {            if (disposing && (components != null))            {                components.Dispose();            }            base.Dispose(disposing);        }        #region Windows 窗体设计器生成的代码        /// <summary>        /// 设计器支持所需的方法 - 不要        /// 使用代码编辑器修改此方法的内容。        /// </summary>        private void InitializeComponent()        {            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form签批板));            this.axHWPenSign1 = new AxHWPenSignLib.AxHWPenSign();            this.button打开设备 = new System.Windows.Forms.Button();            this.button关闭设备 = new System.Windows.Forms.Button();            this.button清除 = new System.Windows.Forms.Button();            this.button保存图像 = new System.Windows.Forms.Button();            this.panel签名区 = new System.Windows.Forms.Panel();            this.panel确认区 = new System.Windows.Forms.Panel();            this.button关闭 = new System.Windows.Forms.Button();            ((System.ComponentModel.ISupportInitialize)(this.axHWPenSign1)).BeginInit();            this.panel签名区.SuspendLayout();            this.panel确认区.SuspendLayout();            this.SuspendLayout();            //             // axHWPenSign1            //             this.axHWPenSign1.Dock = System.Windows.Forms.DockStyle.Fill;            this.axHWPenSign1.Enabled = true;            this.axHWPenSign1.Location = new System.Drawing.Point(0, 0);            this.axHWPenSign1.Name = "axHWPenSign1";            this.axHWPenSign1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axHWPenSign1.OcxState")));            this.axHWPenSign1.Size = new System.Drawing.Size(603, 419);            this.axHWPenSign1.TabIndex = 0;            //             // button打开设备            //             this.button打开设备.Dock = System.Windows.Forms.DockStyle.Left;            this.button打开设备.Location = new System.Drawing.Point(252, 0);            this.button打开设备.Name = "button打开设备";            this.button打开设备.Size = new System.Drawing.Size(92, 24);            this.button打开设备.TabIndex = 1;            this.button打开设备.Text = "打开设备";            this.button打开设备.UseVisualStyleBackColor = true;            this.button打开设备.Visible = false;            this.button打开设备.Click += new System.EventHandler(this.button打开设备_Click);            //             // button关闭设备            //             this.button关闭设备.Dock = System.Windows.Forms.DockStyle.Left;            this.button关闭设备.Location = new System.Drawing.Point(162, 0);            this.button关闭设备.Name = "button关闭设备";            this.button关闭设备.Size = new System.Drawing.Size(90, 24);            this.button关闭设备.TabIndex = 2;            this.button关闭设备.Text = "关闭设备";            this.button关闭设备.UseVisualStyleBackColor = true;            this.button关闭设备.Visible = false;            this.button关闭设备.Click += new System.EventHandler(this.button关闭设备_Click);            //             // button清除            //             this.button清除.Dock = System.Windows.Forms.DockStyle.Left;            this.button清除.Location = new System.Drawing.Point(78, 0);            this.button清除.Name = "button清除";            this.button清除.Size = new System.Drawing.Size(84, 24);            this.button清除.TabIndex = 3;            this.button清除.Text = "清除";            this.button清除.UseVisualStyleBackColor = true;            this.button清除.Click += new System.EventHandler(this.button清除_Click);            //             // button保存图像            //             this.button保存图像.Dock = System.Windows.Forms.DockStyle.Left;            this.button保存图像.Location = new System.Drawing.Point(0, 0);            this.button保存图像.Name = "button保存图像";            this.button保存图像.Size = new System.Drawing.Size(78, 24);            this.button保存图像.TabIndex = 4;            this.button保存图像.Text = "保存";            this.button保存图像.UseVisualStyleBackColor = true;            this.button保存图像.Click += new System.EventHandler(this.button保存图像_Click);            //             // panel签名区            //             this.panel签名区.Controls.Add(this.axHWPenSign1);            this.panel签名区.Dock = System.Windows.Forms.DockStyle.Fill;            this.panel签名区.Location = new System.Drawing.Point(0, 0);            this.panel签名区.Name = "panel签名区";            this.panel签名区.Size = new System.Drawing.Size(603, 419);            this.panel签名区.TabIndex = 0;            //             // panel确认区            //             this.panel确认区.Controls.Add(this.button关闭);            this.panel确认区.Controls.Add(this.button打开设备);            this.panel确认区.Controls.Add(this.button关闭设备);            this.panel确认区.Controls.Add(this.button清除);            this.panel确认区.Controls.Add(this.button保存图像);            this.panel确认区.Dock = System.Windows.Forms.DockStyle.Bottom;            this.panel确认区.Location = new System.Drawing.Point(0, 419);            this.panel确认区.Name = "panel确认区";            this.panel确认区.Size = new System.Drawing.Size(603, 24);            this.panel确认区.TabIndex = 5;            //             // button关闭            //             this.button关闭.Dock = System.Windows.Forms.DockStyle.Left;            this.button关闭.Location = new System.Drawing.Point(344, 0);            this.button关闭.Name = "button关闭";            this.button关闭.Size = new System.Drawing.Size(84, 24);            this.button关闭.TabIndex = 5;            this.button关闭.Text = "关闭";            this.button关闭.UseVisualStyleBackColor = true;            this.button关闭.Click += new System.EventHandler(this.button关闭_Click);            //             // Form签批板            //             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;            this.ClientSize = new System.Drawing.Size(603, 443);            this.ControlBox = false;            this.Controls.Add(this.panel签名区);            this.Controls.Add(this.panel确认区);            this.Name = "Form签批板";            this.Text = "创元一方 签批板";            this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form签批板_KeyUp);            ((System.ComponentModel.ISupportInitialize)(this.axHWPenSign1)).EndInit();            this.panel签名区.ResumeLayout(false);            this.panel确认区.ResumeLayout(false);            this.ResumeLayout(false);        }        #endregion        private AxHWPenSignLib.AxHWPenSign axHWPenSign1;        private System.Windows.Forms.Button button打开设备;        private System.Windows.Forms.Button button关闭设备;        private System.Windows.Forms.Button button清除;        private System.Windows.Forms.Button button保存图像;        private System.Windows.Forms.Panel panel签名区;        private System.Windows.Forms.Panel panel确认区;        private System.Windows.Forms.Button button关闭;    }}


3,

       if (HanWangSM)            {                HanWangSM.汉王ESP370签批板.Form签批板 dlg = new HanWangSM.汉王ESP370签批板.Form签批板();                DataTable dt = BLLUtil.GetTableData(TableFieldBase.T_SINGLE_CHECKINFO.T_NAME, TableFieldBase.T_SINGLE_CHECKINFO.SGLCHECKID, this.strSglCheckID);                if (dt == null || dt.Rows.Count < 1) { }                else                {                    string name = dt.Rows[0][TableFieldBase.T_SINGLE_CHECKINFO.NAME] == null ? "" : dt.Rows[0][TableFieldBase.T_SINGLE_CHECKINFO.NAME].ToString();                    if (string.IsNullOrWhiteSpace(name)) { }                    else                    {                        dlg.setSignName(name);                    }                }                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)                {                    Image Image = dlg.SavedBitmap;                    MemoryStream ms = new MemoryStream();                    dlg.SavedBitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);                    byte[] bytes = ms.GetBuffer();  //byte[]   bytes=   ms.ToArray(); 这两句都可以,至于区别么,下面有解释                    ms.Close();                    DataTable dtImage = BLLUtil.GetTableData(TableField.T_IMAGE.T_NAME, TableField.T_IMAGE.SGLCHECKID, this.strSglCheckID,                    TableField.T_IMAGE.FTYPE, EnumImageType.个人签名.ToString("d"));                    T_IMAGEEntity tImage = new T_IMAGEEntity();                    tImage.IMAGES = bytes;                    tImage.FTYPE = EnumImageType.个人签名.ToString("d");                    tImage.IMAGEEXTEN = Path.GetExtension(".bmp");                    tImage.OPERATEDATE = DateTime.Now;                    tImage.OPERATEDEPT = this.CurDeptID;                    tImage.OPERATOR = this.CurEmpID;                    tImage.UPFLAG = "1";                    tImage.SGLCHECKID = this.strSglCheckID;                    //如果已经存在签名,替换                    if (dtImage != null && dtImage.Rows.Count > 0)                    {                        tImage.FID = dtImage.Rows[0][TableField.T_IMAGE.FID].ToString();                        BLLBaseInfo.SaveImage(tImage, 2);                    }                    else                    {//新加签名                        tImage.FID = CYYFWebService.BLLWebService.GetPK(TableField.T_IMAGE.T_NAME);                        BLLBaseInfo.SaveImage(tImage, 1);                    }                }            }


4,


5,


6,




0 0