Beispiel #1
0
        public bool ThanhToan(BanDTO ban, double tongTien, HoaDonTamDTO hdtam, int Manvlap)
        {
            bool flag;

            try
            {
                //HOA_DON hd = db.HOA_DON.Where(u => u.SOBAN == ban.Soban && u.TRANGTHAI == 0).SingleOrDefault();
                //hd.TONGTIEN = tongTien;
                //hd.TRANGTHAI = 1;
                //db.SaveChanges();
                //BAN bandb = db.BANs.Where(u => u.SOBAN == ban.Soban).SingleOrDefault();
                //bandb.TRANGTHAI = 1;
                //db.SaveChanges();

                HOA_DON hd = new HOA_DON
                {
                    SOBAN    = hdtam.MaBan,
                    NGAYLAP  = DateTime.Now,
                    MANVLAP  = Manvlap,
                    TONGTIEN = tongTien
                };

                db.HOA_DON.Add(hd);
                db.SaveChanges();

                foreach (ThucUongDTO tu in hdtam.ListTUTam)
                {
                    CHI_TIET_HOA_DON cthd = new CHI_TIET_HOA_DON
                    {
                        MAHD   = hd.MAHD,
                        MATU   = tu.Matu,
                        SL     = tu.Soluong,
                        GIABAN = tu.Gia
                    };
                    db.CHI_TIET_HOA_DON.Add(cthd);
                    db.SaveChanges();
                }

                flag = true;
            }
            catch (Exception e)
            {
                flag = false;
            }
            return(flag);
        }
Beispiel #2
0
        public bool ThemThucUongTheoBan(BanDTO ban, int MaNVLap, string TenTU, string LoaiTU, int SoLg)
        {
            bool flag;

            try
            {
                //Lay Thong Tin Thuc Uong Theo TenTu Va Loai Tu
                THUC_UONG MonAn = new THUC_UONG();
                MonAn = db.THUC_UONG.Where(u => u.TENTU == TenTU && u.LOAI_THUC_UONG.TENLOAITU == LoaiTU).SingleOrDefault();

                //Lap Hoa Don
                if (ban.Trangthai == 1)
                {
                    BAN bandb = new BAN();
                    bandb           = db.BANs.Where(u => u.SOBAN == ban.Soban).SingleOrDefault();
                    bandb.TRANGTHAI = 2;
                    db.SaveChanges();
                    HOA_DON hdAdd = new HOA_DON
                    {
                        SOBAN     = ban.Soban,
                        NGAYLAP   = DateTime.Now,
                        TRANGTHAI = 0,
                        MANVLAP   = MaNVLap
                    };
                    db.HOA_DON.Add(hdAdd);
                    db.SaveChanges();
                    CHI_TIET_HOA_DON cthdAdd = new CHI_TIET_HOA_DON
                    {
                        MAHD   = hdAdd.MAHD,
                        MATU   = MonAn.MATU,
                        SL     = SoLg,
                        GIABAN = MonAn.GIA
                    };
                    db.CHI_TIET_HOA_DON.Add(cthdAdd);
                    db.SaveChanges();
                }
                else
                {
                    HoaDonDTO mahd = db.HOA_DON.Where(u => u.SOBAN == ban.Soban && u.TRANGTHAI == 0).Select(v => new HoaDonDTO {
                        Mahd = v.MAHD, Soban = v.SOBAN
                    }).SingleOrDefault();
                    CHI_TIET_HOA_DON ctHoaDon = new CHI_TIET_HOA_DON();
                    if (db.CHI_TIET_HOA_DON.Where(u => u.MATU == MonAn.MATU && u.MAHD == mahd.Mahd && mahd.Soban == ban.Soban).SingleOrDefault() != null)
                    {
                        ctHoaDon     = db.CHI_TIET_HOA_DON.Where(u => u.MATU == MonAn.MATU && u.MAHD == mahd.Mahd && mahd.Soban == ban.Soban).SingleOrDefault();
                        ctHoaDon.SL += SoLg;
                    }
                    else
                    {
                        ctHoaDon.MAHD   = mahd.Mahd;
                        ctHoaDon.MATU   = MonAn.MATU;
                        ctHoaDon.SL     = SoLg;
                        ctHoaDon.GIABAN = MonAn.GIA;
                        db.CHI_TIET_HOA_DON.Add(ctHoaDon);
                    }
                    db.SaveChanges();
                }
                flag = true;
            }
            catch (Exception e)
            {
                flag = false;
            }
            return(flag);
        }