コード例 #1
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            DocumentBase.CountryCode nationality;
            Enum.TryParse <DocumentBase.CountryCode>(cmbNationality.SelectedValue.ToString(), out nationality);

            DocumentBase.CountryCode issuer;
            Enum.TryParse <DocumentBase.CountryCode>(cmbIssuer.SelectedValue.ToString(), out issuer);

            DocumentBase.SexCode sex;
            Enum.TryParse <DocumentBase.SexCode>(cmbSex.SelectedValue.ToString(), out sex);

            PassportModel tmp = new PassportModel(
                nationality,
                charRemap(txtSurname.Text.Replace(' ', '<')),
                charRemap(txtGivenName.Text.Replace(' ', '<')),
                txtPassportNumber.Text,
                dtpBirth.Value.ToString("yyMMdd"),
                dtpExpire.Value.ToString("yyMMdd"),
                charRemap(txtPersonalNumber.Text.Replace(' ', '<')),
                "ValueNotUsed",
                issuer,
                sex,
                txtType.Text
                );

            rtbMRZ.Text = MrzGeneration.GeneratePassportMRZ(tmp);
        }
コード例 #2
0
        public static string GeneratePassportMRZ(PassportModel passport)
        {
            passport.PersonalNum = passport.PersonalNum.Replace(' ', '<').PadRight(14, '<');

            Dictionary <string, string> result = new Dictionary <string, string>();

            result.Add("passport", mrzCheckDigitConvert(passport.PassportNum).ToString());
            result.Add("dob", mrzCheckDigitConvert(passport.Dob).ToString());
            result.Add("expDate", mrzCheckDigitConvert(passport.ExpDate).ToString());
            result.Add("personalNum", mrzCheckDigitConvert(passport.PersonalNum).ToString());
            string final = passport.PassportNum + result["passport"].ToString() + passport.Dob + result["dob"].ToString() + passport.ExpDate + result["expDate"].ToString() + passport.PersonalNum + result["personalNum"].ToString();

            result.Add("final", mrzCheckDigitConvert(final).ToString());

            string MRZ1;
            string name = passport.SurName.ToUpper() + "<<" + passport.GivenNames.Replace(' ', '<').Replace('-', '<').ToUpper();

            if (name.Length > 39)
            {
                name = name.Substring(0, 39);
            }
            MRZ1  = passport.DocType.PadRight(2, '<').ToUpper() + passport.CountryOfIssue;
            MRZ1 += name;
            MRZ1  = MRZ1.PadRight(44, '<');

            string total = passport.PassportNum + result["passport"].ToString() + passport.Nationality.ToString() + passport.Dob + result["dob"].ToString() +
                           Convert.ToChar(Convert.ChangeType(passport.Sex, passport.Sex.GetTypeCode()))
                           + passport.ExpDate + result["expDate"].ToString() + passport.PersonalNum + result["personalNum"] + result["final"].ToString();

            //total.Dump("Total");
            result.Add("mrz", total);

            return(MRZ1 + Environment.NewLine + total);
        }