Ejemplo n.º 1
0
        void ThemPhong()
        {
            using (QuanLiKhachSanEntities db = new QuanLiKhachSanEntities())
            {
                string id  = (Int32.Parse(db.Phong.Select(m => m.ID).Max()) + 1).ToString();
                string ten = txbTenPhong.Text;

                if (db.Phong.Select(m => m.Ten).Contains(ten))
                {
                    MessageBox.Show("Tên phòng đã tồn tại");
                    return;
                }
                int loai      = (cbLoaiPhong.SelectedValue as LoaiPhong).ID;
                int trangthai = (cbTrangThai.SelectedValue as TinhTrang).ID;

                Phong p = new Phong()
                {
                    ID          = id,
                    Ten         = ten,
                    IDLoai      = loai,
                    IDTinhTrang = trangthai
                };

                db.Phong.Add(p);
                db.SaveChanges();

                MessageBox.Show("Thêm phòng thành công");
                LoadPhong(dtgvPhong);
            }
        }
Ejemplo n.º 2
0
        Form nextForm(string id, string pass)
        {
            Form f = new Form();

            int roll = (int)Cons.Roll.TiepTan;

            using (QuanLiKhachSanEntities db = new QuanLiKhachSanEntities())
            {
                var   t = db.Users.Where(p => p.IDNhanVien.Equals(id) && p.Pass.Equals(pass));
                Users u = t.Count() == 1 ? t.Single() : null;
                if (u != null)
                {
                    NhanVien nv = db.NhanVien.Where(p => u.IDNhanVien.Equals(p.ID)).Single();
                    roll = (int)nv.ChucDanh.Roll;

                    Cons.Cons.LoginNhanVien = nv;
                }
                else
                {
                    MessageBox.Show("Tên đăng nhập hoặc mật khẩu không đúng");
                    return(null);
                }
            }

            switch (roll)
            {
            case (int)Cons.Roll.TiepTan:
                f = new QuanLiThuePhong();
                break;
            }

            return(f);
        }
Ejemplo n.º 3
0
        private void dtgvPhong_SelectionChanged(object sender, EventArgs e)
        {
            if (cbLoaiPhong.DataSource == null || dtgvPhong.SelectedCells.Count == 0)
            {
                return;
            }
            string loai  = dtgvPhong.SelectedCells[0].OwningRow.Cells["Loại"].Value.ToString();
            int    index = 0;

            using (QuanLiKhachSanEntities db = new QuanLiKhachSanEntities())
            {
                index = db.LoaiPhong.Select(p => p.Ten).ToList().IndexOf(loai);
            }


            cbLoaiPhong.SelectedIndex = index;

            if (cbTrangThai.DataSource == null || dtgvPhong.SelectedCells.Count == 0)
            {
                return;
            }
            string loaiTrangThai = dtgvPhong.SelectedCells[0].OwningRow.Cells["Loại"].Value.ToString();
            int    index2        = 0;

            using (QuanLiKhachSanEntities db = new QuanLiKhachSanEntities())
            {
                index2 = db.LoaiPhong.Select(p => p.Ten).ToList().IndexOf(loaiTrangThai);
            }


            cbTrangThai.SelectedIndex = index2;
        }
Ejemplo n.º 4
0
 void LoadTinhTrang(ComboBox cb)
 {
     using (QuanLiKhachSanEntities db = new QuanLiKhachSanEntities())
     {
         cb.DataSource    = db.TinhTrang.ToList();
         cb.DisplayMember = "Ten";
     }
 }
Ejemplo n.º 5
0
        void XoaPhong()
        {
            using (QuanLiKhachSanEntities db = new QuanLiKhachSanEntities())
            {
                string id = txbIDPhong.Text;

                db.Phong.Remove(db.Phong.Find(id));
                db.SaveChanges();

                MessageBox.Show("Xóa phòng thành công");
                LoadPhong(dtgvPhong);
            }
        }
Ejemplo n.º 6
0
        void SuaPhong()
        {
            using (QuanLiKhachSanEntities db = new QuanLiKhachSanEntities())
            {
                string id = txbIDPhong.Text;

                Phong phong = db.Phong.Find(id);

                int loai      = (cbLoaiPhong.SelectedValue as LoaiPhong).ID;
                int trangthai = (cbTrangThai.SelectedValue as TinhTrang).ID;

                phong.IDLoai      = loai;
                phong.IDTinhTrang = trangthai;


                db.SaveChanges();

                MessageBox.Show("Sửa phòng thành công");
                LoadPhong(dtgvPhong);
            }
        }
Ejemplo n.º 7
0
        //load thông tin phòng trong datagridview tương ứng

        void LoadPhong(DataGridView dtgv)
        {
            using (QuanLiKhachSanEntities db = new QuanLiKhachSanEntities())
            {
                var source = from p in db.Phong
                             from l in db.LoaiPhong
                             from t in db.TinhTrang
                             where p.IDLoai.Equals(l.ID) &&
                             p.IDTinhTrang.Equals(t.ID)
                             select new
                {
                    ID        = p.ID,
                    Tên       = p.Ten,
                    Loại      = l.Ten,
                    Status    = t.Ten,
                    Giá       = l.Gia,
                    Số_Giường = l.SoGiuong
                };

                dtgv.DataSource = source.ToList();
            }

            BindingPhong(dtgvPhong);
        }