Пример #1
0
    private void getBasicData(ref ResultObj resobj)
    {
        Dictionary <string, string> dictionary = new Dictionary <string, string>();

        if (!openCom())
        {
            resobj.IsSuccess = false;
            resobj.ErrorType = ErrorType.非預期錯誤;
            resobj.ErrorMsg  = "開啟讀卡機通訊埠,失敗!請檢查讀卡機連線。";
            return;
        }
        int iBufferLen = 72;

        byte[] array = new byte[iBufferLen];
        int    num   = hisGetBasicData(array, ref iBufferLen);

        closeCom();
        if (num != 0)
        {
            resobj.IsSuccess = false;
            resobj.ErrorMsg  = ErrCode.errMsg(num);
            return;
        }
        dictionary.Add("卡片號碼", BIG5.GetString(array, 0, 12).Trim());
        dictionary.Add("姓名", BIG5.GetString(array, 12, 20).Trim());
        dictionary.Add("身分證號", BIG5.GetString(array, 32, 10).Trim());
        dictionary.Add("出生日期", BIG5.GetString(array, 42, 7).Trim());
        dictionary.Add("性別", BIG5.GetString(array, 49, 1).Trim());
        dictionary.Add("發卡日期", BIG5.GetString(array, 50, 7).Trim());
        dictionary.Add("卡片註銷註記", BIG5.GetString(array, 57, 1).Trim());
        dictionary.Add("緊急聯絡電話", BIG5.GetString(array, 58, 14).Trim());
        resobj.IsSuccess = true;
        resobj.CardInfo  = dictionary;
    }
Пример #2
0
    private void getInoculateData(ref ResultObj resobj)
    {
        Dictionary <string, string> dictionary = new Dictionary <string, string>();
        StringBuilder stringBuilder            = new StringBuilder();

        if (!openCom())
        {
            resobj.IsSuccess = false;
            resobj.ErrorMsg  = "開啟讀卡機通訊埠,失敗!請檢查讀卡機連線。";
            return;
        }
        int iBufferLen = 1400;

        byte[] array = new byte[iBufferLen];
        int    num   = hisGetInoculateData(array, ref iBufferLen);

        closeCom();
        if (num == 0)
        {
            int num2 = 0;
            for (int i = 0; i < 40; i++)
            {
                if (BIG5.GetString(array, i * 35, 6).Trim() == "")
                {
                    dictionary.Add("資料筆數", num2.ToString());
                    break;
                }
                num2++;
                dictionary.Add(num2 + ".疫苗種類", BIG5.GetString(array, i * 35, 6).Trim());
                dictionary.Add(num2 + ".接種日期", BIG5.GetString(array, i * 35 + 6, 7).Trim());
                dictionary.Add(num2 + ".醫療院所代碼", BIG5.GetString(array, i * 35 + 13, 10).Trim());
                dictionary.Add(num2 + ".疫苗批號", BIG5.GetString(array, i * 35 + 23, 12).Trim());
            }
            resobj.IsSuccess = true;
        }
        else
        {
            resobj.IsSuccess = false;
            resobj.ErrorMsg  = ErrCode.errMsg(num);
        }
    }
Пример #3
0
    private void writeInoculateData(ref ResultObj resobj, string VaccineType, string BatchNo)
    {
        byte[] array  = new byte[11];
        byte[] array2 = new byte[8];
        byte[] bytes  = BIG5.GetBytes(VaccineType + "\0");
        byte[] bytes2 = BIG5.GetBytes(BatchNo + "\0");
        if (!openCom())
        {
            resobj.IsSuccess = false;
            resobj.ErrorMsg  = "開啟讀卡機通訊埠,失敗!請檢查讀卡機連線。";
            return;
        }
        int iBufferLen = 72;

        byte[] array3 = new byte[iBufferLen];
        int    num    = hisGetBasicData(array3, ref iBufferLen);

        Array.Copy(array3, 32, array, 0, 10);
        array[10] = 0;
        Array.Copy(array2, 42, array, 0, 7);
        array2[7] = 0;
        num       = csVerifySAMDC();
        if (num != 0)
        {
            resobj.IsSuccess = false;
            resobj.ErrorMsg  = "讀卡機認證失敗,錯誤訊息:" + ErrCode.errMsg(num);
            return;
        }
        int num2 = hisWriteInoculateData(array, array2, bytes, bytes2);

        closeCom();
        if (num2 == 0)
        {
            resobj.IsSuccess = true;
            return;
        }
        resobj.IsSuccess = false;
        resobj.ErrorMsg  = ErrCode.errMsg(num2);
    }
Пример #4
0
    private void SetErrorMsg(ref ResultObj resobj, uint tmpCode)
    {
        switch (tmpCode)
        {
        case 0u:
            resobj.ErrorType = ErrorType.正常;
            break;

        case 2148532266u:
        case 2148532331u:
            resobj.ErrorType = ErrorType.PIN碼錯誤;
            break;

        case 2148532270u:
            resobj.ErrorType = ErrorType.未接上讀卡機;
            break;

        case 2148532236u:
        case 2148532329u:
            resobj.ErrorType = ErrorType.未插入卡片;
            break;

        case 2148532326u:
            resobj.ErrorType = ErrorType.非指定的卡片類型;
            break;

        case 2148532268u:
        case 2148532269u:
            resobj.ErrorType = ErrorType.憑證錯誤;
            break;

        default:
            resobj.ErrorType = ErrorType.非預期錯誤;
            resobj.ErrorMsg  = ErrCode.errMsg(tmpCode);
            break;
        }
    }
Пример #5
0
    public ResultObj Execute(Dictionary <string, string> args)
    {
        ResultObj resobj = new ResultObj();

        resobj.IsSuccess  = false;
        resobj.CertStatus = CertStatus.未驗證;
        Dictionary <string, string> dictionary = new Dictionary <string, string>();
        int    phContext      = 0;
        int    phCard         = 0;
        int    ActiveProtocol = 0;
        string empty          = string.Empty;

        byte[] array = new byte[21]
        {
            0,
            164,
            4,
            0,
            16,
            209,
            88,
            0,
            0,
            1,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            17,
            0
        };
        byte[] array2 = new byte[7]
        {
            0,
            202,
            17,
            0,
            2,
            0,
            0
        };
        byte[] array3        = new byte[2];
        int    pcbRecvLength = 2;

        byte[] array4         = new byte[59];
        int    pcbRecvLength2 = 59;
        uint   num            = 0u;

        num = SCardEstablishContext(0u, 0, 0, ref phContext);
        if (num != 0)
        {
            resobj.ErrorMsg = ErrCode.errMsg(num);
        }
        else
        {
            int           num2        = 0;
            byte[]        array5      = new byte[num2];
            List <string> list        = new List <string>();
            int           pcchReaders = 0;
            num = SCardListReaders(phContext, null, null, ref pcchReaders);
            if (num == 0)
            {
                byte[] array6 = new byte[pcchReaders];
                num = SCardListReaders(phContext, null, array6, ref pcchReaders);
                if (num == 0)
                {
                    ASCIIEncoding aSCIIEncoding = new ASCIIEncoding();
                    string        text          = aSCIIEncoding.GetString(array6);
                    int           num3          = 0;
                    char          c             = '\0';
                    int           num4          = pcchReaders;
                    while (text[0] != c)
                    {
                        num3 = text.IndexOf(c);
                        string text2 = text.Substring(0, num3);
                        list.Add(text2);
                        num4 -= text2.Length + 1;
                        text  = text.Substring(num3 + 1, num4);
                    }
                }
            }
            if (num != 0)
            {
                SetErrorMsg(ref resobj, num);
            }
            else if (list.Count == 0)
            {
                SetErrorMsg(ref resobj, 2148532270u);
            }
            else
            {
                uint num5 = 0u;
                foreach (string item in list)
                {
                    num = SCardConnect(phContext, item, 1u, 2u, ref phCard, ref ActiveProtocol);
                    if (num != 0)
                    {
                        num5 = num;
                    }
                    else
                    {
                        SCARD_IO_REQUEST pioSendPci = default(SCARD_IO_REQUEST);
                        SCARD_IO_REQUEST pioRecvPci = default(SCARD_IO_REQUEST);
                        pioSendPci.dwProtocol  = (pioRecvPci.dwProtocol = ActiveProtocol);
                        pioSendPci.cbPciLength = (pioRecvPci.cbPciLength = 8);
                        num = SCardTransmit(phCard, ref pioSendPci, array, array.Length, ref pioRecvPci, ref array3[0], ref pcbRecvLength);
                        if (num == 0)
                        {
                            num = SCardTransmit(phCard, ref pioSendPci, array2, array2.Length, ref pioRecvPci, ref array4[0], ref pcbRecvLength2);
                            if (num != 0)
                            {
                                SetErrorMsg(ref resobj, num);
                            }
                            else
                            {
                                try
                                {
                                    string text3  = Encoding.Default.GetString(array4, 0, 12).Replace("\0", "");
                                    double result = 0.0;
                                    double.TryParse(text3, out result);
                                    if (text3.Length != 12 || result == 0.0)
                                    {
                                        throw new Exception();
                                    }
                                    dictionary.Add("健保卡ID", text3);
                                    dictionary.Add("姓名", Encoding.Default.GetString(array4, 12, 20).Replace("\0", ""));
                                    dictionary.Add("身分證字號", Encoding.Default.GetString(array4, 32, 10));
                                    dictionary.Add("生日", Encoding.Default.GetString(array4, 43, 2) + "/" + Encoding.Default.GetString(array4, 45, 2) + "/" + Encoding.Default.GetString(array4, 47, 2));
                                    dictionary.Add("姓別", Encoding.Default.GetString(array4, 49, 1));
                                    dictionary.Add("發卡日期", Encoding.Default.GetString(array4, 51, 2) + "/" + Encoding.Default.GetString(array4, 53, 2) + "/" + Encoding.Default.GetString(array4, 55, 2));
                                    resobj.IsSuccess = true;
                                    resobj.CardInfo  = dictionary;
                                }
                                catch
                                {
                                    resobj.IsSuccess = false;
                                    SetErrorMsg(ref resobj, 2148532326u);
                                }
                            }
                            SCardDisconnect(phCard, 0);
                            break;
                        }
                        SetErrorMsg(ref resobj, num);
                    }
                }
                if (!resobj.IsSuccess && num5 != 0)
                {
                    SetErrorMsg(ref resobj, num5);
                }
            }
            SCardReleaseContext(phContext);
        }
        if (!resobj.IsSuccess && resobj.ErrorMsg.Equals(""))
        {
            resobj.ErrorType = ErrorType.非預期錯誤;
            resobj.ErrorMsg  = "非預期錯誤,無法讀取健保卡";
        }
        return(resobj);
    }
