Пример #1
0
        private void themDV()
        {
            tenphong = cbbPhong.SelectedItem.ToString();
            var result = (from sdp in db.PHIEUTHUEPHONGs
                          join p in db.PHONGs on sdp.MaPhong equals p.MaPhong
                          where p.SoPhong == tenphong
                          select new
            {
                mkh = sdp.MaPhong
            }
                          ).FirstOrDefault();

            tendv = cbbDichVu.SelectedItem.ToString();
            var ABC = (from dv in db.DICHVUs
                       where dv.TenDV == tendv
                       select new
            {
                mdv = dv.MaDV
            }
                       ).FirstOrDefault();

            if (string.IsNullOrWhiteSpace(cbbPhong.ValueMember))
            {
                var newSDDV = new DICHVU_SD()
                {
                    MaDV    = ABC.mdv,
                    MaPhong = result.mkh,

                    SoLuong = Convert.ToInt16(cbbSoLuong.SelectedItem),
                };
                db.DICHVU_SD.AddOrUpdate(newSDDV);
                db.SaveChanges();
            }
        }
Пример #2
0
        private void buttonXoa_Click(object sender, EventArgs e)
        {
            tenphong = cbbPhong.SelectedItem.ToString();
            var result = (from sdp in db.PHIEUTHUEPHONGs
                          join p in db.PHONGs on sdp.MaPhong equals p.MaPhong
                          where p.SoPhong == tenphong
                          select new
            {
                mkh = sdp.MaPhong
            }
                          ).FirstOrDefault();
            var newSDDV = new DICHVU_SD()
            {
                MaPhong = result.mkh,
            };

            db.DICHVU_SD.Remove(newSDDV);

            db.SaveChanges();
        }