Пример #1
0
        private void buttonBuild_Click(object sender, EventArgs e)
        {
            if (!FormValidateHelper.DesignJournalValidateInputs(this))
            {
                return;
            }

            float price  = 0;
            int   amount = 0;

            if (!float.TryParse(textBoxPrice.Text, out price))
            {
                MessageBox.Show("Incorrect field \"Price\"");
                return;
            }
            if (!int.TryParse(textBoxAmount.Text, out amount))
            {
                MessageBox.Show("Incorrect field \"Amount\"");
            }

            _journal = new Journal()
            {
                Id          = _journal?.Id ?? 0,
                Title       = textBoxTitle.Text,
                Periodicity = textBoxPeriodicity.Text,
                Subjects    = textBoxSubjects.Text,
                Date        = textBoxDate.Text,
                Amount      = amount,
                Price       = price
            };
            this.DialogResult = DialogResult.OK;
        }
Пример #2
0
        private void buttonBuild_Click(object sender, EventArgs e)
        {
            if (!FormValidateHelper.DesignBookValidateInputs(this))
            {
                return;
            }

            int   year   = 0;
            int   pages  = 0;
            float price  = 0;
            int   amount = 0;

            if (!int.TryParse(textBoxYear.Text, out year))
            {
                MessageBox.Show("Incorrect field \"Year\"");
                return;
            }
            if (!int.TryParse(textBoxPages.Text, out pages))
            {
                MessageBox.Show("Incorrect field \"Pages\"");
            }
            if (!float.TryParse(textBoxPrice.Text, out price))
            {
                MessageBox.Show("Incorrect field \"Price\"");
                return;
            }
            if (!int.TryParse(textBoxAmount.Text, out amount))
            {
                MessageBox.Show("Incorrect field \"Amount\"");
            }


            _book = new Book()
            {
                Id     = _book?.Id ?? 0,
                Title  = textBoxTitle.Text,
                Author = textBoxAuthor.Text,
                Genre  = textBoxGenre.Text,
                Year   = year,
                Pages  = pages,
                Amount = amount,
                Price  = price
            };
            this.DialogResult = DialogResult.OK;
        }
Пример #3
0
        ValidationResult[] IFormItem.ValidateField()
        {
            if (Rules == null)
            {
                return(Array.Empty <ValidationResult>());
            }

            var results = new List <ValidationResult>();

            var displayName = string.IsNullOrEmpty(Label) ? _fieldIdentifier.FieldName : Label;

            if (_fieldPropertyInfo != null)
            {
                var propertyValue = _fieldPropertyInfo.GetValue(_fieldIdentifier.Model);

                var validateMessages = Form.ValidateMessages ?? ConfigProvider?.Form?.ValidateMessages ?? new FormValidateErrorMessages();

                foreach (var rule in Rules)
                {
                    var validationContext = new FormValidationContext()
                    {
                        Rule             = rule,
                        Value            = propertyValue,
                        FieldName        = _fieldIdentifier.FieldName,
                        DisplayName      = displayName,
                        ValidateMessages = validateMessages,
                    };

                    var result = FormValidateHelper.GetValidationResult(validationContext);

                    if (result != null)
                    {
                        results.Add(result);
                    }
                }
            }

            return(results.ToArray());
        }