Exemplo n.º 1
0
        public bool Delete(int idhaodon, int idhang)
        {
            decimal thanhtiencu = 0;

            try
            {
                using (var db = new QLPhongKaraokeEntities())
                {
                    var x = from s in db.CT_HOADONDV
                            where s.ID_HoaDonDV == idhaodon && s.ID_Hang == idhang && s.Deleted == 0
                            select s;
                    var sv   = x.FirstOrDefault();
                    var hang = (from s in db.HANGs where s.ID == idhang select s).FirstOrDefault();

                    if (sv != null)
                    {
                        thanhtiencu = sv.ThanhTien;
                        sv.Deleted  = 1;
                        db.SaveChanges();

                        // cap nhat so luong ton
                        hang.SLTon += sv.SoLuong;
                        db.SaveChanges();
                        //cap nhat tong tien hoa don
                        var hd = new MMHOADONDV();
                        hd.UpdateTongTien(sv.ID_HoaDonDV, hd.GetOne(sv.ID_HoaDonDV).TongTien - thanhtiencu);
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public bool Insert(BCTONKHO item)
        {
            try
            {
                using (var db = new QLPhongKaraokeEntities())
                {
                    db.BCTONKHOes.Add(item);
                    db.SaveChanges();
                    //lay id BC
                    int id = (from s in db.BCTONKHOes where s.Thang == item.Thang select s.ID).FirstOrDefault();

                    List <GetListBCTonKho_Result> _ctbc = GetList(item.Thang);
                    for (int i = 0; i < _ctbc.Count; i++)
                    {
                        CT_BCTONKHO ctbc = new CT_BCTONKHO();
                        ctbc.ID_BCTonKho = id;
                        ctbc.ID_Hang     = _ctbc[i].ID;
                        ctbc.TonDau      = _ctbc[i].tondau.GetValueOrDefault();
                        ctbc.SuDung      = _ctbc[i].soluongban.GetValueOrDefault();
                        ctbc.SoLuongNhap = _ctbc[i].soluongnhap.GetValueOrDefault();
                        ctbc.TonCuoi     = _ctbc[i].toncuoi.GetValueOrDefault();
                        db.CT_BCTONKHO.Add(ctbc);
                        db.SaveChanges();
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 3
0
 public bool Update(CT_HDNHAP phong)
 {
     try
     {
         using (var db = new QLPhongKaraokeEntities())
         {
             var x = from s in db.CT_HDNHAP
                     where (s.IDHoaDon == phong.IDHoaDon && s.IDHang == phong.IDHang)
                     select s;
             var sv = x.FirstOrDefault();
             if (sv != null)
             {
                 sv.SoLuong    = phong.SoLuong;
                 sv.ThanhTien  = phong.ThanhTien;
                 sv.DonGiaNhap = phong.DonGiaNhap;
                 db.SaveChanges();
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 4
0
        public bool Update(PHIEUCHI item)
        {
            try
            {
                using (var db = new QLPhongKaraokeEntities())
                {
                    var x = from s in db.PHIEUCHIs
                            where s.ID == item.ID && s.Deleted == 0
                            select s;
                    var sv = x.FirstOrDefault();
                    if (sv != null)
                    {
                        sv.NgayLap  = item.NgayLap;
                        sv.NoiDung  = item.NoiDung;
                        sv.TongTien = item.TongTien;
                        sv.GhiChu   = item.GhiChu;

                        db.SaveChanges();
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 5
0
 public bool Update(HANG item)
 {
     try
     {
         using (var db = new QLPhongKaraokeEntities())
         {
             var x = from s in db.HANGs
                     where s.ID == item.ID
                     select s;
             var sv = x.FirstOrDefault();
             if (sv != null)
             {
                 sv.Ten        = item.Ten;
                 sv.DonGiaNhap = item.DonGiaNhap;
                 sv.DonGiaBan  = item.DonGiaBan;
                 // sv.SLTon = GetSLTon();
                 sv.DonVi     = item.DonVi;
                 sv.Requested = item.Requested;
                 db.SaveChanges();
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 6
0
 public bool Update(HANG phong)
 {
     try
     {
         using (var db = new QLPhongKaraokeEntities())
         {
             var x = from s in db.HANGs
                     where (s.ID == phong.ID)
                     select s;
             var sv = x.FirstOrDefault();
             if (sv != null)
             {
                 sv.SLTon      = phong.SLTon;
                 sv.Ten        = phong.Ten;
                 sv.Requested  = phong.Requested;
                 sv.DonVi      = phong.DonVi;
                 sv.DonGiaBan  = phong.DonGiaBan;
                 sv.DonGiaNhap = phong.DonGiaNhap;
                 db.SaveChanges();
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 7
0
 public bool Update(DATPHONG item)
 {
     try
     {
         using (var db = new QLPhongKaraokeEntities())
         {
             var x = from s in db.DATPHONGs
                     where s.ID == item.ID
                     select s;
             var sv = x.FirstOrDefault();
             if (sv != null)
             {
                 sv.NgayGioDat = item.NgayGioDat;
                 sv.SDT        = item.SDT;
                 sv.Note       = item.Note;
                 db.SaveChanges();
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 8
0
 public bool Update(LOAIPHONG item)
 {
     try
     {
         using (var db = new QLPhongKaraokeEntities())
         {
             var x = from s in db.LOAIPHONGs
                     where s.ID == item.ID && s.Deleted == 0
                     select s;
             var sv = x.FirstOrDefault();
             if (sv != null)
             {
                 sv.Ten     = item.Ten;
                 sv.GiaDem  = item.GiaDem;
                 sv.GiaNgay = item.GiaNgay;
                 sv.SoLuong = item.SoLuong;
                 db.SaveChanges();
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 9
0
        public bool Delete(int ID)
        {
            try
            {
                using (var db = new QLPhongKaraokeEntities())
                {
                    var x = from s in db.HOADONDVs
                            where s.ID == ID && s.Deleted == 0
                            select s;
                    var sv = x.FirstOrDefault();
                    if (sv != null)
                    {
                        sv.Deleted = 1;
                        db.SaveChanges();

                        (new MMCT_HoaDonDV()).DeleteAllHoaDon(ID); // xoa hoa don thi xoa luon ct
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 10
0
        public bool Update(HOADONNHAP phong)
        {
            try
            {
                using (var db = new QLPhongKaraokeEntities())
                {
                    var x = from s in db.HOADONNHAPs
                            where s.ID == phong.ID
                            select s;
                    var sv = x.FirstOrDefault();
                    if (sv != null)
                    {
                        sv.NgayNhap = phong.NgayNhap;
                        sv.TongTien = phong.TongTien;

                        db.SaveChanges();
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 11
0
        public bool Begin(int id, DateTime tgbatdau, string tenkh)
        {
            try
            {
                using (var db = new QLPhongKaraokeEntities())
                {
                    var x = from s in db.PHONGs
                            where s.ID == id && s.Deleted == 0
                            select s;
                    var sv = x.FirstOrDefault();
                    if (sv != null)
                    {
                        if (sv.StatusID != 1)
                        {
                            return(false);
                        }
                        sv.StatusID = 3; //busy
                        sv.TGStart  = tgbatdau;
                        db.SaveChanges();

                        //bat dau thi tao hoa don dv
                        var item = new HOADONDV()
                        {
                            ID_Phong   = id,
                            NgayGioLap = tgbatdau,
                            SoGio      = 0,
                            TenKH      = tenkh ?? "",
                            TongTien   = 0
                        };
                        db.HOADONDVs.Add(item);
                        db.SaveChanges();
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 12
0
        public bool Update(CT_HOADONDV item)
        {
            decimal thanhtiencu = 0;

            try
            {
                using (var db = new QLPhongKaraokeEntities())
                {
                    var x = from s in db.CT_HOADONDV
                            where s.ID_HoaDonDV == item.ID_HoaDonDV && s.ID_Hang == item.ID_Hang && s.Deleted == 0
                            select s;
                    var sv   = x.FirstOrDefault();
                    var hang = (from s in db.HANGs where s.ID == sv.ID_Hang select s).FirstOrDefault();

                    if (sv != null)
                    {
                        thanhtiencu = sv.ThanhTien;
                        var soluongcu = sv.SoLuong;

                        sv.SoLuong   = item.SoLuong;
                        sv.DonGia    = item.DonGia;
                        sv.ThanhTien = item.ThanhTien;
                        db.SaveChanges();

                        //cap nhat soluong
                        hang.SLTon = hang.SLTon + soluongcu - sv.SoLuong;
                        db.SaveChanges();

                        var hd       = new MMHOADONDV(); //khi cap nhat thi cap nhat lai tong tien
                        var tongtien = hd.GetOne(sv.ID_HoaDonDV).TongTien - thanhtiencu + item.ThanhTien;
                        hd.UpdateTongTien(sv.ID_HoaDonDV, tongtien);
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 13
0
        public bool End(int idphong)
        {
            try
            {
                using (var db = new QLPhongKaraokeEntities())
                {
                    var x = from s in db.PHONGs
                            where s.ID == idphong && s.Deleted == 0
                            select s;
                    var sv = x.FirstOrDefault();
                    if (sv != null)
                    {
                        if (sv.StatusID != 3)
                        {
                            return(false);
                        }

                        decimal tienphong = 0;
                        //Ket thuc thi tinh tien hoa don.
                        var hoadon     = (from s in db.HOADONDVs where s.ID_Phong == idphong orderby s.ID descending select s).FirstOrDefault();
                        var loaiphong  = (from s in db.LOAIPHONGs where s.ID == sv.IdLoaiPhong select s).FirstOrDefault();
                        var giongaydem = DateTime.Parse("2012/12/12 " + (from s in db.THAMSOes where s.Name == "GioNgayDem" select s).FirstOrDefault().Value);
                        hoadon.SoGio = (DateTime.Now - sv.TGStart.GetValueOrDefault()).TotalHours;

                        //tinh tong tien +=  tien phog. tien nuoc uong lien tuc duoc cap nha roi
                        DateTime t2 = DateTime.Parse("2012/12/12 " + sv.TGStart.GetValueOrDefault().ToString("HH:mm:ss"));
                        if (giongaydem < t2 || t2 < DateTime.Parse("2012/12/12 06:00:00"))
                        {
                            tienphong        = Convert.ToDecimal(hoadon.SoGio.GetValueOrDefault() * (double)loaiphong.GiaDem.GetValueOrDefault());
                            hoadon.TongTien += tienphong;
                        }
                        else
                        {
                            tienphong        = Convert.ToDecimal(hoadon.SoGio.GetValueOrDefault() * (double)loaiphong.GiaNgay.GetValueOrDefault());
                            hoadon.TongTien += tienphong;
                        }

                        //sau do cap nhat tinh trnag phong, lam tron so
                        hoadon.TongTien  = Math.Round(hoadon.TongTien, 0);
                        hoadon.TienPhong = Math.Round(tienphong, 0);
                        sv.StatusID      = 1; //free
                        sv.TGStart       = null;
                        db.SaveChanges();
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 14
0
        public bool Insert(CT_HOADONDV item)
        {
            try
            {
                using (var db = new QLPhongKaraokeEntities())
                {
                    var x = from s in db.CT_HOADONDV
                            where s.ID_HoaDonDV == item.ID_HoaDonDV && s.ID_Hang == item.ID_Hang
                            select s;
                    var sv   = x.FirstOrDefault();
                    var hang = (from s in db.HANGs where s.ID == item.ID_Hang select s).FirstOrDefault();

                    if (sv != null) //da co thi cap nhat sl chu khong co them
                    {
                        sv.SoLuong   += item.SoLuong;
                        sv.ThanhTien += item.ThanhTien;
                        db.SaveChanges();
                    }
                    else
                    {
                        db.CT_HOADONDV.Add(item);
                        db.SaveChanges();
                    }
                    //cap nhat so luong ton
                    hang.SLTon -= item.SoLuong;
                    db.SaveChanges();
                    //cap nhat tong tien hoadon
                    var hd = new MMHOADONDV();
                    hd.UpdateTongTien(item.ID_HoaDonDV, hd.GetOne(item.ID_HoaDonDV).TongTien + item.ThanhTien);
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 15
0
 public bool Insert(LOAIPHONG item)
 {
     try
     {
         using (var db = new QLPhongKaraokeEntities())
         {
             db.LOAIPHONGs.Add(item);
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 16
0
 public bool Insert(HANG phong)
 {
     try
     {
         using (var db = new QLPhongKaraokeEntities())
         {
             db.HANGs.Add(phong);
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 17
0
 public bool Update(NGUOIDUNG item)
 {
     try
     {
         using (var db = new QLPhongKaraokeEntities())
         {
             var x = from s in db.NGUOIDUNGs
                     where s.ID == item.ID
                     select s;
             var sv = x.FirstOrDefault();
             if (sv != null)
             {
                 if (sv.MaDangNhap.CompareTo(item.MaDangNhap) != 0)
                 {
                     var y = from s in db.NGUOIDUNGs
                             where s.MaDangNhap == item.MaDangNhap
                             select s;
                     var svy = x.FirstOrDefault();
                     if (svy != null)
                     {
                         return(false);
                     }
                 }
                 sv.MaDangNhap  = item.MaDangNhap;
                 sv.MatKhau     = item.MatKhau;
                 sv.HoTen       = item.HoTen;
                 sv.Email       = item.Email;
                 sv.SoDT        = item.SoDT;
                 sv.MaNhomQuyen = item.MaNhomQuyen;
                 db.SaveChanges();
                 return(true);
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 18
0
 public bool UpdateTongTien(int id, decimal tongtien)
 {
     try
     {
         using (var db = new QLPhongKaraokeEntities())
         {
             var x = from s in db.HOADONDVs
                     where s.ID == id && s.Deleted == 0
                     select s;
             var sv = x.FirstOrDefault();
             if (sv != null)
             {
                 sv.TongTien = tongtien;
                 db.SaveChanges();
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 19
0
 public bool Delete(int ID)
 {
     try
     {
         using (var db = new QLPhongKaraokeEntities())
         {
             var x = from s in db.LOAIPHONGs
                     where s.ID == ID && s.Deleted == 0
                     select s;
             var sv = x.FirstOrDefault();
             if (sv != null)
             {
                 sv.Deleted = 1;
                 db.SaveChanges();
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 20
0
 public bool Update(THAMSO item)
 {
     try
     {
         using (var db = new QLPhongKaraokeEntities())
         {
             var x = from s in db.THAMSOes
                     where s.Name == item.Name && s.Deleted == 0
                     select s;
             var sv = x.FirstOrDefault();
             if (sv != null)
             {
                 sv.Value = item.Value;
                 db.SaveChanges();
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 21
0
 public bool Delete(int ID)
 {
     try
     {
         using (var db = new QLPhongKaraokeEntities())
         {
             var x = from s in db.HANGs
                     where s.ID == ID
                     select s;
             var sv = x.FirstOrDefault();
             if (sv != null)
             {
                 db.HANGs.Remove(sv);
                 db.SaveChanges();
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 22
0
 public bool Delete(int IDHoaDon, int IDHang)
 {
     try
     {
         using (var db = new QLPhongKaraokeEntities())
         {
             var x = from s in db.CT_HDNHAP
                     where (s.IDHoaDon == IDHoaDon && s.IDHang == IDHang)
                     select s;
             var sv = x.FirstOrDefault();
             if (sv != null)
             {
                 sv.Deleted = 1;
                 db.SaveChanges();
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 23
0
 public bool Update(HOADONDV item)
 {
     try
     {
         using (var db = new QLPhongKaraokeEntities())
         {
             var x = from s in db.HOADONDVs
                     where s.ID == item.ID && s.Deleted == 0
                     select s;
             var sv = x.FirstOrDefault();
             if (sv != null)
             {
                 sv.TenKH    = item.TenKH;
                 sv.ID_Phong = item.ID_Phong;
                 db.SaveChanges();
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 24
0
        public bool DeleteAllHoaDon(int idhaodon)
        {
            try
            {
                using (var db = new QLPhongKaraokeEntities())
                {
                    var x = from s in db.CT_HOADONDV
                            where s.ID_HoaDonDV == idhaodon
                            select s;
                    foreach (var sv in x)
                    {
                        if (sv != null)
                        {
                            //cap nhat so luong ton
                            var hang = (from s in db.HANGs where s.ID == sv.ID_Hang select s).FirstOrDefault();
                            hang.SLTon += sv.SoLuong;

                            sv.Deleted = 1;
                            db.SaveChanges();
                        }
                    }
                    var y = (from s in db.HOADONDVs
                             where s.ID == idhaodon
                             select s).FirstOrDefault();
                    if (y != null)
                    {
                        (new MMHOADONDV()).Delete(y.ID);
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 25
0
 public bool Insert(NGUOIDUNG item)
 {
     try
     {
         using (var db = new QLPhongKaraokeEntities())
         {
             var x = from s in db.NGUOIDUNGs
                     where s.MaDangNhap == item.MaDangNhap
                     select s;
             var sv = x.FirstOrDefault();
             if (sv == null)
             {
                 db.NGUOIDUNGs.Add(item);
                 db.SaveChanges();
                 return(true);
             }
             return(false);//trung username
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 26
0
 public bool Update(PHONG item)
 {
     try
     {
         using (var db = new QLPhongKaraokeEntities())
         {
             var x = from s in db.PHONGs
                     where s.ID == item.ID
                     select s;
             var sv = x.FirstOrDefault();
             if (sv != null)
             {
                 sv.Ten         = item.Ten;
                 sv.IdLoaiPhong = item.IdLoaiPhong;
                 db.SaveChanges();
             }
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }