Beispiel #1
0
 public bool XoaTU(int maTU)
 {
     try
     {
         THUC_UONG tuDB = db.THUC_UONG.SingleOrDefault(p => p.MATU == maTU && p.TRANGTHAIXOA == false);
         tuDB.TRANGTHAIXOA = true;
         db.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Beispiel #2
0
 public bool SuaTU(ThucUongDTO tu)
 {
     try
     {
         THUC_UONG tuDB = db.THUC_UONG.SingleOrDefault(p => p.MATU == tu.Matu && p.TRANGTHAIXOA == false);
         tuDB.TENTU    = tu.Tentu;
         tuDB.MALOAITU = tu.Maloaitu;
         tu.Gia        = tu.Gia;
         db.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Beispiel #3
0
 public bool ThemTU(ThucUongDTO tu)
 {
     try
     {
         THUC_UONG tuDB = new THUC_UONG
         {
             TENTU    = tu.Tentu,
             MALOAITU = tu.Maloaitu,
             GIA      = tu.Gia
         };
         db.THUC_UONG.Add(tuDB);
         db.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Beispiel #4
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);
        }