private void Controls_RequestValidationEvent(object sender, EventArgs e) { IControlValidation objControl = (IControlValidation)sender; switch (((Control)sender).Name) { case "TxtPassword": case "TxtConfirm": objControl.IsValid = true; objControl.IsValidated = true; if (objControl.IsEmpty) { objControl.IsValid = false; objControl.ValidationErrorMsg = "密码不能为空!"; } else { if (objControl.CurrentText.Length < 4 || objControl.CurrentText.Length > 18) { objControl.IsValid = false; objControl.ValidationErrorMsg = "密码长度必须在(4-18)之间!"; } } if (objControl.IsValidated && objControl.IsValid) { if (TxtPassword.Text != TxtConfirm.Text) { objControl.IsValid = false; objControl.ValidationErrorMsg = "两次密码输入不一致!"; if (objControl == TxtPassword && string.IsNullOrEmpty(TxtConfirm.Text)) { objControl.IsValid = true; } } else { TxtPassword.IsValid = true; TxtConfirm.IsValid = true; } } break; } if (!objControl.IsValid && objControl.IsValidated) { ((Control)objControl).Focus(); } }
private void Controls_RequestValidationEvent(object sender, EventArgs e) { IControlValidation objControl = (IControlValidation)sender; objControl.IsValid = true; objControl.IsValidated = true; switch (((Control)sender).Name) { case "TxtAgentCode": if (objControl.IsEmpty) { objControl.IsValid = false; objControl.ValidationErrorMsg = "上级代理商编号不能为空!"; } else { ParamUtil aPU = new ParamUtil().SQLCmdLoadData().SQLWithOutSchema() .SQLEntityScript("BASE_CATEGORY", string.Format("SELECT CATEGORYID FROM BASE_CATEGORY WHERE CATEGORYID='{0}'", objControl.CurrentText)) .ExecuteCmd(ADataLoader.DataLoader()); if (!aPU.IsOK()) { objControl.IsValid = false; objControl.ValidationErrorMsg = aPU.GetError(); } else { if (aPU.GetValueAsDataSet().Tables["BASE_CATEGORY"].Rows.Count == 0) { objControl.IsValid = false; objControl.ValidationErrorMsg = string.Format("代理商编号[{0}]无效!", objControl.CurrentText); } } } break; case "TxtAccountID": if (objControl.IsEmpty) { objControl.IsValid = false; objControl.ValidationErrorMsg = "账户名不能为空!"; } else { if (objControl.CurrentText.Length < 4 || objControl.CurrentText.Length > 18) { objControl.IsValid = false; objControl.ValidationErrorMsg = "账户名长度必须在(4-18)之间!"; } else { // 是否存在? if (MemberDBUtils.MemberIsExist(GetControl(), TxtAccountID.Text)) { objControl.IsValid = false; objControl.ValidationErrorMsg = string.Format("账号[{0}]已经存在!", TxtAccountID.Text); } } } break; case "TxtPassword": case "TxtConfirm": if (objControl.IsEmpty) { objControl.IsValid = false; objControl.ValidationErrorMsg = "密码不能为空!"; } else { if (objControl.CurrentText.Length < 4 || objControl.CurrentText.Length > 18) { objControl.IsValid = false; objControl.ValidationErrorMsg = "密码长度必须在(4-18)之间!"; } } if (objControl.IsValidated && objControl.IsValid) { if (TxtPassword.Text != TxtConfirm.Text) { objControl.IsValid = false; objControl.ValidationErrorMsg = "两次密码输入不一致!"; if (objControl == TxtPassword && string.IsNullOrEmpty(TxtConfirm.Text)) { objControl.IsValid = true; } } else { TxtPassword.IsValid = true; TxtConfirm.IsValid = true; } } break; } if (!objControl.IsValid && objControl.IsValidated) { ((Control)objControl).Focus(); } }