zoukankan      html  css  js  c++  java
  • 将sql20005 的数据同步PDA的sqlce数据库中

    一.创建项目

       打开visual 2005,文件->新建->项目

     

    二.设计界面,编写代码

    首先进行系统界面设计,编写相关逻辑代码处理

    在初始化窗体时,加载扫描头触发事件

    private SymbolScanWood.SymbolScanWood _objScan = new SymbolScanWood.SymbolScanWood("Text");

    private void Zone_Load(object sender, EventArgs e)
    {
            Cursor.Current 
    = Cursors.WaitCursor;
            _objScan.MyAfterRead 
    += new EventHandler(_objScan_OnAfterRead);
            Cursor.Current 
    = Cursors.Default;
     }

    private void _objScan_OnAfterRead(object sender, EventArgs e)
            
    {
                tbZone.Text 
    = _objScan.BarcodeText;//进行扫描相关逻辑处理
            }

    窗体关闭时,关闭扫描头,释放扫描头资源,同时保存数据

            private void Zone_Closing(object sender, CancelEventArgs e)
            
    {
                _objScan.TermReader();
            }

    程序中引用的symbolScanWood.dll代码如下:

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace SymbolScanWood
    {
        
    public class SymbolScanWood
        
    {
            
    private string _strBarcode = "";
            
    private byte[] _byteBarcodeData;
            
    private string _strBarcodeType;
            
    private int _nBarcodeLenth = 0;
            
    private bool _bSuccess = false;
            
    private DateTime _dTimeStamp;
            
    private string _strDataType;

            
    private Symbol.Barcode.Reader _MyReader = null;
            
    private Symbol.Barcode.ReaderData _MyReaderData = null;
            
    private System.EventHandler _MyEventHandler = null;
            
    private event System.EventHandler _MyAfterRead = null;

            
    public string BarcodeText
            
    {
                
    get return _strBarcode; }
            }


            
    public byte[] BarcodeData
            
    {
                
    get return _byteBarcodeData; }
            }


            
    public string BarcodeType
            
    {
                
    get return _strBarcodeType; }
            }


            
    public int BarcodeLenth
            
    {
                
    get return _nBarcodeLenth; }
            }


            
    public bool Success
            
    {
                
    get return _bSuccess; }
            }


            
    public DateTime TimeStamp
            
    {
                
    get return _dTimeStamp; }
            }


            
    public string DataType
            
    {
                
    get return _strDataType; }
            }


            
    public SymbolScanWood(string strDataType)
            
    {
                
    if ((strDataType != "Text"&& (strDataType != "Binary"))
                
    {
                    
    throw new Exception("设置扫描类型错误!");
                }

                
    this._MyReader = null;
                
    this._strDataType = strDataType;
                
    this._MyReaderData = null;
                
    this._MyEventHandler = null;
                
    this._bSuccess = false;
                
    this._strBarcodeType = "";
                
    this._nBarcodeLenth = 0;
                
    this._dTimeStamp = DateTime.Now;
                
    this._strBarcode = "";
                
    this._byteBarcodeData = new byte[0];

                InitReader();
                
    this.StartRead();
            }


            
    ~SymbolScanWood()
            
    {
                
    this.StopRead();
                
    this.TermReader();
            }


            
    public System.EventHandler MyAfterRead
            
    {
                
    get{return _MyAfterRead;}
                
    set{_MyAfterRead=value;}
            }



            
    /// <summary>
            
    /// Initialize the reader.
            
    /// </summary>

            public bool InitReader()
            
    {
                
    // If reader is already present then fail initialize
                if (_MyReader != null)
                
    {
                    
    return false;
                }


                
    // Create new reader, first available reader will be used.
                _MyReader = new Symbol.Barcode.Reader();

                
    // Create reader data
                if(_strDataType.ToLower().Trim() == "Binary")
                
    {
                    _MyReaderData 
    = new Symbol.Barcode.ReaderData(
                        Symbol.Barcode.ReaderDataTypes.Binary,
                        Symbol.Barcode.ReaderDataLengths.MaximumLabel);
                }

                
    else
                
    {
                    _MyReaderData 
    = new Symbol.Barcode.ReaderData(
                        Symbol.Barcode.ReaderDataTypes.Text,
                        Symbol.Barcode.ReaderDataLengths.MaximumLabel);
                }


                
    this._MyEventHandler = new EventHandler(MyReader_ReadNotify);

                
    // Enable reader, with wait cursor
                _MyReader.Actions.Enable();

                _MyReader.Parameters.Feedback.Success.BeepTime 
    = 0;
                _MyReader.Parameters.Feedback.Success.WaveFile 
    = "\windows\alarm3.wav";

                
    return true;
            }


            
    /// <summary>
            
    /// Stop reading and disable/close reader
            
    /// </summary>

            public void TermReader()
            
    {
                
    // If we have a reader
                if ( this._MyReader != null )
                
    {
                    
    // Disable the reader
                    this._MyReader.Actions.Disable();

                    
    // Free it up
                    this._MyReader.Dispose();

                    
    // Indicate we no longer have one
                    this._MyReader = null;
                }


                
    // If we have a reader data
                if ( this._MyReaderData != null )
                
    {
                    
    // Free it up
                    this._MyReaderData.Dispose();

                    
    // Indicate we no longer have one
                    this._MyReaderData = null;
                }

            }


            
    /// <summary>
            
    /// Start a read on the reader
            
    /// </summary>

            public void StartRead()
            
    {
                
    // If we have both a reader and a reader data
                if ( ( this._MyReader != null ) &&
                    ( 
    this._MyReaderData != null ) )
                
    {
                    
    // Submit a read
                    this._MyReader.ReadNotify += this._MyEventHandler;
                    
    this._MyReader.Actions.Read(this._MyReaderData);
                }

            }


            
    /// <summary>
            
    /// Stop all reads on the reader
            
    /// </summary>

            public void StopRead()
            
    {
                
    // If we have a reader
                if ( this._MyReader != null )
                
    {
                    
    // Flush (Cancel all pending reads)
                    this._MyReader.ReadNotify -= this._MyEventHandler;
                    
    this._MyReader.Actions.Flush();
                }

            }


            
    /// <summary>
            
    /// Read complete or failure notification
            
    /// </summary>

            private void MyReader_ReadNotify(object sender, EventArgs e)
            
    {
                Symbol.Barcode.ReaderData TheReaderData 
    = this._MyReader.GetNextReaderData();

                
    // If it is a successful read (as opposed to a failed one)
                if ( TheReaderData.Result == Symbol.Results.SUCCESS )
                
    {
                    _bSuccess 
    = true;
                    
    // Handle the data from this read
                    this.HandleData(TheReaderData);

                    
    // Start the next read
                    this.StartRead();
                }

                
    else
                
    {
                    _bSuccess 
    = false;
                }


                
    if(_MyAfterRead != null)
                    _MyAfterRead(sender, e);
            }


            
    /// <summary>
            
    /// Handle data from the reader
            
    /// </summary>

            private void HandleData(Symbol.Barcode.ReaderData TheReaderData)
            
    {
                _nBarcodeLenth 
    = TheReaderData.Length;
                _strBarcodeType 
    = TheReaderData.Type.ToString();
                _dTimeStamp 
    = TheReaderData.TimeStamp;

                
    if(_strDataType.Trim() == "Text")
                
    {
                    _strBarcode 
    = TheReaderData.Text;
                }

                
    else
                
    {
                    _byteBarcodeData 
    = new byte[_nBarcodeLenth];
                    
    for (int i = 0; i < _nBarcodeLenth; i++)
                    
    {
                        _byteBarcodeData[i] 
    = TheReaderData.RawData[i];
                    }

                }

            }

        }

    }

  • 相关阅读:
    【转载】我的七个建议Joel Spolsky
    C语言文件读写操作
    【转】RO段、RW段和ZI段 Image$$??$$Limit 含义(zz)
    给大家一个测试webservice的软件
    .net 实现深拷贝的方法
    第一次设计数据访问层,大家给你建议,谢谢
    重新写博客
    (转)理解 Thread.Sleep 函数
    slk解压缩
    SMTP Service设置
  • 原文地址:https://www.cnblogs.com/ziyan22/p/1241311.html
Copyright © 2011-2022 走看看