/// <summary>
        /// 开始初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.btnSave.Text == "结束初始化")
            {
                timer_start.Enabled = false;
                this.btnSave.Text   = "开始初始化";
                return;
            }

            int iExist = Convert.ToInt32(DbHelperSQL.GetSingle("Select Count(0) from TT_RFCard where CardCode='" + this.txtREFCode.Text + "'"));

            if (this.txtREFCode.Text.Trim() == "")
            {
                MessageBox.Show("请点击获取电子标签起始号!");
                return;
            }

            if (!DbHelperSQL.bolIsNumber(txtREFCode.Text.Trim(), iRfLen))//判断卡号是否是10位数字
            {
                this.lblTips.Text = "起始卡号只能为" + iRfLen + "位的数字!";
                return;
            }
            if (iExist > 0)
            {
                this.lblTips.Text = "获取到的电子标签起始号已经存在,请联系开发人员!";

                txtCardCode.Clear();
                return;
            }


            if (txtCardCode.Text.Trim() == "")
            {
                this.lblTips.Text = "没有读取到电子标签号";

                return;
            }

            if (iExist == 0)
            {
                string strCardCode = this.rfCard.CardCode;
                //int iIsInit = Convert.ToInt32(DbHelperSQL.GetSingle("Select Count(0) from TT_RFCard where CardCode='" + strCardCode + "'"));
                int iIsInit = Convert.ToInt32(DbHelperSQL.GetSingle("Select Count(0) from TT_RFCard where CardCode='" + txtCardCode.Text.Trim() + "'"));
                if (iIsInit != 0)
                {
                    DialogResult result = MessageBox.Show("该卡已经初始化过,是否再初始化一遍", "天大天科卡初始化系统", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (result == DialogResult.No)
                    {
                        return;
                    }
                }
                short iSuccess = -1;
                while (iSuccess != 0)
                {
                    iSuccess = this.rfCard.RfWrite(this.txtREFCode.Text.Trim());
                }
                if (iSuccess == 0)//电子标签内部写入成功
                {
                    DateTime nowTime   = DateTime.Now;
                    string   sqlInsert = string.Empty;
                    if (iIsInit == 0)
                    {
                        DbHelperSQL.ExecuteSql("Insert into TT_RFCard Values('" + this.txtREFCode.Text + "'," + nowTime + ",'" + ini.IniReadValue("UserInfo", "UserCode") + "')");

                        #region 插入sql语句到同步表中
                        sqlInsert = "insert [NetWorkDisconnectionLog] (ID, SQLcontext, datetime, IP) values (@ID,@SQLcontext,@datetime,@IP)";
                        SqlParameter[] sqlpars = new SqlParameter[]
                        {
                            new SqlParameter("@ID", DateTime.Now.ToString()),
                            new SqlParameter("@SQLcontext", "Insert into TT_RFCard Values('" + this.txtREFCode.Text + "'," + nowTime + ",'" + ini.IniReadValue("UserInfo", "UserCode") + "')"),
                            new SqlParameter("@datetime", DateTime.Now.ToString()),
                            new SqlParameter("@IP", "172.10.14.1")
                        };
                        DbHelperSQL.ExecuteSql(sqlInsert);
                        #endregion
                    }
                    else
                    {
                        DbHelperSQL.ExecuteSql("Update TT_RFCard Set CardCode='" + this.txtREFCode.Text + "',InitialTime='" + nowTime + "' where CardCode='" + txtCardCode.Text.Trim() + "'");

                        #region 插入sql语句到同步表中
                        sqlInsert = "insert [NetWorkDisconnectionLog] (ID, SQLcontext, datetime, IP) values (@ID,@SQLcontext,@datetime,@IP)";
                        SqlParameter[] sqlpars = new SqlParameter[]
                        {
                            new SqlParameter("@ID", DateTime.Now.ToString()),
                            new SqlParameter("@SQLcontext", "Update TT_RFCard Set CardCode='" + this.txtREFCode.Text + "',InitialTime='" + nowTime + "' where CardCode='" + txtCardCode.Text.Trim() + "'"),
                            new SqlParameter("@datetime", DateTime.Now.ToString()),
                            new SqlParameter("@IP", "172.10.14.1")
                        };
                        DbHelperSQL.ExecuteSql(sqlInsert);
                        #endregion
                    }

                    //this.txtCardCode.Text = (Convert.ToInt64(this.txtCardCode.Text) + 1).ToString();
                    this.lblTips.Text = "初始化成功,请刷另一张电子标签";
                    RWini.Beep(2047, 150);//鸣叫

                    string rfcode = txtREFCode.Text;
                    txtREFCode.Clear();
                    txtREFCode.Text = (int.Parse(rfcode) + 1).ToString();
                    txtCardCode.Clear();
                    this.rfCard.CardCode = "";
                    timer_start.Enabled  = true;
                    this.btnSave.Text    = "结束初始化";
                }
            }
            else
            {
                this.lblTips.Text    = "获取到的电子标签起始号已经存在,请联系开发人员!";
                this.rfCard.CardCode = "";
                txtCardCode.Clear();
                return;
            }
        }
        /// <summary>
        /// 时钟进行重复读写,对电子标签进行读取和写入,并存入数据库中
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer_start_Tick(object sender, EventArgs e)
        {
            if (i == 0)//i=0表示电子标签初始化成功!
            {
                string strCardCode = this.rfCard.CardCode;

                //txtCardCode.Text = this.rfCard.CardCode;

                byte iCount = this.rfCard.CardCount;

                this.rfCard.CardCode = "";

                if (iCount == 0)
                {
                    lblTips.Text = "请检查电子标签读写器上是否有卡!";
                    txtCardCode.Clear();
                    return;
                }
                else if (iCount > 1)
                {
                    lblTips.Text = "请检查电子标签读写器上是否只有一张卡!";
                    txtCardCode.Clear();
                    return;
                }
                else if (iCount == 1)//读到了一张电子标签
                {
                    timer_start.Stop();

                    int iExist = Convert.ToInt32(DbHelperSQL.GetSingle("Select Count(0) from TT_RFCard where CardCode='" + this.txtREFCode.Text + "'"));
                    if (iExist == 0)
                    {
                        strCardCode = this.rfCard.CardCode;
                        //int iIsInit = Convert.ToInt32(DbHelperSQL.GetSingle("Select Count(0) from TT_RFCard where CardCode='" + strCardCode + "'"));
                        int iIsInit = Convert.ToInt32(DbHelperSQL.GetSingle("Select Count(0) from TT_RFCard where CardCode='" + txtCardCode.Text.Trim() + "'"));
                        if (iIsInit > 0)
                        {
                            DialogResult result = MessageBox.Show("该卡已经初始化过,是否再初始化一遍", "天大天科卡初始化系统", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                            if (result == DialogResult.No)
                            {
                                this.lblTips.Text = "该电子标签已初始化过";
                                txtCardCode.Clear();
                                return;
                            }
                        }


                        short iSuccess = -1;
                        while (iSuccess != 0)
                        {
                            iSuccess = this.rfCard.RfWrite(txtREFCode.Text.Trim());//写入电子标签信息
                        }
                        if (iSuccess == 0)
                        {
                            if (iIsInit == 0)
                            {
                                DbHelperSQL.ExecuteSql("Insert into TT_RFCard Values('" + this.txtREFCode.Text + "',getdate(),'" + ini.IniReadValue("UserInfo", "UserCode") + "')");
                            }
                            else
                            {
                                DbHelperSQL.ExecuteSql("Update TT_RFCard Set CardCode='" + this.txtREFCode.Text + "' where CardCode='" + txtCardCode.Text.Trim() + "'");
                            }
                            RWini.Beep(2047, 150);
                            this.lblTips.Text = "初始化成功,请刷另一张电子标签";
                            //if (strOperateType == "asc")
                            //    this.txtCardCode.Text = (Convert.ToInt64(this.txtCardCode.Text) + 1).ToString();
                            //else if (strOperateType == "desc")
                            //    this.txtCardCode.Text = (Convert.ToInt64(this.txtCardCode.Text) - 1).ToString();
                            string rfcode = txtREFCode.Text;
                            txtREFCode.Clear();
                            txtREFCode.Text = (int.Parse(rfcode) + 1).ToString();
                            txtCardCode.Clear();
                            this.rfCard.CardCode = "";
                        }
                    }
                    else
                    {
                        this.lblTips.Text = "该卡号已经被使用过,不能继续初始化";

                        txtCardCode.Clear();
                        this.rfCard.CardCode = "";
                    }
                }
                txtCardCode.Clear();
                this.rfCard.CardCode = "";
                timer_start.Start();
            }
        }