Пример #6
0
        private void btn_ReadCard_Click(object sender, EventArgs e)
        {
            int    phContext      = 0;
            int    phCard         = 0;
            int    ActiveProtocol = 0;
            string empty          = string.Empty;

            byte[] array = new byte[21]
            {
                0,
                164,
                4,
                0,
                16,
                209,
                88,
                0,
                0,
                1,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                17,
                0
            };
            byte[] array2 = new byte[7]
            {
                0,
                202,
                17,
                0,
                2,
                0,
                0
            };
            byte[] array3        = new byte[2];
            int    pcbRecvLength = 2;

            byte[] array4         = new byte[59];
            int    pcbRecvLength2 = 59;
            uint   num            = 0u;

            num = SCardEstablishContext(0u, 0, 0, ref phContext);
            if (num != 0)
            {
                MessageBox.Show(ErrCode.errMsg(num), "讀卡失敗", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            int num2 = 0;

            byte[]        array5      = new byte[num2];
            List <string> list        = new List <string>();
            int           pcchReaders = 0;

            num = SCardListReaders(phContext, null, null, ref pcchReaders);
            if (num == 0)
            {
                byte[] array6 = new byte[pcchReaders];
                num = SCardListReaders(phContext, null, array6, ref pcchReaders);
                if (num == 0)
                {
                    ASCIIEncoding aSCIIEncoding = new ASCIIEncoding();
                    string        text          = aSCIIEncoding.GetString(array6);
                    int           num3          = 0;
                    char          c             = '\0';
                    int           num4          = pcchReaders;
                    while (text[0] != c)
                    {
                        num3 = text.IndexOf(c);
                        string text2 = text.Substring(0, num3);
                        list.Add(text2);
                        num4 -= text2.Length + 1;
                        text  = text.Substring(num3 + 1, num4);
                    }
                }
            }
            if (num != 0)
            {
                MessageBox.Show("請確認卡片類別,並重新插卡", "讀卡失敗", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else if (list.Count == 0)
            {
                MessageBox.Show("請接上讀卡機裝置", "讀卡失敗", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                uint num5 = 0u;
                foreach (string item in list)
                {
                    num = SCardConnect(phContext, item, 1u, 2u, ref phCard, ref ActiveProtocol);
                    if (num != 0)
                    {
                        num5 = num;
                    }
                    else
                    {
                        SCARD_IO_REQUEST pioSendPci = default(SCARD_IO_REQUEST);
                        SCARD_IO_REQUEST pioRecvPci = default(SCARD_IO_REQUEST);
                        pioSendPci.dwProtocol  = (pioRecvPci.dwProtocol = ActiveProtocol);
                        pioSendPci.cbPciLength = (pioRecvPci.cbPciLength = 8);
                        num = SCardTransmit(phCard, ref pioSendPci, array, array.Length, ref pioRecvPci, ref array3[0], ref pcbRecvLength);
                        if (num == 0)
                        {
                            num = SCardTransmit(phCard, ref pioSendPci, array2, array2.Length, ref pioRecvPci, ref array4[0], ref pcbRecvLength2);
                            if (num != 0)
                            {
                                MessageBox.Show(ErrCode.errMsg(num), "讀卡失敗", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            }
                            else
                            {
                                try
                                {
                                    if (dt.Select("Modified = 1").Length != 0)
                                    {
                                        if (MessageBox.Show("本個案接種資料未完成儲存,是否放棄儲存繼續讀取下一位個案?", "紀錄尚未儲存", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.No)
                                        {
                                            return;
                                        }
                                        InitDataTable();
                                    }
                                    string text3  = Encoding.Default.GetString(array4, 0, 12).Replace("\0", "");
                                    double result = 0.0;
                                    double.TryParse(text3, out result);
                                    if (text3.Length != 12 || result == 0.0)
                                    {
                                        throw new Exception();
                                    }
                                    tb_CaseName.Text     = Encoding.Default.GetString(array4, 12, 20).Replace("\0", "");
                                    tb_RocID.Text        = Encoding.Default.GetString(array4, 32, 10);
                                    tb_Birthday.Text     = Convert.ToInt32(Encoding.Default.GetString(array4, 42, 3)) + 1911 + "/" + Encoding.Default.GetString(array4, 45, 2) + "/" + Encoding.Default.GetString(array4, 47, 2);
                                    tb_Birthday2.Text    = tb_Birthday.Text;
                                    cb_Sex.SelectedIndex = ((!tb_RocID.Text.Substring(1, 1).Equals("1")) ? 1 : 0);
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show("請確認卡片類別,並重新插卡", "讀卡失敗", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                                    string str = "C:\\NIISOL\\";
                                    Utility.WriteToFile(str + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "_log.txt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\t請確認卡片類別,並重新插卡,讀卡失敗" + ex.Message, 'A', "");
                                }
                            }
                            SCardDisconnect(phCard, 0);
                            break;
                        }
                        MessageBox.Show(ErrCode.errMsg(num), "讀卡失敗", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                }
                if (num5 != 0)
                {
                    MessageBox.Show(ErrCode.errMsg(num), "讀卡失敗", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
            }
            SCardReleaseContext(phContext);
        }
Пример #7
0
    private bool ValidCard(ref ResultObj resobj)
    {
        int num = 0;

        byte[] array = new byte[21];
        if (HCA_GNFuncCall(10102, null, ref array[0], 0, 21, 0, 0, 0) != 0)
        {
            resobj.CertStatus = CertStatus.驗證不通過;
            resobj.ErrorType  = ErrorType.憑證錯誤;
            resobj.ErrorMsg   = "取卡片序號失敗";
            return(false);
        }
        int num2 = Convert.ToInt32(Encoding.ASCII.GetString(array, 7, 7));
        int num3 = Convert.ToInt32(Encoding.ASCII.GetString(array, 14, 7));
        int num4 = (DateTime.Now.Year - 1911) * 10000 + DateTime.Now.Month * 100 + DateTime.Now.Day;

        if (num2 > num4 || num4 > num3)
        {
            resobj.CertStatus = CertStatus.驗證不通過;
            resobj.ErrorType  = ErrorType.憑證錯誤;
            resobj.ErrorMsg   = "卡片不在有效日期區間";
            return(false);
        }
        byte[] array2 = new byte[4096];
        int    num5   = 4096;

        num = HCA_GNFuncCall(10201, null, ref array2[0], 0, 4096, 0, 0, 0);
        if (num != 0)
        {
            resobj.CertStatus = CertStatus.驗證不通過;
            resobj.ErrorType  = ErrorType.憑證錯誤;
            resobj.ErrorMsg   = "取CA憑證失敗 (" + ErrCode.errMsg(num) + ")";
            return(false);
        }
        int num6 = array2[1] & 0xF;

        num5 = 0;
        for (int i = 0; i < num6; i++)
        {
            num5 = ((num5 << 8) | (array2[2 + i] & 0xFF));
        }
        num5 += 2 + num6;
        byte[] array3 = new byte[2048];
        int    num7   = 2048;

        num = HCA_GNFuncCall(10201, null, ref array3[0], 1, 2048, 0, 0, 0);
        if (num != 0)
        {
            resobj.CertStatus = CertStatus.驗證不通過;
            resobj.ErrorType  = ErrorType.憑證錯誤;
            resobj.ErrorMsg   = "取簽章憑證失敗 (" + ErrCode.errMsg(num) + ")";
            return(false);
        }
        num6 = (array3[1] & 0xF);
        num7 = 0;
        for (int i = 0; i < num6; i++)
        {
            num7 = ((num7 << 8) | (array3[2 + i] & 0xFF));
        }
        num7 += 2 + num6;
        num   = HCA_GNFuncCall(10214, array3, ref array2[0], num7, num5, 0, 0, 0);
        if (num != 0)
        {
            resobj.CertStatus = CertStatus.驗證不通過;
            resobj.ErrorType  = ErrorType.憑證錯誤;
            resobj.ErrorMsg   = "驗章失敗 (" + ErrCode.errMsg(num) + ")";
            return(false);
        }
        byte[] array4 = new byte[1024];
        num = HCA_GNFuncCall(10212, array3, ref array4[0], num7, 1024, 1, 1, 0);
        if (num != 0)
        {
            resobj.CertStatus = CertStatus.驗證不通過;
            resobj.ErrorType  = ErrorType.憑證錯誤;
            resobj.ErrorMsg   = "取不到憑證序號 (" + ErrCode.errMsg(num) + ")";
            return(false);
        }
        string @string          = Encoding.GetEncoding("BIG5").GetString(array4);
        string requestUriString = "https://www.hyacrd.com.tw/Verify.aspx?crl=HCA&serial=" + @string;
        string text             = "";

        try
        {
            HttpWebRequest  httpWebRequest  = (HttpWebRequest)WebRequest.Create(requestUriString);
            HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            Stream          responseStream  = httpWebResponse.GetResponseStream();
            StreamReader    streamReader    = new StreamReader(responseStream, Encoding.GetEncoding("UTF-8"));
            text = streamReader.ReadToEnd();
            streamReader.Close();
            responseStream.Close();
            if (text == "OK")
            {
                resobj.CertStatus = CertStatus.驗證通過;
                return(true);
            }
            resobj.CertStatus = CertStatus.驗證不通過;
            resobj.ErrorMsg   = "憑證狀態失敗";
            resobj.ErrorType  = ErrorType.憑證錯誤;
            return(false);
        }
        catch
        {
            resobj.CertStatus = CertStatus.未驗證;
            resobj.ErrorType  = ErrorType.憑證錯誤;
            return(false);
        }
    }