public bool Open()
        {
            string msg = string.Empty;

            return(_ReaderMethod.DevOpen(out msg));
        }
Ejemplo n.º 2
0
        public override bool LoadData(out string msg)
        {
            bool result = true;

            if (_ReaderMethod == null || _Ipassword == null)
            {
                msg = "读卡器驱动或密码存储未初始化";
                return(false);
            }

            if (_ReaderMethod.DevOpen(out msg))
            {
                if (_ReaderMethod.OpenCard(out msg))
                {
                    this.Section0.Block0.FID = _ReaderMethod.CardId;
                    //初始化扇区存储密码
                    string pass = _Ipassword.GetPasswords(this.Section0.Block0.FID, 0);
                    this.Section0.LoadDBPassword(pass);
                    if (this.Section0.Block3.DBPasswordA == "FFFFFFFFFFFF" && this.Section0.Block3.DBPasswordB == "FFFFFFFFFFFF")
                    {
                        Haspublished = false;
                    }
                    else
                    {
                        Haspublished = true;
                    }
                    pass = _Ipassword.GetPasswords(this.Section0.Block0.FID, 1);
                    this.Section1.LoadDBPassword(pass);
                    pass = _Ipassword.GetPasswords(this.Section0.Block0.FID, 2);
                    this.Section2.LoadDBPassword(pass);
                    //初始化卡片信息
                    //扇区0
                    //string keystr = string.Format("{0}{1}{2}", this.Section0.Block3.DBPasswordA,defaultcontrolstr, this.Section0.Block3.DBPasswordB);
                    //if (Haspublished)
                    //{
                    //    keystr = string.Format("{0}{1}{2}", this.Section0.Block3.DBPasswordA, publishcontrolstr, this.Section0.Block3.DBPasswordB);
                    //}
                    string keystr = this.Section0.Block3.DBPasswordA;
                    //keystr = "027E388D27AA";
                    string data = _ReaderMethod.GetSectionData(0, keystr, this.Section0.Block3.DBPasswordB, out msg);
                    if (!string.IsNullOrEmpty(data))
                    {
                        this.Section0.LoadData(data);
                    }
                    else
                    {
                        return(false);
                    }

                    //扇区1
                    keystr = this.Section1.Block3.DBPasswordA;
                    //keystr = "EDCCC1331884";
                    data = _ReaderMethod.GetSectionData(1, keystr, this.Section1.Block3.DBPasswordB, out msg);
                    if (!string.IsNullOrEmpty(data))
                    {
                        this.Section1.LoadData(data);
                        //验证数据CRC
                        if (Haspublished)
                        {
                            if (!this.Section1.IsValid())
                            {
                                msg = "扇区1数据验证失败!";
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }

                    //扇区2
                    keystr = this.Section2.Block3.DBPasswordA;
                    //keystr = "BE35252096AB";
                    data = _ReaderMethod.GetSectionData(2, keystr, this.Section2.Block3.DBPasswordB, out msg);
                    if (!string.IsNullOrEmpty(data))
                    {
                        this.Section2.LoadData(data);
                        //验证数据CRC
                        if (Haspublished)
                        {
                            if (!this.Section2.IsValid())
                            {
                                msg = "扇区2数据验证失败!";
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }


                    this.HasInit = true;
                    // _ReaderMethod.Halt(out msg);
                }
                else
                {
                    result = false;
                }
            }
            else
            {
                result = false;
            }

            return(result);
        }