コード例 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (ValidateChildren(ValidationConstraints.Enabled))
            {
                try
                {
                    BOCompany       BO = new BOCompany();
                    BusinessManager BM = new BusinessManager();
                    BO.CompanyName = txtCompanyName.Text.Trim();
                    bool res = BM.BALVerifyCompanyName(BO);

                    if (res == true)
                    {
                        MessageBox.Show("Company name already exits. Please enter a new company name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtCompanyName.Text = "";
                        txtCompanyName.Focus();
                    }

                    int rowsAffected = BM.BALInsertCompany(BO);

                    if (rowsAffected > 0)
                    {
                        MessageBox.Show("Successfully saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        btnSave.Enabled = false;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }