示例#1
0
        private void btnLoadKey_Click(object sender, EventArgs e)
        {
            if (!db.CheckOprtRole(formCode, "M", true))
            {
                return;
            }
            DialogResult ret        = Pub.MessageBoxQuestion(Pub.GetResText(formCode, "Msg001", ""));
            string       SectorData = "";

            switch (ret)
            {
            case DialogResult.Yes:
                int rtn = DeviceObject.objCPIC.ReadCardKeySectorData(ref SectorData);
                if ((rtn != 0) || (SectorData == ""))
                {
                    Pub.ShowErrorMsg(Pub.GetCardMsg(rtn));
                    return;
                }
                break;

            case DialogResult.No:
                dlgOpen.Filter = Pub.GetResText(formCode, "FilterKey", "") + "(*.key)|*.key";
                if (dlgOpen.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                StreamReader sr = new StreamReader(dlgOpen.FileName, Encoding.Default);
                SectorData = sr.ReadLine();
                sr.Close();
                sr.Dispose();
                if (SectorData.Length != 96)
                {
                    FileStream fs  = new FileStream(dlgOpen.FileName, FileMode.Open);
                    byte[]     buf = new byte[fs.Length];
                    fs.Read(buf, 0, (int)fs.Length);
                    fs.Close();
                    fs.Dispose();
                    SectorData = "";
                    for (int i = 0; i < buf.Length; i++)
                    {
                        SectorData += Pub.ByteToHex(buf[i]);
                    }
                }
                break;

            default:
                break;
            }
            string key  = "";
            string code = "";

            if (!DeviceObject.objCPIC.ReadCardKey(SectorData, ref key, ref code))
            {
                Pub.ShowErrorMsg(Pub.GetResText(formCode, "Msg003", ""));
                return;
            }
            if (!db.WriteConfig("RS_System", "DealersCode", code, this.Text, CurrentOprt))
            {
                return;
            }
            SystemInfo.DealersCode = code;
            if (!db.WriteConfig("RS_System", "CardKey", key, this.Text, CurrentOprt))
            {
                return;
            }
            SystemInfo.CardKey = DeviceObject.objCPIC.GetCardKey(key, "yyc120114");
            Pub.InitCardInfo();
            Pub.MessageBoxShow(Pub.GetResText(formCode, "Msg002", ""), MessageBoxIcon.Information);
        }