PDA物流快递条码扫描系统

 PDA物流快递条码扫描系统

快件扫描、拍照上传,电子签名上传

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using handset_dll;
using System.Threading;
using System.Media;//for netcf 3.5
using System.IO;
using System.Runtime.InteropServices;
using deliverSys.Utils;
 
using PocketSignature;
using System.Reflection;
using System.Text.RegularExpressions;
 

namespace deliverSys
{
    public partial class FrmMain : Form
    {
       
        private Scan_Interface scan_demo = new Scan_Interface();
        private int Scan_Method = 0;
        private volatile bool thread_exit = false;
        private string scan_text;       
        private Gprs_connect gprs_conn = new Gprs_connect();
        public FrmSign frmSign;      
        public FrmCaption frmCaption;
        //签名
        public string imgPath = "";
        public string signPath = "";//签名文件

        public FrmMain()
        {
            InitializeComponent();           
        }

        //拍照
        private void butPic_Click(object sender, EventArgs e)
        {
            frmCaption = new FrmCaption(this);
            frmCaption.Show();
            this.Hide();
        }
        //提交
        private void butSend_Click(object sender, EventArgs e)
        {
            string sImgName="", sSignName="";
            Globals.Ht.Clear();          
            if (!imgPath.Equals(""))
            {
                sImgName = txtDeliver.Text + "-" + DateTime.Now.ToString("yyyyMMddHHmmss")+".jpg";
                Globals.Ht.Add(sImgName,  imgPath);
            }
            if (!signPath.Equals(""))
            {
                sSignName = txtDeliver.Text+"-"+signPath;
                Globals.Ht.Add(sSignName, Globals.CaptionPath + signPath);
            }
            string sSql = "insert into deliverSendingPieces([id],[Barcode],[Staffer],[Description],[picPath],[signPath],[createData],[memo]) "+
                        " values('" + DateTime.Now.ToString("yyyyMMddHHmmss") + "','" + this.txtBarcode.Text + "','" + txtDeliver.Text+ "',"+
                        " '" + this.txtDecript.Text + "','" + sImgName + "','" + sSignName + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','')";

            Cursor.Current = Cursors.WaitCursor;
            bool bReturn = Globals.uploadRecord(sSql, Globals.Ht);
            Cursor.Current = Cursors.Default;
            if (bReturn)
            {
                MessageBox.Show("上传成功!");
            }
            else
                MessageBox.Show("上传失败!");
        }
        //退出
        private void butExit_Click(object sender, EventArgs e)
        {
         
            if (butScan.Text.Equals("停止"))
            {
                thread_exit = true;
                if (scanthread != null)
                {
                    if (!scanthread.Join(2000))
                        scanthread.Abort();
                }
                scan_demo.Scan_Close();             
            }
            gprs_conn.Disconnect();
          
            this.Close();
            Application.Exit();
        }
        //扫描
        private delegate void scan_delegate();//代理
        private Thread scanthread = null;
        private void butScan_Click(object sender, EventArgs e)
        {
          
            if (butScan.Text.Equals("停止"))
            {
                thread_exit = true;
                if (!scanthread.Join(2000))
                    scanthread.Abort();
                scan_demo.Scan_Close();
                butScan.Text = "扫描";
            }
            else
            {
                thread_exit = false;
                if (scan_demo.com_open)
                    return;
                scan_demo.Scan_Open();

                Scan_Method = 2;
                this.butScan.Text = "停止";
                scanthread = new Thread(new ThreadStart(scan_todo));
                scanthread.Start();
            }
           
        }

        private void scan_display()
        {
            this.txtBarcode.Text = scan_text;
        }        
        private void scan_todo()
        {
           
            scan_delegate fc = new scan_delegate(scan_display);

            byte[] temp = new byte[0xff];
            temp[0] = 0x00;
            scan_demo.Scan_Write(ref temp, 1);
            Thread.Sleep(100);
            temp[0] = 0x07;
            temp[1] = 0xc6;
            temp[2] = 0x04;
            temp[3] = 0x00;
            temp[4] = 0x00;
            temp[5] = 0x8a;
            temp[6] = 0x04;
            temp[7] = 0xfe;
            temp[8] = 0xa1;
            scan_demo.Scan_Write(ref temp, 9);

            //Thread.Sleep(10);
            //for(int i=0;i<10;i++)
            //    scan_text = scan_demo.Scan_Read();
            scan_text = "";
            while (true)
            {
                Thread.Sleep(10);
                scan_text = scan_demo.Scan_Read();
                if (scan_text.Length > 5)
                {
                    this.Invoke(fc);
                    break;
                }
                if (thread_exit)
                    break;


            }
            scan_demo.Scan_Close();             
        }       
      

        private void FrmMain_Load(object sender, EventArgs e)
        {
            try
            {
                thread_exit = true;
                if (scanthread != null)
                {
                    if (!scanthread.Join(2000))
                        scanthread.Abort();
                }
                scan_demo.Scan_Close();

                //gprs连接
                gprs_conn.Connect();

            }
            catch (Exception ex)
            {
                Globals.WriteLog("启动出错:" + ex.ToString());
            }
        }
        //签名
        private void button1_Click(object sender, EventArgs e)
        {
            frmSign = new FrmSign(this);
            frmSign.Show();
            this.Hide();
        }

    
    }
}

 

 

 原创文章,禁止做为商用,版权为浩瀚技术团队,转载请注明出处:http://blog.csdn.net/haohantech

你可能感兴趣的:(移动POS系统软件)