예제 #1
0
        private void btnEditButton_Click(object sender, EventArgs e)
        {
            Company company = new Company();

            company = (Company)bsCompanies.Current;
            CompanyForm frmCompanyForm = new CompanyForm(company);

            frmCompanyForm.MdiParent = MdiParent;
            frmCompanyForm.Show();
            frmCompanyForm.Text              = "Szczegóły firmy - Edytuj dane firmy";
            frmCompanyForm.SaveButton.Click += delegate
            {
                company = frmCompanyForm.Company;
                string            errorText         = string.Empty;
                CompanyRepository companyRepository = new CompanyRepository();
                if (Validation.ValidateCompany(company, ref errorText))
                {
                    companyRepository.Update(company);
                    frmCompanyForm.Close();
                }
                else
                {
                    ShowErrorMessage(errorText);
                }
                bsCompanies.DataSource = companyRepository.FindAll();
                grdCompanies.Refresh();
            };
            frmCompanyForm.CancelChangesButton.Click += delegate
            {
                CompanyRepository companyRepository = new CompanyRepository();
                bsCompanies.DataSource = companyRepository.FindAll();
                grdCompanies.Refresh();
            };
        }
예제 #2
0
        private void btnAddButton_Click(object sender, EventArgs e)
        {
            Company     company        = new Company();
            CompanyForm frmCompanyForm = new CompanyForm(company);

            frmCompanyForm.MdiParent            = MdiParent;
            frmCompanyForm.AddButton.Enabled    = false;
            frmCompanyForm.EditButton.Enabled   = false;
            frmCompanyForm.DeleteButton.Enabled = false;
            frmCompanyForm.Show();
            frmCompanyForm.Text              = "Szczegóły firmy - Dodaj firmę";
            frmCompanyForm.SaveButton.Click += delegate
            {
                company = frmCompanyForm.Company;
                string            errorText         = string.Empty;
                CompanyRepository companyRepository = new CompanyRepository();
                if (Validation.ValidateCompany(company, ref errorText))
                {
                    companyRepository.Add(company);
                    frmCompanyForm.Close();
                }
                else
                {
                    ShowErrorMessage(errorText);
                }
                bsCompanies.DataSource = companyRepository.FindAll();
                grdCompanies.Refresh();
            };
        }