Beispiel #1
0
    /// <summary>
    /// Validate the form
    /// </summary>
    /// <returns>True if valid</returns>
    private bool IsValidForm()
    {
        bool rval = true;

        ErrorMsg.InnerHtml = string.Empty;
        foreach (Control ctl in phAddForm.Controls)
        {
            if (ctl.GetType().Name == "TextBox")
            {
                TextBox txt = (TextBox)ctl;
                // check if required
                if (_settings.IsRequiredParameter(txt.ID) && string.IsNullOrEmpty(txt.Text.Trim()))
                {
                    ErrorMsg.InnerHtml = "\"" + _settings.GetLabel(txt.ID) + "\" is a required field";
                    ErrorMsg.Visible   = true;
                    rval = false;
                    break;
                }
                // check data type
                if (!string.IsNullOrEmpty(txt.Text) && !ValidateType(txt.ID, txt.Text))
                {
                    ErrorMsg.InnerHtml = "\"" + _settings.GetLabel(txt.ID) + "\" must be a " + _settings.GetParameterType(txt.ID);
                    ErrorMsg.Visible   = true;
                    rval = false;
                    break;
                }
                if (!_settings.IsScalar)
                {
                    if (_settings.KeyField == (txt.ID) && _settings.IsKeyValueExists(txt.Text.Trim()))
                    {
                        ErrorMsg.InnerHtml = "\"" + txt.Text + "\" is already exists";
                        ErrorMsg.Visible   = true;
                        rval = false;
                        break;
                    }
                }
            }
        }
        return(rval);
    }