private void CommitButton_Click(object sender, EventArgs e)
        {
            bool filled = Utils.CheckFormFilled(this);

            if (filled)
            {
                Control nameBox    = Utils.FindControl(this, "nameBox");
                Control surnameBox = Utils.FindControl(this, "surnameBox");
                Control ageBox     = Utils.FindControl(this, "ageBox");

                string name      = nameBox.Text;
                string surname   = surnameBox.Text;
                string ageString = ageBox.Text;

                bool nameValidated = PersonFormValidator.ValidateName(name, surname);
                bool ageValidated  = PersonFormValidator.ValidateAge(ageString);

                if (nameValidated && ageValidated)
                {
                    person.Name    = name;
                    person.Surname = surname;
                    person.Age     = int.Parse(ageString);

                    DocumentManagementForm form = (DocumentManagementForm)Application.OpenForms["DocumentManagementForm"];
                    form.UpdatePersonsBox();
                    form.UpdateCompaniesBox();
                    Controls.Remove(nameBox);
                    Controls.Remove(surnameBox);
                    Controls.Remove(ageBox);
                    Controls.Remove((Control)sender);
                    AddInfoForms();
                }
                else
                {
                    MessageBox.Show("Неправильно введенные данные!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Одно из полей пустое!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        private void AddCompanyButton_Click(object sender, EventArgs e)
        {
            bool filled = Utils.CheckFormFilled(this);

            if (filled && director != null)
            {
                String      name    = Utils.FindControl(this, "nameBox").Text;
                String      address = Utils.FindControl(this, "addressBox").Text;
                CompanyType type    = (CompanyType)((ComboBox)Utils.FindControl(this, "typeBox")).SelectedValue;

                bool nameValidated    = CompanyFormValidator.ValidateName(name);
                bool addressValidated = CompanyFormValidator.ValidateAddress(address);
                if (nameValidated && addressValidated)
                {
                    Chancery chancery = new Chancery
                    {
                        Archive          = new List <Document>(),
                        PendingDocuments = new List <Document>(),
                        Secretaries      = new List <Secretary>()
                    };
                    Company company = new Company(director, type, chancery, name, address);
                    company.Persist();
                    DocumentManagementForm form = (DocumentManagementForm)Application.OpenForms["DocumentManagementForm"];
                    form.UpdateCompaniesBox();
                    Close();
                    Dispose();
                }
                else
                {
                    MessageBox.Show("Неправильно введенные данные!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Одно из полей пустое!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #3
0
        private void CommitEditEvent(object sender, EventArgs e)
        {
            bool filled  = true;
            bool correct = true;

            foreach (Control c in Controls)
            {
                if (c is TextBox)
                {
                    if (string.IsNullOrWhiteSpace(c.Text) || director == null)
                    {
                        MessageBox.Show("Одно из полей пустое!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        filled = false;
                        break;
                    }
                }
            }
            if (filled)
            {
                Control nameBox               = Utils.FindControl(this, "nameBox");
                Control addressBox            = Utils.FindControl(this, "addressBox");
                Control personsBox            = Utils.FindControl(this, "personsBox");
                Control typeBox               = Utils.FindControl(this, "typeBox");
                Control directorBox           = Utils.FindControl(this, "directorBox");
                Control directorChooserButton = Utils.FindControl(this, "directorChooserButton");
                Button  openChanceryButton    = (Button)Utils.FindControl(this, "openChanceryButton");
                try
                {
                    if (directorChanged)
                    {
                        //Удаляем старого директора
                        company.Director.Delete();
                        company.Director = null;
                        //Добавляем нового директора
                        director.Persist();
                        company.Director = director;
                    }
                    //Обновляем компанию
                    string      name    = nameBox.Text;
                    string      address = addressBox.Text;
                    CompanyType type    = (CompanyType)((ComboBox)typeBox).SelectedItem;
                    company.Name    = name;
                    company.Address = address;
                    company.Type    = type;
                    DocumentManagementForm form = (DocumentManagementForm)Application.OpenForms["DocumentManagementForm"];
                    form.UpdateCompaniesBox();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Неправильно введенные данные!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    correct = false;
                }
                if (correct)
                {
                    Controls.Remove(nameBox);
                    Controls.Remove(addressBox);
                    Controls.Remove(typeBox);
                    Controls.Remove(personsBox);
                    Controls.Remove(directorBox);
                    Controls.Remove(directorChooserButton);
                    Controls.Remove((Control)sender);
                    openChanceryButton.Enabled = true;
                    directorChanged            = false;
                    AddInfoForms();
                }
            }
        }