private void txtCardNo_TextChanged(object sender, EventArgs e) { if (cmbCardType.Text == "身份证") { string idno = txtCardNo.Text.Trim(); idno = EagleString.egString.Full2Half(idno); if (idno.Length == 18) { try { BirthAndGender bg = Common.GetBirthAndSex(idno); if (bg.Gender == Gender.Female) { rbFemale.Checked = true; } else { rbMale.Checked = true; } dtpBirth.Value = bg.Birth; } catch { } } } }
public static BirthAndGender GetBirthAndSex(string identityCard) { string birthday = ""; string genderStr = ""; Gender gender; if (identityCard.Length == 18)//处理18位的身份证号码从号码中得到生日和性别代码 { birthday = identityCard.Substring(6, 4) + "-" + identityCard.Substring(10, 2) + "-" + identityCard.Substring(12, 2); genderStr = identityCard.Substring(14, 3); } else if (identityCard.Length == 15) { birthday = "19" + identityCard.Substring(6, 2) + "-" + identityCard.Substring(8, 2) + "-" + identityCard.Substring(10, 2); genderStr = identityCard.Substring(12, 3); } else { throw new Exception("身份证位数不正确!"); } if (int.Parse(genderStr) % 2 == 0)//性别代码为偶数是女性奇数为男性 { gender = Gender.Female; } else { gender = Gender.Male; } BirthAndGender birthAndGender = new BirthAndGender { Birth = DateTime.Parse(birthday), Gender = gender }; return(birthAndGender); }
private void btnPrint_Click(object sender, EventArgs e) { if (cmbInsuranceType.SelectedIndex == -1) { MessageBox.Show("没有可选的保险类型,请尝试重新登录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string mobile = EagleString.egString.Full2Half(txtCustomerPhone.Text.Trim()); txtCustomerPhone.Text = mobile; if (!string.IsNullOrEmpty(mobile)) { if (!Regex.IsMatch(mobile, "^1[358][0-9]{9}$")) { MessageBox.Show("请正确输入手机号,以提供短信通知服务!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } string cardNo = EagleString.egString.Full2Half(txtCardNo.Text.Trim()); txtCardNo.Text = cardNo; if (cardNo.Length < 4)//军官证最少有4位数的 { MessageBox.Show("请正确输入证件号码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { if (cmbCardType.Text == "身份证") { try { BirthAndGender bg = Common.GetBirthAndSex(cardNo); } catch { MessageBox.Show("身份证号码有误,请检查!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } decimal years = DateTime.Today.Subtract(dtpBirth.Value.Date).Days / 365m; double days = DateTime.Today.Subtract(dtpBirth.Value.Date).TotalDays; if (years > 90 || years < 0 || days < 28) { MessageBox.Show("出生日期有误,请检查!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DateTime dtFlight = dtpFlightDate.Value; if (dtFlight < DateTime.Today) { MessageBox.Show("请正确填写乘机日期!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string flightNo = EagleString.egString.Full2Half(txtFlightNo.Text.Trim()); txtFlightNo.Text = flightNo; dtpFlightDate_ValueChanged(null, null);//生效时间再次同步 if (MessageBox.Show("即将连接打印机,是否确认?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { pbPrint.Visible = true; btnPrint.Enabled = false; txtDate.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(GetIt)); th.Start(); } }