예제 #1
0
        /// <summary>
        /// Кнопка подтверждения
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (ValidateForm())
            {
                // Создание сотрудника и адреса на основе данных формы
                EmployeeModel employee = new EmployeeModel(
                    TBFirstName.Text,
                    TBMiddleName.Text,
                    TBLastName.Text,
                    dtpDateOfBirth.Value,
                    TBDapartment.Text,
                    TBAbout.Text);

                AddressModel address = new AddressModel(
                    TBCountry.Text,
                    TBRegion.Text,
                    TBCity.Text,
                    TBStreetAddress.Text,
                    TBPostalCode.Text
                    );

                IDataConnection db = GlobalConfig.Connections[0];

                if ((this.EmployeeId > 0) && (this.AddressId > 0))
                {
                    employee.Id        = this.EmployeeId;
                    address.Id         = this.AddressId;
                    address.EmployeeId = this.EmployeeId;

                    db.UpdateEmployee(employee);
                    db.UpdateAddress(address);
                }
                else
                {
                    employee = db.CreateEmployee(employee);

                    address.EmployeeId = employee.Id;

                    db.CreateAddress(address);
                }
            }
        }