Example #1
0
        public ActionResult GiaHanPhong(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblHoaDon tblHoaDon = db.tblHoaDons.Find(id);

            if (tblHoaDon == null)
            {
                return(HttpNotFound());
            }
            tblPhieuDatPhong pdp = db.tblPhieuDatPhongs.Find(tblHoaDon.ma_pdp);
            String           dt  = null;

            try
            {
                DateTime d = (DateTime)db.tblPhieuDatPhongs.Where(t => t.ma_tinh_trang == 1 && t.ma_phong == pdp.tblPhong.ma_phong).Select(t => t.ngay_vao).OrderBy(t => t.Value).First();
                dt = d.ToString();
            }
            catch
            {
            }
            ViewBag.dateMax = dt;
            return(View(pdp));
        }
Example #2
0
 private void Form_ThuTien_Load(object sender, EventArgs e)
 {
     try
     {
         if (ca.getCart().Count > 0)
         {
             double sum = ca.tinhTong();
             lbl_TongTien.Text = sum + "";
             //lbl_TongTien.Text = mc.convertCurrency(sum);
         }
         else if (ca.getCart2().Count == 0)
         {
             tblHoaDon           h     = hd.getMaHDTheoBan(ca.getMaBan());
             List <tblChiTietHD> lstCT = (List <tblChiTietHD>)ct.getCTByMaHD(h.MaHD);
             lbl_TongTien.Text = lstCT.Sum(t => t.TongTien) + "";
             //lbl_TongTien.Text = mc.convertCurrency((double)lstCT.Sum(t => t.TongTien));
         }
         else if (ca.getCart2().Count > 0)
         {
             tblHoaDon           h     = hd.getMaHDTheoBan(ca.getMaBan());
             List <tblChiTietHD> lstCT = (List <tblChiTietHD>)ct.getCTByMaHD(h.MaHD);
             double sum = ca.tinhTong2();
             lbl_TongTien.Text = ((double)lstCT.Sum(t => t.TongTien) + sum) + "";
             //lbl_TongTien.Text = mc.convertCurrency((double)lstCT.Sum(t => t.TongTien) + sum);
         }
     }
     catch (Exception ee)
     { }
 }
Example #3
0
 public Form_ChiTietHoaDon(int maHDInput)
 {
     InitializeComponent();
     Current     = this;
     this.maHD   = maHDInput;
     this.hoaDon = hd.getHDByMaHD(maHDInput);
 }
        public void load3()
        {
            try
            {
                flowLayoutPanel1.Controls.Clear();
                bool colorFlag = false;


                tblHoaDon           h     = hd.getMaHDTheoBan(ca.getMaBan());
                List <tblChiTietHD> lstCT = (List <tblChiTietHD>)ct.getCTByMaHD(h.MaHD);
                for (int i = 0; i < lstCT.Count; i++)
                {
                    DoUongGioHang_Item_Temp item;
                    item      = new DoUongGioHang_Item_Temp(lstCT[i].tblThucDon.TenMon, lstCT[i].SoLuong, double.Parse(lstCT[i].tblThucDon.DonGia), colorFlag, lstCT[i].MaMon);
                    item.Dock = DockStyle.Top;
                    flowLayoutPanel1.Controls.Add(item);
                }

                List <Item> lstCart = ca.getCart2();
                for (int i = 0; i < lstCart.Count; i++)
                {
                    DoUongGioHang_Item_Temp item;
                    item      = new DoUongGioHang_Item_Temp(lstCart[i].tenMon, lstCart[i].sl, lstCart[i].donGia, colorFlag, lstCart[i].maMon);
                    item.Dock = DockStyle.Top;
                    flowLayoutPanel1.Controls.Add(item);
                }
            }
            catch (Exception ee)
            { }
        }
Example #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            tblHoaDon tblHoaDon = db.tblHoaDons.Find(id);

            db.tblHoaDons.Remove(tblHoaDon);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #6
