示例#1
0
        private AjaxReponseModel <dynamic> GetProductByID()
        {
            var response = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);

            try
            {
                var data = new StreamReader(Request.InputStream).ReadToEnd();
                var dym  = JsonConvert.DeserializeObject <Product>(data);
                int maSP = dym.MaSP;
                using (var ctx = new qlksEntities())
                {
                    var emp = ctx.tblSanPhams.AsEnumerable().Select(st => new
                    {
                        st.MaSP,
                        st.TenSP,
                        st.DonGia
                    }).Where(st => st.MaSP == maSP).ToList();
                    response.Data = emp;
                }
                return(response);
            }
            catch (Exception e)
            {
                return(response);
            }
            finally
            {
            }
        }
示例#2
0
        private AjaxReponseModel <dynamic> Login()
        {
            var response = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);
            var data     = new StreamReader(Request.InputStream).ReadToEnd();
            var dym      = JsonConvert.DeserializeObject <dynamic>(data);

            string userName = dym.userName;
            string passWord = dym.passWord;

            using (var db = new qlksEntities())
            {
                var user = db.tblNhanViens.SingleOrDefault(w => w.MatKhau == passWord && w.TenDangNhap == userName);

                if (user != null)
                {
                    response.Message     = "Đăng nhập thành công.";
                    Session["UserLogin"] = user;
                }
                else
                {
                    response.Status  = AjaxReponseStatusEnum.Fail;
                    response.Message = "Đăng nhập thất bại. Vui lòng kiểm tra lại tên đăng nhập hoặc mật khẩu.";
                }
            };

            return(response);
        }
示例#3
0
        private AjaxReponseModel <dynamic> UpdateProduct()
        {
            var response = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);

            try
            {
                var data = new StreamReader(Request.InputStream).ReadToEnd();
                var dym  = JsonConvert.DeserializeObject <Product>(data);
                int maSP = dym.MaSP;
                using (var db = new qlksEntities())
                {
                    tblSanPham sp = db.tblSanPhams.SingleOrDefault(w => w.MaSP == maSP);
                    sp.TenSP  = String.IsNullOrEmpty(dym.TenSP.ToString()) ? String.Empty : dym.TenSP.ToString().Trim();
                    sp.DonGia = dym.DonGia;

                    db.SaveChanges();
                    response.Message = "SUCCESS";
                };

                return(response);
            }
            catch (Exception e)
            {
                response.Message = "ERROR";
                return(response);
            }
            finally
            {
            }
        }
示例#4
0
        private AjaxReponseModel <dynamic> GetRoomByID()
        {
            var response = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);

            try
            {
                var data    = new StreamReader(Request.InputStream).ReadToEnd();
                var dym     = JsonConvert.DeserializeObject <Room>(data);
                int maPhong = dym.MaPhong;
                using (var ctx = new qlksEntities())
                {
                    var emp = ctx.tblPhongs.AsEnumerable().Where(st => st.MaPhong == maPhong).Select(st => new
                    {
                        st.MaPhong,
                        st.TenPhong,
                        st.DonGia,
                        StrTrangThai = st.TrangThai == true ? "Đã đặt" : "Trống",
                        TrangThai    = Convert.ToInt32(st.TrangThai)
                    }).ToList();
                    response.Data = emp;
                }
                return(response);
            }
            catch (Exception e)
            {
                return(response);
            }
            finally
            {
            }
        }
示例#5
0
        private AjaxReponseModel <dynamic> UpdateCustomer()
        {
            var response = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);

            try
            {
                var data = new StreamReader(Request.InputStream).ReadToEnd();
                var dym  = JsonConvert.DeserializeObject <Customer>(data);
                int maKH = dym.MaKH;
                using (var db = new qlksEntities())
                {
                    tblKhachHang kh = db.tblKhachHangs.SingleOrDefault(w => w.MaKH == maKH);
                    kh.TenKH    = String.IsNullOrEmpty(dym.TenKH.ToString()) ? String.Empty : dym.TenKH.ToString().Trim();
                    kh.SDT      = String.IsNullOrEmpty(dym.SDT.ToString()) ? String.Empty : dym.SDT.ToString().Trim();
                    kh.Email    = String.IsNullOrEmpty(dym.Email.ToString()) ? String.Empty : dym.Email.ToString().Trim();
                    kh.DiaChi   = String.IsNullOrEmpty(dym.DiaChi.ToString()) ? String.Empty : dym.DiaChi.ToString().Trim();
                    kh.NgaySinh = dym.NgaySinh;
                    kh.GioiTinh = dym.GioiTinh;
                    kh.CMND     = dym.CMND;

                    db.SaveChanges();
                    response.Message = "SUCCESS";
                };

                return(response);
            }
            catch (Exception e)
            {
                response.Message = "ERROR";
                return(response);
            }
            finally
            {
            }
        }
示例#6
0
        private AjaxReponseModel <dynamic> GetCustomerByID()
        {
            var response = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);

            try
            {
                var data = new StreamReader(Request.InputStream).ReadToEnd();
                var dym  = JsonConvert.DeserializeObject <Customer>(data);
                int maKH = dym.MaKH;
                using (var ctx = new qlksEntities())
                {
                    //var emp1 = ctx.tblNhanViens.ToList();
                    var emp = ctx.tblKhachHangs.AsEnumerable().Select(st => new
                    {
                        st.MaKH,
                        st.TenKH,
                        st.SDT,
                        NgaySinh = st.NgaySinh.GetValueOrDefault().ToString("dd-MM-yyyy"),
                        st.Email,
                        st.DiaChi,
                        st.CMND,
                        st.GioiTinh
                    }).Where(st => st.MaKH == maKH).ToList();
                    response.Data = emp;
                }
                return(response);
            }
            catch (Exception e)
            {
                return(response);
            }
            finally
            {
            }
        }
示例#7
0
        private AjaxReponseModel <dynamic> UpdateBookingRoom()
        {
            var response = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);
            var data     = new StreamReader(Request.InputStream).ReadToEnd();
            var dym      = JsonConvert.DeserializeObject <BookingRoomModel>(data);

            try
            {
                using (var db = new qlksEntities())
                {
                    var room = db.tblPhongs.FirstOrDefault(f => f.MaPhong == dym.MaPhong);
                    if (room != null)
                    {
                        room.TrangThai = true;
                    }

                    if (dym.SanPhamPhong != null && dym.SanPhamPhong.Length != 0)
                    {
                        foreach (var item in dym.SanPhamPhong)
                        {
                            if (item.MaSPP != null && item.MaSPP != 0)
                            {
                                var dvp = db.tblSanPhamPhongs.FirstOrDefault(f => f.MaPhieuDP == dym.MaPhieuDP && f.MaSPP == item.MaSPP);
                                dvp.SoLuong   = item.SoLuong;
                                dvp.ThanhTien = item.ThanhTien;
                            }
                            else
                            {
                                tblSanPhamPhong dichVuPhong = new tblSanPhamPhong()
                                {
                                    MaPhieuDP = dym.MaPhieuDP,
                                    MaSP      = item.MaSP,
                                    SoLuong   = item.SoLuong,
                                    DonGia    = item.DonGia,
                                    ThanhTien = item.ThanhTien
                                };
                                db.tblSanPhamPhongs.Add(dichVuPhong);
                            }
                        }
                    }

                    db.SaveChanges();

                    response.Message = "Cập nhật thành công.";
                };
            }
            catch (Exception e)
            {
                response.Status  = AjaxReponseStatusEnum.Fail;
                response.Message = "Cập nhật thất bại (Exception).";
            }

            return(response);
        }
        private AjaxReponseModel <dynamic> GetBookingRoom()
        {
            var response   = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);
            var roomId     = int.Parse(Request.Params["RoomId"]);
            var customerId = int.Parse(Request.Params["CustomerId"]);
            var phone      = Request.Params["Phone"];
            var maPhieuDP  = int.Parse(Request.Params["MaPhieuDP"]);

            using (var db = new qlksEntities())
            {
                var list = db.tblPhieuDatPhongs.Where(w => (maPhieuDP == 0 || w.MaPhieuDP == maPhieuDP) && (roomId == 0 || w.MaPhong == roomId) && (customerId == 0 || w.MaKH == customerId) && (phone == "" || w.tblKhachHang.SDT == phone)).Select(s => new
                {
                    s.MaPhieuDP,
                    s.MaPhong,
                    s.MaKH,
                    s.MaNV,
                    s.NgayBD,
                    s.NgayKT,
                    s.DonGia,
                    s.TongTien,
                    TrangThai = s.TrangThai == null ? false : true,
                    s.tblKhachHang.TenKH,
                    s.tblKhachHang.SDT,
                    s.tblPhong.TenPhong,
                    DichVuPhong = s.tblDichVuPhongs.Select(s1 => new
                    {
                        s1.MaDVP,
                        s1.MaPhieuDP,
                        s1.MaDV,
                        s1.tblDichVu.TenDV,
                        s1.DonGia,
                        s1.ThanhTien,
                        s1.SoLuong
                    }).ToList(),
                    SanPhamPhong = s.tblSanPhamPhongs.Select(s2 => new
                    {
                        s2.MaSPP,
                        s2.MaPhieuDP,
                        s2.MaSP,
                        s2.tblSanPham.TenSP,
                        s2.SoLuong,
                        s2.DonGia,
                        s2.ThanhTien
                    }).ToList()
                }).ToList();

                response.Data = list;
            };

            return(response);
        }
示例#9
0
        private AjaxReponseModel <dynamic> GetRoomList()
        {
            var response = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);

            try
            {
                var    data      = new StreamReader(Request.InputStream).ReadToEnd();
                var    dym       = JsonConvert.DeserializeObject <dynamic>(data);
                string maPhong   = dym.MaPhong;
                string tenPhong  = dym.TenPhong;
                string trangThai = dym.TrangThai;
                int    lau       = !string.IsNullOrEmpty(dym.Lau.ToString()) ? int.Parse(dym.Lau.ToString()) : 0;
                string loaiPhong = !string.IsNullOrEmpty(dym.LoaiPhong.ToString()) ? dym.LoaiPhong : "";

                using (var ctx = new qlksEntities())
                {
                    var emp = ctx.tblPhongs.AsEnumerable()
                              .Where(st => (maPhong == "" || st.MaPhong == Convert.ToInt32(maPhong)) &&
                                     (tenPhong == "" || st.TenPhong == tenPhong) &&
                                     (trangThai == "" || st.TrangThai == trangThai.Equals("1")) &&
                                     (lau == 0 || st.Lau == lau) &&
                                     (loaiPhong == "" || st.LoaiPhong == loaiPhong))
                              .Select(st => new
                    {
                        st.MaPhong,
                        st.TenPhong,
                        st.DonGia,
                        StrTrangThai = st.TrangThai == true ? "Đã đặt" : "Trống",
                        TrangThai    = Convert.ToInt32(st.TrangThai)
                    }).ToList();
                    response.Data = emp;
                }
                return(response);
            }
            catch (Exception e)
            {
                return(response);
            }
            finally
            {
            }
        }
示例#10
0
        private AjaxReponseModel <dynamic> PaymentBookingRoom()
        {
            var response = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);
            var data     = new StreamReader(Request.InputStream).ReadToEnd();
            var dym      = JsonConvert.DeserializeObject <BookingRoomModel>(data);

            try
            {
                using (var db = new qlksEntities())
                {
                    var pdp = db.tblPhieuDatPhongs.FirstOrDefault(f => f.MaPhieuDP == dym.MaPhieuDP);
                    if (pdp != null)
                    {
                        pdp.TrangThai = true;

                        var p = db.tblPhongs.FirstOrDefault(f => f.MaPhong == pdp.MaPhong);
                        if (p != null)
                        {
                            p.TrangThai = false;
                        }

                        db.SaveChanges();

                        response.Message = "Trả phòng thành công.";
                    }
                    else
                    {
                        response.Status  = AjaxReponseStatusEnum.Fail;
                        response.Message = "Trả phòng thất bại.";
                    }
                };
            }
            catch (Exception e)
            {
                response.Status  = AjaxReponseStatusEnum.Fail;
                response.Message = "Trả phòng thất bại (Exception).";
            }

            return(response);
        }
