예제 #1
0
        private void btnInsertFailure_Click(object sender, EventArgs e)
        {
            if (comboBoxCounties.SelectedIndex > 0 && comboBoxCities.SelectedIndex > 0 && comboBoxTypesOfFailure.SelectedIndex > 0)
            {
                int userId = _failureRepository.GetUserIdByString(userName);

                string countyComboBox = comboBoxCounties.SelectedItem.ToString();
                int    countyId       = _failureRepository.GetCountyIdByString(countyComboBox);

                string cityCombobox = comboBoxCities.SelectedItem.ToString();
                int    cityId       = _failureRepository.GetCityIdByString(cityCombobox);

                string typeOfFailureCombobox = comboBoxTypesOfFailure.SelectedItem.ToString();
                int    typeOfFailureId       = _failureRepository.GetTypeOfFailureIdByString(typeOfFailureCombobox);

                string additionalDescription = richTextBoxAdditionalDescription.Text.ToString();

                if (dateChanged)
                {
                    var dateTimeFromChanged = dateTimePickerBeginOfFailure.Value;

                    var failure = new Failure
                    {
                        Id_Username           = userId,
                        Id_TypeOfFailure      = typeOfFailureId,
                        Id_City               = cityId,
                        BeginOfFailure        = dateTimeFromChanged,
                        AdditionalDescription = additionalDescription
                    };
                    _failureRepository.AddFailure(failure);
                }
                else
                {
                    var dateTimeFrom = dateTimePickerBeginOfFailure.Value;

                    var failure = new Failure
                    {
                        Id_Username           = userId,
                        Id_TypeOfFailure      = typeOfFailureId,
                        Id_City               = cityId,
                        BeginOfFailure        = dateTimeFrom,
                        AdditionalDescription = additionalDescription
                    };
                    _failureRepository.AddFailure(failure);
                }
            }
            else
            {
                MessageBox.Show("Odaberite županiju, grad i vrstu ispada!");
            }
        }