private void TxtNumberSub_Validating(object sender, CancelEventArgs e) { if (!string.IsNullOrEmpty(txtSubPackage.Text)) { if (string.IsNullOrEmpty(txtNumberSub.Text)) { e.Cancel = true; errorProvider.SetError(txtNumberSub, "Please input number of sub package"); } else if (!ProDAO.checkInt(txtNumberSub.Text) || int.Parse(txtNumberSub.Text) <= 0) { e.Cancel = true; errorProvider.SetError(txtNumberSub, "Number sub package must be number and greater than 0"); } else { e.Cancel = false; errorProvider.SetError(txtNumberSub, null); } } else { e.Cancel = false; errorProvider.SetError(txtNumberSub, null); } }
//validate public bool validate() { bool valid = true; if (string.IsNullOrEmpty(txtNumberPackage.Text)) { errorProvider.SetError(txtNumberPackage, "Please input number of one package"); valid = false; } else if (!ProDAO.checkInt(txtNumberPackage.Text) || int.Parse(txtNumberPackage.Text) < 0) { errorProvider.SetError(txtNumberPackage, "Number package must be possible number"); valid = false; } else if (!string.IsNullOrEmpty(lbSub.Text)) { errorProvider.SetError(txtNumberPackage, null); if (string.IsNullOrEmpty(txtNumberSub.Text)) { valid = false; errorProvider.SetError(txtNumberSub, "Please input number of sub package"); } else if (!ProDAO.checkInt(txtNumberSub.Text) || int.Parse(txtNumberSub.Text) < 0) { valid = false; errorProvider.SetError(txtNumberSub, "Number sub package must be number and greater than 0"); } else { valid = true; errorProvider.SetError(txtNumberSub, null); } } else { valid = true; errorProvider.SetError(txtNumberPackage, null); errorProvider.SetError(txtNumberSub, null); } return(valid); }