Пример #1
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            int parsedValue;

            if (!int.TryParse(textBoxOrderBy.Text, out parsedValue))
            {
                ProcessInvalid(labelOrderBy);
                MessageBox.Show("OrderBy contains number only", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (textBoxClass.Text == "")
            {
                ProcessInvalid(labelClass);
                MessageBox.Show("Class name can't be empty", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (CheckClassExists(textBoxClass.Text))
            {
                ProcessInvalid(labelClass);
                MessageBox.Show("Class already exists", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (CheckOrderByExists(textBoxOrderBy.Text))
            {
                ProcessInvalid(labelOrderBy);
                MessageBox.Show("Order already exists", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                var sec = new Class
                {
                    ClassName = textBoxClass.Text,
                    IsActive  = checkBoxIsActive.Checked,
                    OrderBy   = int.Parse(textBoxOrderBy.Text)
                };
                if (_settingService.AddClass(sec))
                {
                    MessageBox.Show("Data Saved Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ProcessValid(labelClass);
                    ProcessValid(labelOrderBy);
                    gridViewSelectedId = sec.ClassId.ToString();
                    LoadDataClass(_settingService.GetClassList());
                    dataGridViewClass.Refresh();
                }
                else
                {
                    MessageBox.Show("error");
                }
            }
        }