In the past, the information in the ID card number was great. For the 18-digit ID card, the first six represent the location of your household registration, and the seventh to 14th represent the date of birth, from 15th to 17th represents your gender (even numbers are female and odd numbers are male). According to this information, after I enter an employee's ID card in the system, the control focus is transferred and the birthday and gender are obtained based on the ID card number. The code written in C # is as follows:
/// <Summary>
/// Define the validity of the ID card number in the validated event of the Control Verification textbox_identitycard and get the birthday and gender according to the ID card number
/// </Summary>
Private void textbox_identitycard_validated (Object sender, eventargs E)
{
Try
{
String identitycard = textbox_identitycard.text.trim (); // obtain the entered ID number.
If (string. isnullorempty (identitycard ))
{
MessageBox. Show ("ID card number cannot be blank! "); // ID card number cannot be blank. If it is blank, return
If (textbox_identitycard.canfocus)
{
Textbox_identitycard.focus (); // sets the current input focus to textbox_identitycard
}
Return;
}
Else
{
If (identitycard. length! = 15 & identitycard. length! = 18) // the ID card number can only be 15 or 18 other illegal characters
{
MessageBox. Show ("the ID card number is 15 or 18 characters. Please check it! ");
If (textbox_identitycard.canfocus)
{
Textbox_identitycard.focus ();
}
Return;
}
}
String Birthday = "";
String sex = "";
If (identitycard. Length = 18) // process the 18-digit ID card number to get the birthday and gender code from the number
{
Birthday = identitycard. substring (6, 4) + "-" + identitycard. substring (10, 2) + "-" + identitycard. substring (12, 2 );
Sex = identitycard. substring (14, 3 );
}
If (identitycard. Length = 15)
{
Birthday = "19" + identitycard. substring (6, 2) + "-" + identitycard. substring (8, 2) + "-" + identitycard. substring (10, 2 );
Sex = identitycard. substring (12, 3 );
}
Textbox_birthday.text = birthday;
If (Int. parse (sex) % 2 = 0) // The gender code is an even number and the female odd number is male.
{
This. combobox_sex.text = "";
}
Else
{
This. combobox_sex.text = "male ";
}
}
Catch (exception ex)
{
MessageBox. Show ("Incorrect ID card number entered ");
If (textbox_identitycard.canfocus)
{
Textbox_identitycard.focus ();
}
Return;
}
}