Esempio n. 1
0
        /// <summary>
        /// Handles the Click event of the Repair control. Changes the status of the vehicle from "w naprawie" to "Sprawny". It does an update on the associative HISTORY_NAPRAW table specifying the end of the repair period.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void Repair_Click(object sender, RoutedEventArgs e)
        {
            dynamic obj = this.pojazdGrid.SelectedValue;

            if (obj.STATUS != "W naprawie")
            {
                MessageBox.Show("Najpierw przyjmij pojazd do naprawy!");
            }
            else
            {
                int pojazdID = obj.ID;

                POJAZD newPojazd = (POJAZD)con.POJAZD.Where(poj => poj.ID == pojazdID).First();
                newPojazd.STATUS = "Sprawny";
                con.POJAZD.Attach(newPojazd);
                con.Entry(newPojazd).Property(poj => poj.STATUS).IsModified = true;

                HISTORIA_NAPRAW historia = (HISTORIA_NAPRAW)con.HISTORIA_NAPRAW.Where(hn => hn.ID_POJAZD == pojazdID && hn.DO_KIEDY == null).First();
                historia.DO_KIEDY = DateTime.Now;
                con.HISTORIA_NAPRAW.Attach(historia);
                con.Entry(historia).Property(x => x.DO_KIEDY).IsModified = true;

                con.SaveChanges();
                loadVehicle();
                MessageBox.Show("Pojazd naprawiony, oddany do użytku.");
            }
        }
        /// <summary>
        /// Handles the Click event of the Report control. Changes the status of the vehicle with "Sprawny" to "Oczekuję na naprawę"
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void Report_Click(object sender, RoutedEventArgs e)
        {
            if (pojazdGrid.SelectedIndex > -1)
            {
                dynamic obj   = this.pojazdGrid.SelectedValue;
                int     pojID = obj.ID;
                int     osID  = obj.ID_OSOBA;
                if (obj.STATUS == "Do kasacji")
                {
                    MessageBox.Show("Ten pojazd jest przeznaczony do kasacji.");
                }
                else if (obj.STATUS == "W naprawie")
                {
                    MessageBox.Show("Ten pojazd jest już w naprawie");
                }
                else if (obj.STATUS == "Oczekuje na naprawę")
                {
                    MessageBox.Show("Ten pojazd już został zgłoszony");
                }
                else
                {
                    int      idPrzeglad  = con.PRZEGLAD.Select(h => h.ID).DefaultIfEmpty(0).Max() + 1;
                    PRZEGLAD newPrzeglad = new PRZEGLAD(idPrzeglad);
                    con.PRZEGLAD.Add(newPrzeglad);

                    //con.Entry<PRZEGLAD>(newPrzeglad).State = System.Data.Entity.EntityState.Added;

                    int             idHistoriaNapraw  = con.HISTORIA_NAPRAW.Select(h => h.ID).DefaultIfEmpty(0).Max() + 1;
                    HISTORIA_NAPRAW newHistoriaNapraw = new HISTORIA_NAPRAW(idHistoriaNapraw, DateTime.Now, obj.ID, idPrzeglad);
                    con.HISTORIA_NAPRAW.Add(newHistoriaNapraw);

                    //con.Entry<HISTORIA_NAPRAW>(newHistoriaNapraw).State = System.Data.Entity.EntityState.Added;

                    POJAZD newPojazd = (POJAZD)con.POJAZD.Where(poj => poj.ID == pojID).First();
                    newPojazd.STATUS = "W naprawie";
                    con.POJAZD.Attach(newPojazd);
                    con.Entry(newPojazd).Property(poj => poj.STATUS).IsModified = true;
                    con.SaveChanges();
                    loadVehicle();

                    //con.Entry<PRZEGLAD>(newPrzeglad).State = System.Data.Entity.EntityState.Detached;
                    //con.Entry<HISTORIA_NAPRAW>(newHistoriaNapraw).State = System.Data.Entity.EntityState.Detached;

                    con.Entry <POJAZD>(newPojazd).State = System.Data.Entity.EntityState.Detached;
                    MessageBox.Show("Zgłoszono Pojazd do naprawy");
                }
            }
        }