예제 #1
0
        private void Form2_Load(object sender, EventArgs e)
        {
            //System.IO.StreamReader file = new System.IO.StreamReader(@"E:\Choose.txt") ;
            //string choose_tour;
            //choose_tour = file.ReadLine();
            //file.Close();
            //Tour tour = new Tour();
            TourContext db     = new TourContext();
            var         tours2 = db.Tours.Where(t => t.Status == "Reserved");

            //tour.ReadFromFile(tours2);
            foreach (Tour tour2 in tours2)
            {
                //if(tour2.country == choose_tour)
                //{
                materialSingleLineTextField1.Text = Convert.ToString(tour2.Сountry);
                materialSingleLineTextField2.Text = Convert.ToString(tour2.Rate);
                materialSingleLineTextField3.Text = Convert.ToString(tour2.lenght);
                materialSingleLineTextField4.Text = Convert.ToString(tour2.Price);
                materialSingleLineTextField5.Text = Convert.ToString(tour2.Hotel);
                materialSingleLineTextField6.Text = Convert.ToString(tour2.RoomType);
                materialSingleLineTextField7.Text = Convert.ToString(tour2.Transport);
                materialSingleLineTextField8.Text = Convert.ToString(tour2.DepartureDate);
                break;
                //}
            }
        }
예제 #2
0
        public void ConfirmOrder(Order order)
        {
            order.Status = "Payed";
            TourContext db = new TourContext();

            db.Orders.Add(order);
            db.SaveChanges();
        }
예제 #3
0
 public void AddTourToDB(Tour tour)//4-5.6 - create
 {
     using (TourContext db = new TourContext())
     {
         db.Tours.Add(tour);
         db.SaveChanges();
     }
 }
예제 #4
0
        public void UpdateTourPrice(string country, int price)//4-5.6 - update
        {
            using (TourContext db = new TourContext())
            {
                Tour t1 = db.Tours.FirstOrDefault(t => t.Сountry == country);//5-6.10

                t1.Price = price;
                db.SaveChanges();   // сохраняем изменения
            }
        }
예제 #5
0
 private void Union()//5-6.18
 {
     using (TourContext db = new TourContext())
     {
         var tours = db.Tours.Where(t => t.Price < 2500)
                     .Union(db.Tours.Where(t => t.Rate > 4));
         //foreach (var item in tours)
         //Console.WriteLine(item.Name);
     }
 }
예제 #6
0
        private void Form3_Load(object sender, EventArgs e)
        {
            TourContext db    = new TourContext();
            var         tour2 = db.Tours.Where(t => t.Status == "Reserved");

            foreach (Tour t in tour2)
            {
                materialLabel3.Text = Convert.ToString(t.Price);
                break;
            }
        }
예제 #7
0
 public void DeleteTour(string country)//4-5.6 - delete
 {
     using (TourContext db = new TourContext())
     {
         Tour p1 = db.Tours.FirstOrDefault(t => t.Сountry == country);
         if (p1 != null)
         {
             db.Tours.Remove(p1);
             db.SaveChanges();
         }
     }
 }
예제 #8
0
        public void ChoosenTour(string choosen_tour)
        {
            TourContext db   = new TourContext();
            Tour        tour = db.Tours.FirstOrDefault(t => t.Сountry == choosen_tour);

            tour.Status = "Reserved";
            db.SaveChanges();
            Form2 f2 = new Form2();

            this.Hide();
            f2.Show();
        }
예제 #9
0
        private void Except()//5-6.18
        {
            using (TourContext db = new TourContext())
            {
                var selector1 = db.Tours.Where(t => t.Price < 2500);
                var selector2 = db.Tours.Where(t => t.Сountry.Contains("Italy"));
                var phones    = selector1.Except(selector2);

                //foreach (var item in phones)
                //    Console.WriteLine(item.Name);
            }
        }
예제 #10
0
 private Tour[] Eager_loading()//завантаження даних(жадна загрузка) 4-5.7
 {
     using (TourContext db = new TourContext())
     {
         var    Tours = db.Tours.Include(t => t.Region).ToList();
         Tour[] tours = new Tour[Tours.Count];
         foreach (Tour t in Tours)
         {
             MessageBox.Show(t.Region.Name);
         }
         return(tours);
     }
 }
예제 #11
0
 private void Group_By_Status()//5-6.11
 {
     using (TourContext db = new TourContext())
     {
         int count  = db.Tours.Count();//5-6.15
         var groups = from t in db.Tours
                      group t by t.Status;
         foreach (var g in groups)
         {
             Console.WriteLine(g.Key);
             foreach (var t in g)
             {
                 Console.WriteLine("{0} - {1}", t.Сountry, t.Price);
             }
             Console.WriteLine();
         }
     }
 }
예제 #12
0
 private void Join()//5-6.12
 {
     using (TourContext db = new TourContext())
     {
         var tours = db.Tourists.Join(db.Orders,        // второй набор // 5-6.13 5-6.17
                                      t => t.Id,        // свойство-селектор объекта из первого набора
                                      o => o.TouristId, // свойство-селектор объекта из второго набора
                                      (t, o) => new     // результат
         {
             Name   = t.Name,
             Email  = o.Email,
             Price  = o.Price,
             Status = o.Status
         });
         foreach (var t in tours)
         {
             Console.WriteLine("{0} ({1}) - {2}", t.Name, t.Email, t.Status);
         }
     }
 }