0
 private void lbl_TenBan_Click(object sender, EventArgs e)
 {
     try
     {
         if (chuyen == 0)
         {
             ca.setMaBan(int.Parse(lbl_TenBan.Tag + ""));
             if ((Program.frmGM == null || Program.frmGM.IsDisposed) && lbl_TrangThai.Tag.ToString().Equals("False"))
             {
                 Program.frmGM = new Form_GoiMon();
             }
             else if ((Program.frmGM == null || Program.frmGM.IsDisposed) && lbl_TrangThai.Tag.ToString().Equals("True"))
             {
                 Program.frmGM = new Form_GoiMon("a");
             }
             Program.frmCNC.Visible = false;
             Program.frmGM.Show();
         }
         else if (chuyen == 1)
         {
             if (lbl_TrangThai.Tag.ToString().Equals("False"))
             {
                 int maBanMoi = int.Parse(lbl_TenBan.Tag + "");
                 int maBanCu  = maBan;
                 //xu li
                 tblHoaDon h = hd.getMaHDTheoBan(maBanCu);
                 hd.suaHoaDonMaBan(h.MaHD, maBanMoi);
                 b.updateTTBan(maBanCu);
                 Program.frmCNC.load2();
                 chuyen = 0;
             }
             else
             {
                 MessageBox.Show("Mời chọn 1 bàn khác");
             }
         }
         else if (chuyen == 2)
         {
             if (lbl_TrangThai.Tag.ToString().Equals("True") && maBan != int.Parse(lbl_TenBan.Tag + ""))
             {
                 int maBanMoi = int.Parse(lbl_TenBan.Tag + "");
                 int maBanCu  = maBan;
                 //xu li
                 b.gopBan(maBanCu, maBanMoi);
                 Program.frmCNC.load2();
                 chuyen = 0;
             }
             else
             {
                 MessageBox.Show("Mời chọn 1 bàn khác");
             }
         }
     }
     catch (Exception ee)
     {
     }
 }
Example #7
0
        public Form_GoiMon(String a)
        {
            InitializeComponent();
            loadUserControl();
            ca.setFlag(1);
            tblHoaDon h = hd.getMaHDTheoBan(ca.getMaBan());

            lstCT = ct.getCTByMaHD(h.MaHD).ToList <tblChiTietHD>();
            loadListOrder2();
        }
Example #8
0
 public ActionResult Edit([Bind(Include = "ma_hd,ma_nv,ma_pdp,ngay_tra_phong,ma_tinh_trang,tien_phong,tien_dich_vu,phu_thu,tong_tien")] tblHoaDon tblHoaDon)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tblHoaDon).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ma_nv         = new SelectList(db.tblNhanViens, "ma_nv", "ho_ten", tblHoaDon.ma_nv);
     ViewBag.ma_pdp        = new SelectList(db.tblPhieuDatPhongs, "ma_pdp", "ma_kh", tblHoaDon.ma_pdp);
     ViewBag.ma_tinh_trang = new SelectList(db.tblTinhTrangHoaDons, "ma_tinh_trang", "mo_ta", tblHoaDon.ma_tinh_trang);
     return(View(tblHoaDon));
 }
        public void gopBan(int maBanCu, int maBanMoi)
        {
            try
            {
                tblBan bCu  = db.tblBans.Where(t => t.MaBan == maBanCu).FirstOrDefault();
                tblBan bMoi = db.tblBans.Where(t => t.MaBan == maBanMoi).FirstOrDefault();

                tblHoaDon hCu  = hd.getMaHDTheoBan(maBanCu);
                tblHoaDon hMoi = hd.getMaHDTheoBan(maBanMoi);

                List <tblChiTietHD> lstCu  = ct.getCTByMaHD(hCu.MaHD).ToList();
                List <tblChiTietHD> lstMoi = ct.getCTByMaHD(hMoi.MaHD).ToList();
                double sum1 = (double)hCu.TongTienTT;
                double sum2 = (double)hCu.TongTienTT;
                //cap nhat cac hoa don trung nhau
                foreach (tblChiTietHD ctCu in lstCu)
                {
                    foreach (tblChiTietHD ctMoi in lstMoi)
                    {
                        if (ctCu.MaMon == ctMoi.MaMon)
                        {
                            //cap nhat sl + tong tien
                            ctCu.SoLuong  = ctCu.SoLuong + ctMoi.SoLuong;
                            ctCu.TongTien = ctCu.TongTien + ctMoi.TongTien;
                            //xoa chi tiet moi
                            ct.xoaCTHDByMa(hMoi.MaHD, ctMoi.MaMon);
                        }
                    }
                }
                //them cac hoa don moi
                foreach (tblChiTietHD ctMoi in lstMoi)
                {
                    //them
                    tblChiTietHD c = new tblChiTietHD();
                    c.MaHD     = hCu.MaHD;
                    c.MaMon    = ctMoi.MaMon;
                    c.SoLuong  = ctMoi.SoLuong;
                    c.TongTien = ctMoi.TongTien;
                    c.GiamGia  = ctMoi.GiamGia;
                    db.tblChiTietHDs.InsertOnSubmit(c);
                    //xoa
                    ct.xoaCTHDByMa(hMoi.MaHD, ctMoi.MaMon);
                }
                //update tong tien hd
                hd.suaHoaDon(hCu.MaHD, (sum1 + sum2));
                db.SubmitChanges();
            }
            catch (Exception ee)
            {
            }
        }
