Ejemplo n.º 1
0
        private void addButton_Click(object sender, EventArgs e)
        {
            try
            {
                //Empty condition area
                if (String.IsNullOrEmpty(idTextBox.Text))
                {
                    MessageBox.Show("Id Can not be Empty!!!");
                    return;
                }
                if (String.IsNullOrEmpty(nameTextBox.Text))
                {
                    MessageBox.Show("Name Can not be Empty!!!");
                    return;
                }
                if (String.IsNullOrEmpty(addressTextBox.Text))
                {
                    MessageBox.Show("Address Can not be Empty!!!");
                    return;
                }
                if (String.IsNullOrEmpty(contactTextBox.Text))
                {
                    MessageBox.Show("contact Can not be Empty!!!");
                    return;
                }

                //Check UNIQUE
                if (_customerBll.IsContactExists(idTextBox.Text))
                {
                    MessageBox.Show("Id " + idTextBox.Text + " is Already Exists!");
                    return;
                }
                if (_customerBll.IsContactExists(nameTextBox.Text))
                {
                    MessageBox.Show("Name " + nameTextBox.Text + " is Already Exists!");
                    return;
                }
                if (_customerBll.IsContactExists(contactTextBox.Text))
                {
                    MessageBox.Show("Conact " + contactTextBox.Text + " is Already Exists!");
                    return;
                }


                //Add/Insert Item
                bool isAdded = _customerBll.Add(Convert.ToInt32(idTextBox.Text), nameTextBox.Text, addressTextBox.Text, Convert.ToInt32(contactTextBox.Text));

                if (isAdded)
                {
                    MessageBox.Show("Saved");
                }
                else
                {
                    MessageBox.Show("Not Saved");
                }

                //showDataGridView.DataSource = dataTable;
                showDataGridView.DataSource = _customerBll.Display();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }