Ejemplo n.º 1
0
        private void ClubsGrid_RowValidating(object sender, GridViewRowValidatingEventArgs e)
        {
            this.ValidationSummary.Errors.Clear();

            var club = e.Row.DataContext as Club;

            if (string.IsNullOrEmpty(club.Name) || club.Name.Length < 5)
            {
                this.ValidationSummary.Errors.Add(new ErrorInfo()
                {
                    SourceFieldDisplayName = "Name",
                    ErrorContent           = "Name is required and must be at least five characters!"
                });
                e.IsValid = false;
            }

            if (club.StadiumCapacity < 0)
            {
                this.ValidationSummary.Errors.Add(new ErrorInfo()
                {
                    SourceFieldDisplayName = "StadiumCapacity",
                    ErrorContent           = "StadiumCapacity must be positive!"
                });
                e.IsValid = false;
            }
        }
Ejemplo n.º 2
0
        private void AddValidating(GridViewRowValidatingEventArgs e, string error, string property_name)
        {
            GridViewCellValidationResult validationResult = new GridViewCellValidationResult();

            validationResult.PropertyName = property_name;
            validationResult.ErrorMessage = error;
            e.ValidationResults.Add(validationResult);
            e.IsValid = false;
            AddError(property_name, error);
        }
        private void GridView_RowValidating(object sender, GridViewRowValidatingEventArgs e)
        {
            bool        isValid        = true;
            string      validationText = "Validation failed. ";
            GridViewRow row            = e.Row;

            foreach (GridViewCell cell in row.Cells)
            {
                object value = cell.Value;
                switch (cell.Column.UniqueName)
                {
                case "ContactName":
                    isValid = ValidateName((string)value);
                    if (!isValid)
                    {
                        validationText += "The name of the customer may contain only Latin letters" +
                                          Environment.NewLine + "and empty spaces and must start with a letter.";
                    }
                    break;

                //case "Country":
                //    isValid = this.ValidateCountry((string)e.NewValue);
                //    if (!isValid)
                //    {
                //        validationText += "The name of the country must match the name of an existing one.";
                //    }
                //    break;
                case "Phone":
                    isValid = ValidatePhone((string)value);
                    if (!isValid)
                    {
                        validationText += "The phone must be in one of the formats X.X.X.X, Y or (X) Y, where " +
                                          Environment.NewLine +
                                          "X is a random sequence of numerals and Y is a random sequence of numerals, " +
                                          Environment.NewLine +
                                          "empty spaces and '-', which starts and ends with a numeral.";
                    }
                    break;

                case "PostalCode":
                    isValid = ValidatePostalCode(value);
                    if (!isValid)
                    {
                        validationText += "The postal code of the customer must not be empty.";
                    }
                    break;

                // Truongnx add
                case "AccountName":
                    isValid = ValidateAccountName((string)value);
                    if (!isValid)
                    {
                        validationText += "The account name must not be empty.";
                    }
                    break;

                case "AccountNo":
                    isValid = ValidateAccountNo((string)value);
                    if (!isValid)
                    {
                        validationText += "The account number must not be empty and must be in range 0-9.";
                    }
                    break;

                case "BankCode":
                    isValid = ValidateBank((string)value);
                    if (!isValid)
                    {
                        validationText += "The bank must not be empty.";
                    }
                    break;

                case "Branch":
                    isValid = ValidateBranch((string)value);
                    if (!isValid)
                    {
                        validationText += "The branch must not be empty.";
                    }
                    break;
                }
                if (!isValid)
                {
                    this.MarkCell(cell, validationText);
                    e.IsValid = isValid;
                    return;
                }
                else
                {
                    this.RestoreCell(cell);
                }
            }
            e.IsValid = isValid;
        }
Ejemplo n.º 4
0
        private void GridView_RowValidating(object sender, GridViewRowValidatingEventArgs e)
        {
            bool isValid = true;
            //string validationText = "Validation failed. ";
            string      validationText = "Giá trị không phù hợp. ";
            GridViewRow row            = e.Row;

            foreach (GridViewCell cell in row.Cells)
            {
                object value = cell.Value;
                switch (cell.Column.UniqueName)
                {
                case "ContactName":
                    isValid = ValidateName((string)value);
                    if (!isValid)
                    {
                        validationText += "The name of the customer may contain only Latin letters" +
                                          Environment.NewLine + "and empty spaces and must start with a letter.";
                    }
                    break;

                case "Country":
                    isValid = this.ValidateCountry((string)value);
                    if (!isValid)
                    {
                        validationText += "The name of the country must match the name of an existing one.";
                    }
                    break;

                case "Phone":
                    isValid = ValidatePhone((string)value);
                    if (!isValid)
                    {
                        validationText += "The phone must be in one of the formats X.X.X.X, Y or (X) Y, where " +
                                          Environment.NewLine +
                                          "X is a random sequence of numerals and Y is a random sequence of numerals, " +
                                          Environment.NewLine +
                                          "empty spaces and '-', which starts and ends with a numeral.";
                    }
                    break;

                case "PostalCode":
                    isValid = ValidatePostalCode(value);
                    if (!isValid)
                    {
                        validationText += "The postal code of the customer must not be empty.";
                    }
                    break;

                // Truongnx add
                case "SO_CTU":
                    isValid = ValidateSO_CTU((string)value);
                    if (!isValid)
                    {
                        validationText += "Số chứng từ không được để trống.";
                    }
                    break;

                case "CAU_THANH":
                    isValid = ValidateCAU_THANH((string)value);
                    if (!isValid)
                    {
                        validationText += "Chưa chọn cấu thành nguyên giá.";
                    }
                    break;

                case "HTHUC_TTOAN":
                    isValid = ValidateHTHUC_TTOAN((string)value);
                    if (!isValid)
                    {
                        validationText += "Chưa chọn hình thức thanh toán.";
                    }
                    break;

                case "NGAY_CTU":
                    //isValid = ValidateNGAY_CTU((string)value);
                    //if (!isValid)
                    //{
                    //    validationText += "Ngày chứng từ không được để trống.";
                    //}
                    break;

                case "GIA_TRI":
                    isValid = ValidateGIA_TRI((string)value);
                    if (!isValid)
                    {
                        validationText += "Giá trị nguyên giá không được để trống và chỉ là các ký tự số.";
                    }
                    break;

                    //case "TKHOAN_TTOAN":
                    //    isValid = ValidateTKHOAN_TTOAN((string)value);
                    //    if (!isValid)
                    //    {
                    //        validationText += "Tài khoản thanh toán không được để trống và chỉ là các ký tự số.";
                    //    }
                    //    break;
                }
                if (!isValid)
                {
                    this.MarkCell(cell, validationText);
                    e.IsValid = isValid;
                    return;
                }
                else
                {
                    this.RestoreCell(cell);
                }
            }
            e.IsValid = isValid;
        }