Exemplo n.º 1
0
        private void btnTao_Click(object sender, EventArgs e)
        {
            Tour tour = new Tour();

            tour.TenGoi   = txtTenTour.Text;
            tour.DacDiem  = txtDacDiem.Text;
            tour.LoaiDLId = dsloaidl[cbLoaiDL.SelectedIndex].Id; var stt = 1;
            foreach (var i in dscttour)
            {
                i.ThuTuThamQuan = stt;
                tour.CTTours.Add(i);
                stt++;
            }
            GiaTour gia = new GiaTour();

            gia.Gia         = Convert.ToInt32(txtGiaTour.Text);
            gia.NgayCapNhat = DateTime.Now.Date;
            tour.GiaTours.Add(gia);
            if (db.Them(tour) > 0)
            {
                txtTenTour.Text = "";
                txtDacDiem.Text = "";
                txtGiaTour.Text = "";
                GridDDTour.Rows.Clear();
                MessageBox.Show("Tạo tour thành công");
            }
            else
            {
                MessageBox.Show("Tạo tour thất bại");
            }
        }
Exemplo n.º 2
0
 public int Sua(object a)
 {
     try
     {
         if (a.GetType().ToString().IndexOf("Tour") > 1)
         {
             Tour temp = (Tour)a;
             temp = db.Tours.Where(s => s.Id == temp.Id).FirstOrDefault();
             db.Entry(temp).CurrentValues.SetValues(a);
         }
         else if (a.GetType().ToString().IndexOf("TinhThanh") > 1)
         {
             TinhThanh temp = (TinhThanh)a;
             temp = db.TinhThanhs.Where(s => s.Id == temp.Id).First();
             db.Entry(temp).CurrentValues.SetValues(a);
         }
         else if (a.GetType().ToString().IndexOf("DiaDiem") > 1)
         {
             DiaDiem temp = (DiaDiem)a;
             temp = db.DiaDiems.Where(s => s.Id == temp.Id).First();
             db.Entry(temp).CurrentValues.SetValues(a);
         }
         else if (a.GetType().ToString().IndexOf("LoaiDL") > 1)
         {
             LoaiDL temp = (LoaiDL)a;
             temp = db.LoaiDLs.Where(s => s.Id == temp.Id).First();
             db.Entry(temp).CurrentValues.SetValues(a);
         }
         else if (a.GetType().ToString().IndexOf("CTTour") > 1)
         {
             CTTour temp = (CTTour)a;
             temp = db.CTTours.Where(s => s.Id == temp.Id).First();
             db.Entry(temp).CurrentValues.SetValues(a);
         }
         else if (a.GetType().ToString().IndexOf("GiaTour") > 1)
         {
             GiaTour temp = (GiaTour)a;
             temp = db.GiaTours.Where(s => s.Id == temp.Id).First();
             db.Entry(temp).CurrentValues.SetValues(a);
         }
         db.SaveChanges();
         return(1);
     }
     catch
     {
         return(0);
     }
 }
Exemplo n.º 3
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            GiaTour a = new GiaTour();

            a.Gia         = Convert.ToInt32(txtGia.Text);
            a.NgayCapNhat = Convert.ToDateTime(txtNgay.Text);
            tour.GiaTours.Add(a);
            if (db.Sua(tour) > 0)
            {
                MessageBox.Show("Thêm thành công");
            }
            else
            {
                MessageBox.Show("Thêm thất bại");
            }
            refeshGia();
        }