示例#1
0
        private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            MessageBox.Show("Wygenerować załączniki do wybranej pozycji?");
            DataGrid    dg    = (DataGrid)sender;
            ZGLOSZENIA_ row   = dg.SelectedItem as ZGLOSZENIA_;
            string      numer = row.DATA_PADNIECIA.ToString();

            MessageBox.Show(numer);
        }
示例#2
0
        //zapisujemy zgłoszenie
        private void btnSaveNewNotificationOfAnimalDead_Click(object sender, RoutedEventArgs e) //przycisk "Zapisz zgłoszenie"
        {
            if (String.IsNullOrWhiteSpace(txtEarTagNumber.Text))                                // sprawdzamy czy wszystkie pola są wypełnione
            {
                MessageBox.Show("Uzupełnij numer kolczyka");
                return;
            }
            else if (String.IsNullOrWhiteSpace(txtDateBorn.Text))
            {
                MessageBox.Show("Uzupełnij datę urodzenia");
                return;
            }
            else if (String.IsNullOrWhiteSpace(txtDateDead.Text))
            {
                MessageBox.Show("Uzupełnij datę padnięcia");
                return;
            }
            else if (String.IsNullOrWhiteSpace(txtHourOfDeadAnimal.Text))
            {
                MessageBox.Show("Uzupełnij godzinę padnięcia");
                return;
            }
            else if (String.IsNullOrWhiteSpace(txtHowManyAnimalsInFarm.Text))
            {
                MessageBox.Show("Uzupełnij liczbę sztuk w stadzie");
                return;
            }
            else if (String.IsNullOrWhiteSpace(txtWhoReportingNewNotification.Text) ||
                     String.IsNullOrWhiteSpace(txtAddressPersonReporting.Text))
            {
                MessageBox.Show("Uzupełnij dane zgłaszającego");
                return;
            }

            string farmNumber, dateBorn, howManyAnimalsInFarm, earTagNumber, whyDead, dateDead, hourOfDeadAnimal, typeOfDeadAnimal, genderOfDeadAnimal,
                   deadDeterminedOrNot, utilizationCompany, whoReportingNewNotification, addressPersonReporting, phonePersonReporting,
                   whoGetNewNotification, dateAndTimeNewNotificationOfAnimalDead, typeOfFarm, comment;

            WhatTypeOfAnimalDead(); //odczyt jaki gatunek zwierzęcia padł

            DataOfNewNotification(out farmNumber, out dateBorn, out howManyAnimalsInFarm, out earTagNumber, out whyDead, out dateDead,
                                  out hourOfDeadAnimal, out whoReportingNewNotification, out addressPersonReporting, out phonePersonReporting,
                                  out whoGetNewNotification, out dateAndTimeNewNotificationOfAnimalDead, out typeOfFarm, out genderOfDeadAnimal,
                                  out deadDeterminedOrNot, out utilizationCompany, out typeOfDeadAnimal, out comment); //pobranie z formularza danych zgłoszenia

            try
            {
                //zapis do bazy za pomocą Entity Framework
                using (var db2 = new BAZA_ARIMREntities())
                {
                    ZGLOSZENIA_ newItem = new ZGLOSZENIA_();
                    newItem.ID                = 1;
                    newItem.NR_STADA          = farmNumber;
                    newItem.TYP_STADA         = typeOfFarm;
                    newItem.LICZBA_SZTUK      = Convert.ToDouble(howManyAnimalsInFarm);
                    newItem.NR_KOLCZYKA       = earTagNumber;
                    newItem.GATUNEK           = typeOfDeadAnimal;
                    newItem.PLEC              = genderOfDeadAnimal;
                    newItem.DATA_URODZENIA    = dateBorn;
                    newItem.DATA_PADNIECIA    = dateDead;
                    newItem.GODZINA_PADNIECIA = hourOfDeadAnimal;
                    newItem.PRZYCZYNA         = deadDeterminedOrNot;
                    newItem.OPIS_PRZYCZYNA    = whyDead;
                    newItem.KTO_ODBIERA       = utilizationCompany;
                    newItem.OSOBA_ZGL         = whoReportingNewNotification;
                    newItem.ADRES_OSOBY_ZGL   = addressPersonReporting;
                    newItem.TEL_OSOBY_ZGL     = phonePersonReporting;
                    newItem.DATA_CZAS_ZGL     = dateAndTimeNewNotificationOfAnimalDead;
                    newItem.KTO_PRZYJMUJE_ZGL = whoGetNewNotification;

                    db2.ZGLOSZENIA_.Add(newItem);
                    db2.SaveChanges();
                }
                PrintSendMail okno = new PrintSendMail(this);// otwieramy nowe okno
                okno.Owner = this;
                okno.ShowDialog();

                ClearAlls(); // czyszczenie wszystkoch boxów i pól
            }
            catch (SqlException odbcEx)
            {
                MessageBox.Show("Coś poszło nie tak z zapisem zgłoszenia, trzeba to sprawdzić.");// obsługa bardziej szczegółowych wyjątków
            }
            catch (Exception ex)
            {
                MessageBox.Show("Błąd 2"); // obsługa wyjątku głównego
            }
            //koniec zapisu Entity Framework

            string WhatTypeOfAnimalDead()
            {
                if (checkOwca.IsChecked == true)
                {
                    txtTypeOfDeadAnimal.Text = "owca";
                    return(txtTypeOfDeadAnimal.Text);
                }
                else if (checkBydlo.IsChecked == true)
                {
                    txtTypeOfDeadAnimal.Text = "bydlo";
                    return(txtTypeOfDeadAnimal.Text);
                }
                else if (checkKoza.IsChecked == true)
                {
                    txtTypeOfDeadAnimal.Text = "koza";
                    return(txtTypeOfDeadAnimal.Text);
                }
                return(txtTypeOfDeadAnimal.Text = "brak");
            }
        }