private void btnSaveEdit_Click(object sender, EventArgs e)
        {
            if (dateChanged)
            {
                _failure.Id = Int32.Parse(lblFailure.Text);
                string typeOfFailure = lblTypeOfFailure.Text;
                _failure.Id_TypeOfFailure = _failureRepository.GetTypeOfFailureIdByString(typeOfFailure);
                string username = lblUsername.Text;
                _failure.Id_Username = _failureRepository.GetUserIdByString(username);
                string city = lblCity.Text;
                _failure.Id_City               = _failureRepository.GetCityIdByString(city);
                _failure.BeginOfFailure        = dateTimePickerBegin.Value;
                _failure.EndOfFailure          = dateTimePickerEnd.Value;
                _failure.AdditionalDescription = textBoxAdditionalDescription.Text;

                _failureRepository.UpdateFailure(_failure);
            }
            else
            {
                _failure.Id = Int32.Parse(lblFailure.Text);
                string typeOfFailure = lblTypeOfFailure.Text;
                _failure.Id_TypeOfFailure = _failureRepository.GetTypeOfFailureIdByString(typeOfFailure);
                string username = lblUsername.Text;
                _failure.Id_Username = _failureRepository.GetUserIdByString(username);
                string city = lblCity.Text;
                _failure.Id_City               = _failureRepository.GetCityIdByString(city);
                _failure.BeginOfFailure        = dateTimePickerBegin.Value;
                _failure.AdditionalDescription = textBoxAdditionalDescription.Text;

                _failureRepository.UpdateFailureWithoutDate(_failure);
            }
        }
Example #2
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!");
            }
        }