示例#11
0
        private AjaxReponseModel <dynamic> DeleteProduct()
        {
            var response = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);

            try
            {
                var data = new StreamReader(Request.InputStream).ReadToEnd();
                var dym  = JsonConvert.DeserializeObject <Product>(data);
                int maSP = dym.MaSP;
                using (var db = new qlksEntities())
                {
                    tblSanPham      sp  = db.tblSanPhams.SingleOrDefault(w => w.MaSP == maSP);
                    tblSanPhamPhong pdp = db.tblSanPhamPhongs.SingleOrDefault(w => w.MaSP == maSP);
                    if (pdp != null && pdp.MaPhieuDP > 0)
                    {
                        response.Message = "PDP_EXIST";
                    }
                    else
                    {
                        db.tblSanPhams.Remove(sp);
                        db.SaveChanges();
                        response.Message = "SUCCESS";
                    }
                };

                return(response);
            }
            catch (Exception e)
            {
                response.Message = "ERROR";
                return(response);
            }
            finally
            {
            }
        }
示例#12
0
        private AjaxReponseModel <dynamic> SaveBookingRoom()
        {
            var         response  = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);
            var         data      = new StreamReader(Request.InputStream).ReadToEnd();
            var         dym       = JsonConvert.DeserializeObject <BookingRoomModel>(data);
            tblNhanVien userLogin = Session["UserLogin"] as tblNhanVien;

            try
            {
                using (var db = new qlksEntities())
                {
                    tblPhieuDatPhong datPhong = new tblPhieuDatPhong()
                    {
                        MaKH     = dym.MaKH,
                        MaPhong  = dym.MaPhong,
                        MaNV     = userLogin.MaNV,
                        NgayBD   = dym.NgayBD,
                        NgayKT   = dym.NgayKT,
                        TongTien = dym.TongTien,
                        DonGia   = dym.DonGia
                    };

                    db.tblPhieuDatPhongs.Add(datPhong);
                    var numberSave = db.SaveChanges();

                    if (numberSave > 0)
                    {
                        var room = db.tblPhongs.FirstOrDefault(f => f.MaPhong == dym.MaPhong);
                        if (room != null)
                        {
                            room.TrangThai = true;
                        }

                        if (dym.SanPhamPhong != null && dym.SanPhamPhong.Length != 0)
                        {
                            List <tblSanPhamPhong> listSPP = new List <tblSanPhamPhong>();
                            foreach (var item in dym.SanPhamPhong)
                            {
                                tblSanPhamPhong dichVuPhong = new tblSanPhamPhong()
                                {
                                    MaPhieuDP = datPhong.MaPhieuDP,
                                    MaSP      = item.MaSP,
                                    SoLuong   = item.SoLuong,
                                    DonGia    = item.DonGia,
                                    ThanhTien = item.ThanhTien
                                };
                                listSPP.Add(dichVuPhong);
                            }

                            db.tblSanPhamPhongs.AddRange(listSPP);
                        }

                        db.SaveChanges();

                        response.Message = "Đặt phòng thành công.";
                    }
                    else
                    {
                        response.Status  = AjaxReponseStatusEnum.Fail;
                        response.Message = "Đặt phòng thất bại.";
                    }
                };
            }
            catch (Exception e)
            {
                response.Status  = AjaxReponseStatusEnum.Fail;
                response.Message = "Đặt phòng thất bại (Exception).";
            }

            return(response);
        }