Example #10
0
        public ActionResult TraPhong(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblPhieuDatPhong phieudatphong = new tblPhieuDatPhong();

            phieudatphong = db.tblPhieuDatPhongs.Where(x => x.ma_phong == id && x.ma_tinh_trang == 2).SingleOrDefault();

            tblHoaDon MaHoaDon = db.tblHoaDons.Where(x => x.ma_pdp == phieudatphong.ma_pdp && x.ma_tinh_trang == 1).SingleOrDefault();

            return(RedirectToAction("ThanhToan", "HoaDon", new { id = MaHoaDon.ma_hd }));
        }
Example #11
0
        // GET: HoaDon/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblHoaDon tblHoaDon = db.tblHoaDons.Find(id);

            if (tblHoaDon == null)
            {
                return(HttpNotFound());
            }
            return(View(tblHoaDon));
        }
Example #12
0
        public ActionResult Create([Bind(Include = "ma_hd,ma_pdp,ngay_tra_phong,ma_tinh_trang")] tblHoaDon tblHoaDon)
        {
            if (ModelState.IsValid)
            {
                db.tblHoaDons.Add(tblHoaDon);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ma_nv         = new SelectList(db.tblNhanViens, "ma_nv", "ho_ten", tblHoaDon.ma_nv);
            ViewBag.ma_pdp        = new SelectList(db.tblPhieuDatPhongs, "ma_pdp", "ma_kh", tblHoaDon.ma_pdp);
            ViewBag.ma_tinh_trang = new SelectList(db.tblTinhTrangHoaDons, "ma_tinh_trang", "mo_ta", tblHoaDon.ma_tinh_trang);
            return(View(tblHoaDon));
        }
        public void loadItemFormOrder(tblHoaDon tblHD)
        {
            tblBan tblBan = new tblBan();

            List <tblHoaDon> listHD = hd.getDSHoaDonChuaThanhToan();

            //List<Grid_Item> lst = new List<Grid_Item>();
            foreach (tblHoaDon item in listHD)
            {
                tblBan = ban.getBanByID(item.MaBan);
                Grid_Item user;
                user = new Grid_Item(tblBan.KhuVuc, tblBan.TenBan, Convert.ToDouble(item.TongTienTT.ToString()), item.TGVao.ToString(), item.MaHD, item.MaBan);
                //lst.Add(user);
                flowLayoutPanel_TrangOrder.Controls.Add(user);
            }
        }
        public int suaHoaDonMaBan(int maHD, int maBan)
        {
            tblHoaDon h = new tblHoaDon();

            try
            {
                h       = db.tblHoaDons.Where(t => t.MaHD == maHD).FirstOrDefault();
                h.MaBan = maBan;

                db.SubmitChanges();
            }
            catch (Exception ee)
            {
            }
            return(h.MaHD);
        }
        public int suaHoaDon(int maHD, double tong)
        {
            tblHoaDon h = new tblHoaDon();

            try
            {
                h            = db.tblHoaDons.Where(t => t.MaHD == maHD).FirstOrDefault();
                h.TongTienTT = (Decimal)tong;

                db.SubmitChanges();
            }
            catch (Exception ee)
            {
            }
            return(h.MaHD);
        }
Example #16
0
        // Chuyển giá trị trong Textbox thành tblHoaDon
        public tblHoaDon Textbox_To_tblHoaDon()
        {
            try
            {
                tblHoaDon result = new tblHoaDon();


                result.id          = (int)this.numbid.Value;
                result.ngayTao     = this.datengayTao.Value;
                result.tenNhanVien = (this.txttenNhanVien.Text == null ? null : (string)(this.txttenNhanVien.Text));
                result.tongTien    = (int)this.numbtongTien.Value;

                return(result);
            }
            catch (Exception ex) { ShowMessage(ex.Message, false); } // Không load được hoặc xảy ra lỗi
            return(null);
        }
Example #17
0
        // GET: HoaDon/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblHoaDon tblHoaDon = db.tblHoaDons.Find(id);

            if (tblHoaDon == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ma_nv         = new SelectList(db.tblNhanViens, "ma_nv", "ho_ten", tblHoaDon.ma_nv);
            ViewBag.ma_pdp        = new SelectList(db.tblPhieuDatPhongs, "ma_pdp", "ma_kh", tblHoaDon.ma_pdp);
            ViewBag.ma_tinh_trang = new SelectList(db.tblTinhTrangHoaDons, "ma_tinh_trang", "mo_ta", tblHoaDon.ma_tinh_trang);
            return(View(tblHoaDon));
        }
        public int suaHoaDon(int maHD, DateTime tgRa, String tt)
        {
            tblHoaDon h = new tblHoaDon();

            try
            {
                h           = db.tblHoaDons.Where(t => t.MaHD == maHD).FirstOrDefault();
                h.TGRa      = tgRa;
                h.TrangThai = tt;

                db.SubmitChanges();
            }
            catch (Exception ee)
            {
            }
            return(h.MaHD);
        }
Example #19
0
        public ActionResult DoiPhong(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblHoaDon tblHoaDon = db.tblHoaDons.Find(id);

            if (tblHoaDon == null)
            {
                return(HttpNotFound());
            }
            tblPhieuDatPhong pdp = db.tblPhieuDatPhongs.Find(tblHoaDon.ma_pdp);

            var li = db.tblPhongs.Where(t => t.ma_tinh_trang == 1 && !(db.tblPhieuDatPhongs.Where(m => (m.ma_tinh_trang == 1 || m.ma_tinh_trang == 2) && m.ngay_ra > DateTime.Now && m.ngay_vao < pdp.ngay_ra)).Select(m => m.ma_phong).ToList().Contains(t.ma_phong));

            ViewBag.ma_phong_moi = new SelectList(li, "ma_phong", "so_phong");
            return(View(pdp));
        }
Example #20
0
        public ActionResult ThanhToan(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblHoaDon tblHoaDon = db.tblHoaDons.Find(id);

            if (tblHoaDon == null)
            {
                return(HttpNotFound());
            }
            var so_ngay = (tblHoaDon.tblPhieuDatPhong.ngay_ra - tblHoaDon.tblPhieuDatPhong.ngay_vao).Value.Days;
            //if (so_ngay < 1)
            //    so_ngay = 1;
            var tien_phong = so_ngay * tblHoaDon.tblPhieuDatPhong.tblPhong.tblLoaiPhong.gia;

            ViewBag.tien_phong = tien_phong;
            ViewBag.so_ngay    = so_ngay;
            ViewBag.time_now   = DateTime.Now.ToString();
            tblNhanVien nv = (tblNhanVien)Session["NV"];

            if (nv != null)
            {
                ViewBag.ho_ten = nv.ho_ten;
            }
            List <tblDichVuDaDat> dsdv = db.tblDichVuDaDats.Where(u => u.ma_hd == id).ToList();

            ViewBag.list_dv = dsdv;
            double        tongtiendv = 0;
            List <double> tt         = new List <double>();

            foreach (var item in dsdv)
            {
                double t = (double)(item.so_luong * item.tblDichVu.gia);
                tongtiendv += t;
                tt.Add(t);
            }
            ViewBag.list_tt      = tt;
            ViewBag.tien_dich_vu = tongtiendv;
            ViewBag.tong_tien    = tien_phong + tongtiendv;
            return(View(tblHoaDon));
        }
 private void Form_ThanhToan_Load(object sender, EventArgs e)
 {
     try
     {
         if (ca.getCart().Count > 0)
         {
             load1();
             //lbl_ThanhTien.Text = ca.tinhTong() + "";
             //lbl_TongThanhToan.Text = ca.tinhTong() + "";
             lbl_ThanhTien.Text     = mc.convertCurrency(ca.tinhTong()) + "";
             lbl_TongThanhToan.Text = mc.convertCurrency(ca.tinhTong()) + "";
             lbl_TenBan.Text        = "Bàn số: " + ca.getMaBan();
             lbl_ThoiGianVao.Text   = DateTime.Now + "";
         }
         else if (ca.getCart2().Count == 0)
         {
             load2();
             tblHoaDon           h     = hd.getMaHDTheoBan(ca.getMaBan());
             List <tblChiTietHD> lstCT = (List <tblChiTietHD>)ct.getCTByMaHD(h.MaHD);
             //lbl_TongThanhToan.Text = lstCT.Sum(t => t.TongTien) + "";
             lbl_ThanhTien.Text     = mc.convertCurrency((double)lstCT.Sum(t => t.TongTien)) + "";
             lbl_TongThanhToan.Text = mc.convertCurrency((double)lstCT.Sum(t => t.TongTien)) + "";
             lbl_TenBan.Text        = "Bàn số: " + ca.getMaBan();
             lbl_ThoiGianVao.Text   = h.TGVao + "";
         }
         else if (ca.getCart2().Count > 0)
         {
             load3();
             tblHoaDon           h     = hd.getMaHDTheoBan(ca.getMaBan());
             List <tblChiTietHD> lstCT = (List <tblChiTietHD>)ct.getCTByMaHD(h.MaHD);
             double sum = ca.tinhTong2();
             //lbl_ThanhTien.Text = ((double)lstCT.Sum(t => t.TongTien)+sum) + "";
             //lbl_TongThanhToan.Text = ((double)lstCT.Sum(t => t.TongTien)+sum) + "";
             lbl_ThanhTien.Text     = mc.convertCurrency((double)lstCT.Sum(t => t.TongTien) + sum) + "";
             lbl_TongThanhToan.Text = mc.convertCurrency((double)lstCT.Sum(t => t.TongTien) + sum) + "";
             lbl_TenBan.Text        = "Bàn số: " + ca.getMaBan();
             lbl_ThoiGianVao.Text   = h.TGVao + "";
         }
     }
     catch (Exception ee)
     { }
 }
Example #22
0
        public ActionResult XacNhanThanhToan(string ma_hd, string tien_phong, string tien_dich_vu, string phu_thu, string tong_tien)
        {
            if (ma_hd == null || tien_phong == null || tien_dich_vu == null || phu_thu == null || tong_tien == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            try
            {
                tblHoaDon   hd = db.tblHoaDons.Find(Int32.Parse(ma_hd));
                tblNhanVien nv = (tblNhanVien)Session["NhanVien"];
                if (nv != null)
                {
                    hd.ma_nv = nv.ma_nv;
                }

                hd.tien_phong      = Double.Parse(tien_phong);
                hd.tien_dich_vu    = Double.Parse(tien_dich_vu);
                hd.phu_thu         = Double.Parse(phu_thu);
                hd.tong_tien       = Double.Parse(tong_tien);
                hd.ma_tinh_trang   = 2;
                hd.ngay_tra_phong  = DateTime.Now;
                db.Entry(hd).State = EntityState.Modified;

                tblPhong p = db.tblPhongs.Find(hd.tblPhieuDatPhong.ma_phong);
                p.ma_tinh_trang = 3;

                tblPhieuDatPhong pd = db.tblPhieuDatPhongs.Find(hd.tblPhieuDatPhong.ma_pdp);
                pd.ma_tinh_trang = 4;

                db.Entry(p).State  = EntityState.Modified;
                db.Entry(pd).State = EntityState.Modified;
                db.SaveChanges();

                ViewBag.result = "success";
            }
            catch
            {
                ViewBag.result = "error";
            }
            ViewBag.ma_hd = ma_hd;
            return(View());
        }
Example #23
0
        public ActionResult GoiDichVu(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblPhong phong = new tblPhong();

            phong = db.tblPhongs.Find(id);

            tblPhieuDatPhong phieudatphong = new tblPhieuDatPhong();

            phieudatphong = db.tblPhieuDatPhongs.Where(x => x.ma_phong == phong.ma_phong && x.ma_tinh_trang == 2 && phong.ma_tinh_trang == 2).FirstOrDefault();

            tblHoaDon hoadon = new tblHoaDon();

            hoadon = db.tblHoaDons.Where(x => x.ma_pdp == phieudatphong.ma_pdp && phieudatphong.ma_tinh_trang == 2 && x.ma_tinh_trang == 1).SingleOrDefault();

            //int ma_hd = db.tblHoaDons.Where(x => x.ma_phong == id && u.ma_tinh_trang == 2).First().ma_hd;
            return(RedirectToAction("GoiDichVu", "HoaDon", new { id = hoadon.ma_hd }));
        }
        public int LuuHoaDon2(DateTime dt, int maB, int MaNV, String pt, double tong, String tt)
        {
            tblHoaDon h = new tblHoaDon();

            try
            {
                h.TGVao        = dt;
                h.TGRa         = dt;
                h.MaBan        = maB;
                h.MaNV         = 2;
                h.PhuongThucTT = "Cash";
                h.TongTienTT   = (Decimal)tong;
                h.TrangThai    = "Roi";
                db.tblHoaDons.InsertOnSubmit(h);
                db.SubmitChanges();
            }
            catch (Exception ee)
            {
            }
            return(h.MaHD);
        }
Example #25
0
 public ActionResult Result(String ma_tgd)
 {
     if (ma_tgd == null)
     {
         return(RedirectToAction("Index", "Admin"));
     }
     else
     {
         tblHoaDon hd = new tblHoaDon();
         hd.ma_tgd        = Int32.Parse(ma_tgd);
         hd.ma_tinh_trang = 1;
         try
         {
             db.tblHoaDons.Add(hd);
             tblPhieuDatPhong tgd = db.tblPhieuDatPhongs.Find(Int32.Parse(ma_tgd));
             if (tgd == null)
             {
                 return(HttpNotFound());
             }
             tblPhong p = db.tblPhongs.Find(tgd.ma_phong);
             if (p == null)
             {
                 return(HttpNotFound());
             }
             tgd.ma_tinh_trang   = 2;
             db.Entry(tgd).State = EntityState.Modified;
             p.ma_tinh_trang     = 2;
             db.Entry(p).State   = EntityState.Modified;
             ViewBag.ngay_ra     = tgd.ngay_ra;
             db.SaveChanges();
             ViewBag.Result = "success";
         }
         catch
         {
             ViewBag.Result = "error";
         }
     }
     return(View());
 }
Example #26
0
        // Chuyển giá trị trong DataGridView thành tblHoaDon
        public tblHoaDon DataGridView_To_tblHoaDon(int index)
        {
            try
            {
                tblHoaDon result = new tblHoaDon();


                var id = this.dgvData.Rows[index].Cells["id"].Value;
                if (id != null)
                {
                    result.id = int.Parse(id.ToString());
                }

                var ngayTao = this.dgvData.Rows[index].Cells["ngayTao"].Value;
                if (ngayTao != null)
                {
                    result.ngayTao = (ngayTao == null ? null : (DateTime?)DateTime.Parse(ngayTao.ToString()));
                }

                var tenNhanVien = this.dgvData.Rows[index].Cells["tenNhanVien"].Value;
                if (tenNhanVien != null)
                {
                    result.tenNhanVien = (tenNhanVien == null ? null : (string)(tenNhanVien));
                }

                var tongTien = this.dgvData.Rows[index].Cells["tongTien"].Value;
                if (tongTien != null)
                {
                    result.tongTien = (tongTien == null ? null : (int?)int.Parse(tongTien.ToString()));
                }

                return(result);
            }
            catch (Exception ex) { ShowMessage(ex.Message, false); } // Không load được hoặc xảy ra lỗi
            return(null);
        }
Example #27
0
        public ActionResult ChiTietHoaDon(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblHoaDon tblHoaDon = db.tblHoaDons.Find(id);

            if (tblHoaDon == null)
            {
                return(HttpNotFound());
            }

            var tien_phong = (tblHoaDon.tblPhieuDatPhong.ngay_ra - tblHoaDon.tblPhieuDatPhong.ngay_vao).Value.TotalDays * tblHoaDon.tblPhieuDatPhong.tblPhong.tblLoaiPhong.gia;

            ViewBag.tien_phong = tien_phong;

            ViewBag.time_now = DateTime.Now.ToString();

            List <tblDichVuDaDat> dsdv = db.tblDichVuDaDats.Where(u => u.ma_hd == id).ToList();

            ViewBag.list_dv = dsdv;
            double        tongtiendv = 0;
            List <double> tt         = new List <double>();

            foreach (var item in dsdv)
            {
                double t = (double)(item.so_luong * item.tblDichVu.gia);
                tongtiendv += t;
                tt.Add(t);
            }
            ViewBag.list_tt      = tt;
            ViewBag.tien_dich_vu = tongtiendv;
            ViewBag.tong_tien    = tien_phong + tongtiendv;
            return(View(tblHoaDon));
        }
Example #28
0
        public ActionResult ThanhToan(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblHoaDon tblHoaDon = db.tblHoaDons.Find(id);

            if (tblHoaDon == null)
            {
                return(HttpNotFound());
            }
            DateTime ngay_ra      = DateTime.Now;
            DateTime ngay_vao     = (DateTime)tblHoaDon.tblPhieuDatPhong.ngay_vao;
            DateTime ngay_du_kien = (DateTime)tblHoaDon.tblPhieuDatPhong.ngay_ra;

            DateTime dateS = new DateTime(ngay_vao.Year, ngay_vao.Month, ngay_vao.Day, 12, 0, 0);
            DateTime dateE = new DateTime(ngay_ra.Year, ngay_ra.Month, ngay_ra.Day, 12, 0, 0);

            Double gia = (Double)tblHoaDon.tblPhieuDatPhong.tblPhong.tblLoaiPhong.gia;

            var songay = (dateE - dateS).TotalDays;

            if (dateS > ngay_vao)
            {
                songay++;
            }
            if (ngay_ra > dateE)
            {
                songay++;
            }
            var ti_le_phu_thu   = tblHoaDon.tblPhieuDatPhong.tblPhong.tblLoaiPhong.ti_le_phu_thu;
            var so_ngay_phu_thu = Math.Abs(Math.Ceiling((ngay_ra - ngay_du_kien).TotalDays));

            System.Diagnostics.Debug.WriteLine("So ngay: " + so_ngay_phu_thu);
            System.Diagnostics.Debug.WriteLine("Gia: " + gia);
            System.Diagnostics.Debug.WriteLine("Ti le: :" + ti_le_phu_thu);

            var phuthu = so_ngay_phu_thu * gia * ti_le_phu_thu / 100;

            ViewBag.phu_thu = phuthu;

            System.Diagnostics.Debug.WriteLine("Phu thu:" + phuthu);

            ViewBag.so_ngay_phu_thu = so_ngay_phu_thu;
            var tien_phong = songay * gia;

            ViewBag.tien_phong = tien_phong;
            ViewBag.so_ngay    = songay;

            tblNhanVien nv = (tblNhanVien)Session["NV"];

            if (nv != null)
            {
                ViewBag.ho_ten = nv.ho_ten;
            }
            List <tblDichVuDaDat> dsdv = db.tblDichVuDaDats.Where(u => u.ma_hd == id).ToList();

            ViewBag.list_dv = dsdv;
            double        tongtiendv = 0;
            List <double> tt         = new List <double>();

            foreach (var item in dsdv)
            {
                double t = (double)(item.so_luong * item.tblDichVu.gia);
                tongtiendv += t;
                tt.Add(t);
            }
            ViewBag.list_tt      = tt;
            ViewBag.tien_dich_vu = tongtiendv;
            ViewBag.tong_tien    = tien_phong + tongtiendv + phuthu;
            return(View(tblHoaDon));
        }
Example #29
0
        public ActionResult XacNhanThanhToan(FormCollection c)
        {
            if (Session["dangnhap"] == null)
            {
                ViewBag.TB = "Ban chua dang nhap";
                return(RedirectToAction("DangNhap", "KhachHang"));
            }
            try
            {
                tblKhachHang kh = Session["dangnhap"] as tblKhachHang;
                //  tblKhachHang kh = db.tblKhachHangs.FirstOrDefault();
                String      pt  = c["PTThanhToan"].ToString();
                String      tg  = c["DonViVC"].ToString();
                String      dc  = c["DiaChiNhan"].ToString();
                List <item> lst = layGioHang();
                tblHoaDon   hd  = new tblHoaDon();
                DateTime    now = DateTime.Now;
                hd.NgayHD   = DateTime.Parse(now.ToShortDateString());
                hd.MaNV     = 1;
                hd.TongTien = (decimal)tongTien();
                db.tblHoaDon.Add(hd);
                db.SaveChanges();

                tblThanhToan thanhtoan = new tblThanhToan();
                thanhtoan.MaHD            = hd.MaHD;
                thanhtoan.MaKH            = kh.MaKH;
                thanhtoan.SoTienThanhToan = (decimal)tongTien();
                thanhtoan.NgayThanhToan   = hd.NgayHD;
                if (pt == "0")
                {
                    thanhtoan.PhuongThucThanhToan = "Thanh toán khi nhận hàng";
                }
                else
                {
                    thanhtoan.PhuongThucThanhToan = "Thanh toán ngay";
                }
                tblGiaoHang giaohang = new tblGiaoHang();
                giaohang.MaHD             = hd.MaHD;
                giaohang.TenNguoiNhan     = kh.TenKH;
                giaohang.DiaChi1          = dc;
                giaohang.DiaChi2          = dc;
                giaohang.DiaChi3          = dc;
                giaohang.MaDonViVanChuyen = tg;
                giaohang.SoDT1            = kh.DienThoai;
                giaohang.Email            = kh.Email;
                //   add data into database
                db.tblThanhToan.Add(thanhtoan);
                db.tblGiaoHang.Add(giaohang);
                db.SaveChanges();
                foreach (var sp in lst)
                {
                    if (ktSL(sp.maTB, sp.sl, sp.cauHinh))
                    {
                        tblChiTietHD ct = new tblChiTietHD();
                        ct.MaHD      = hd.MaHD;
                        ct.MaTB      = sp.maTB;
                        ct.MaCauHinh = sp.cauHinh;
                        ct.SoLuong   = sp.sl;
                        ct.ThanhTien = (decimal)sp.thanhTien;
                        db.tblChiTietHD.Add(ct);
                        db.SaveChanges();
                    }
                    else
                    {
                        ViewBag.TB = "Failed";
                        return(RedirectToAction("ThanhToan", "ThanhToan"));
                    }
                }
                lst.Clear();
                return(RedirectToAction("HoanTat", "ThanhToan"));
            }
            catch
            {
                TempData["Message"] = "Error !!";
                return(RedirectToAction("ThanhToan", "ThanhToan"));
            }
        }
Example #30
0
        private void simpleButton5_Click(object sender, EventArgs e)
        {
            try
            {
                if (ca.getFlag() == 0)
                {
                    if (ca.getCart().Count != 0)
                    {
                        DateTime    dt      = DateTime.Now;
                        int         maB     = ca.getMaBan();
                        int         maNV    = ca.getMaNV();
                        String      PT      = "Cash";
                        double      tong    = ca.tinhTong();
                        String      TT      = "Chua";
                        int         x       = hd.LuuHoaDon(dt, maB, maNV, PT, tong, TT);
                        List <Item> lstCart = ca.getCart();

                        foreach (Item i in lstCart)
                        {
                            int    maHD  = x;
                            int    maMon = i.maMon;
                            int    sl    = i.sl;
                            double tong2 = i.tongTien;
                            ct.LuuChiTietHD(maHD, maMon, sl, tong2);
                        }

                        ca.clearCard2();
                        ca.clearCard();
                        this.Dispose();
                        if (Program.frmCNC.Visible == false)
                        {
                            Program.frmCNC = new Form_ChucNangChinh();
                        }
                        Program.frmCNC.Show();
                    }
                    else
                    {
                        MessageBox.Show("Moi Chon San Pham");
                    }
                }
                else
                {
                    ////xoa het ct cu
                    //tblHoaDon h = hd.getMaHDTheoBan(ca.getMaBan());
                    //List<tblChiTietHD> lstCT = ct.getCTByMaHD(h.MaHD).ToList<tblChiTietHD>();
                    //foreach (tblChiTietHD t in lstCT)
                    //{
                    //    ct.xoaCTHDByMa(t.MaHD,t.MaMon);
                    //}
                    ////them chi tiet moi
                    //DateTime dt = DateTime.Today;
                    //int maB = ca.getMaBan();
                    //int maNV = 2;
                    //String PT = "Cash";
                    //double tong = ca.tinhTong();
                    //String TT = "Chua";
                    //int x = hd.LuuHoaDon(dt, maB, maNV, PT, tong, TT);
                    //List<Item> lstCart = ca.getCart2();

                    //foreach (Item i in lstCart)
                    //{
                    //    int maHD = x;
                    //    int maMon = i.maMon;
                    //    int sl = i.sl;
                    //    double tong2 = i.tongTien;
                    //    ct.LuuChiTietHD(maHD, maMon, sl, tong2);
                    //}

                    //update lai cac mon an da co;
                    if (ca.getCart2().Count != 0)
                    {
                        tblHoaDon h = hd.getMaHDTheoBan(ca.getMaBan());

                        List <tblChiTietHD> lstCT = ct.getCTByMaHD(h.MaHD).ToList <tblChiTietHD>();

                        List <Item> lstCart = ca.getCart2();
                        double      tong1   = ca.tinhTong2();
                        //update lai chi tiet
                        for (int i = 0; i < lstCT.Count; i++)
                        {
                            for (int j = 0; j < lstCart.Count; j++)
                            {
                                if (lstCT[i].MaMon == lstCart[j].maMon)
                                {
                                    ct.suaChiTietHD(lstCT[i].MaHD, lstCT[i].MaMon, (lstCart[j].sl + lstCT[i].SoLuong), (lstCart[j].tongTien + (double)lstCT[i].TongTien));
                                    lstCart.Remove(lstCart[j]);
                                    j--;
                                }
                            }
                        }
                        //them cac chi tiet moi
                        foreach (Item i in lstCart)
                        {
                            int    maHD  = h.MaHD;
                            int    maMon = i.maMon;
                            int    sl    = i.sl;
                            double tong  = i.tongTien;
                            ct.LuuChiTietHD(maHD, maMon, sl, tong);
                        }
                        //update lai tong tien cho hoa don
                        hd.suaHoaDon(h.MaHD, (tong1 + (double)h.TongTienTT));

                        ca.clearCard2();
                        ca.clearCard();
                        this.Dispose();
                        if (Program.frmCNC.Visible == false)
                        {
                            Program.frmCNC = new Form_ChucNangChinh();
                        }
                        Program.frmCNC.Show();
                    }
                    else
                    {
                        MessageBox.Show("Moi Chon San Pham");
                    }
                }
            }
            catch (Exception eee)
            { }
        }