Ejemplo n.º 1
0
 /// <summary>
 /// The method of adding  info about Client and Car to Parking
 /// </summary>
 private void AddToBalanceParking()
 {
     using (ParkingContext db = new ParkingContext())
     {
         var            tempCar    = db.Cars.Where(c => c.NumberCar == txbInfoNumber.Text).FirstOrDefault();
         int            tempNum    = Int32.Parse(txbInfoPhone.Text);
         var            tempClient = db.Clients.Where(c => c.Phone == tempNum).FirstOrDefault();
         BalanceParking temPlace   = new BalanceParking {
             ClientId = tempClient.Id, CarId = tempCar.Id, DataAdded = DateTime.Parse(txbInfoDate.Text), Place = (int)SenderPlace
         };
         var isExistPlace = db.BalanceParking.Where(pl => pl.CarId == temPlace.CarId).FirstOrDefault();
         if (isExistPlace == null)
         {
             db.BalanceParking.Add(temPlace);
             db.HistoryAddedCars.Add(new HistoryAddedCars {
                 ClientId = tempClient.Id, CarId = tempCar.Id, DataAdded = DateTime.Parse(txbInfoDate.Text), Place = (int)SenderPlace
             });
             db.SaveChanges();
             StatisticsOfPlaces.UpdateStatisticsPlaces(temPlace.Place, '+');
             StatisticsOfPlaces.ShowStatisticsInMainWind();
             SetColor.SetColorForPlaces((List <Button>)(this.Owner as MainWindow).ListButtons);
             this.Close();
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Notice place in list of buttons
        /// </summary>
        /// <param name="ListBtns"></param>
        /// <param name="blPark"></param>
        /// <returns></returns>
        private bool FindPlaceSetScheme(IEnumerable <Button> ListBtns, BalanceParking blPark)
        {
            var res = ListBtns.Where(n => n.Content.ToString() == blPark.Place.ToString()).FirstOrDefault();

            if (res != null)
            {
                res.BorderBrush     = Brushes.Black;
                res.BorderThickness = new Thickness(4);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Find place by numberCar
 /// </summary>
 /// <param name="numberCar"></param>
 private void FindPlaceByNumberCar(string numberCar)
 {
     using (ParkingContext db = new ParkingContext())
     {
         BalanceParking findPlace = db.BalanceParking.Where(p => p.Car.NumberCar == numberCar).FirstOrDefault();
         if (findPlace != null)
         {
             if (FindPlaceSetScheme(ListButtons, findPlace))
             {
                 ShowSector(findPlace);
             }
         }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Find place by client's phone
 /// </summary>
 /// <param name="phoneClient"></param>
 private void FindPlaceByPhoneClient(string phoneClient)
 {
     phoneClient = phoneClient.TrimStart('0');
     using (ParkingContext db = new ParkingContext())
     {
         BalanceParking findPlace = db.BalanceParking.Where(p => p.Client.Phone.ToString() == phoneClient.ToString()).FirstOrDefault();
         if (findPlace != null)
         {
             if (FindPlaceSetScheme(ListButtons, findPlace))
             {
                 ShowSector(findPlace);
             }
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Show place in sector with border
 /// </summary>
 /// <param name="result"></param>
 private void ShowSector(BalanceParking result)
 {
     if (Int32.Parse(result.Place.ToString()) > 0 & Int32.Parse(result.Place.ToString()) < 22)
     {
         SetColor.SetColorForPlaces(ListButtons);
         sector1.Show();
     }
     if (Int32.Parse(result.Place.ToString()) > 21 & Int32.Parse(result.Place.ToString()) < 46)
     {
         SetColor.SetColorForPlaces(ListButtons);
         sector2.Show();
     }
     if (Int32.Parse(result.Place.ToString()) > 45 & Int32.Parse(result.Place.ToString()) < 67)
     {
         sector3.Show();
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Take the car out off the parking place
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnMoveFromPlace_Click(object sender, RoutedEventArgs e)
 {
     if (CheckAllFieldsClickPlace())
     {
         using (ParkingContext db = new ParkingContext())
         {
             using (var tran = db.Database.BeginTransaction())
             {
                 try
                 {
                     BalanceParking bal = db.BalanceParking.Where(b => b.Place == SenderPlace).FirstOrDefault();
                     //BalanceParking bal = new BalanceParking { Place = (int)SenderPlace };
                     //db.BalanceParking.Attach(bal);
                     if (bal != null)
                     {
                         db.BalanceParking.Remove(bal);
                         db.HistoryDeletedCars.Add(new HistoryDeletedCars {
                             ClientId = bal.ClientId, CarId = bal.CarId, DataAdded = bal.DataAdded, Place = (int)SenderPlace
                         });
                         db.SaveChanges();
                         tran.Commit();
                         btnMoveFromPlace.IsEnabled = false;
                         btnSaveToPlace.IsEnabled   = false;
                         StatisticsOfPlaces.UpdateStatisticsPlaces(bal.Place, '-');
                         StatisticsOfPlaces.ShowStatisticsInMainWind();
                         SetColor.SetColorForPlaces((List <Button>)(this.Owner as MainWindow).ListButtons);
                         this.Close();
                     }
                 }
                 catch (Exception)
                 {
                     tran.Rollback();
                 }
             }
         }
     }
 }