Esempio n. 1
0
        public static bool CapNhatChiTietHD(int id1, string id2, CHITIETHOADONBANHANG ctNew, ref decimal deltaTT)
        {
            QLCuaHangDDSDataContext db = new QLCuaHangDDSDataContext();
            var ct = db.CHITIETHOADONBANHANGs.Single(p => p.MaHD == id1 && p.TenMH == id2);

            ct.SoLuong = ctNew.SoLuong;

            decimal originTT = ct.ThanhTien.Value;

            ct.GiamGiaTrenMatHang = ctNew.GiamGiaTrenMatHang;
            ct.ThanhTien          = ct.DonGia.Value * (1 - (decimal)ct.GiamGiaTrenMatHang.Value) * ct.SoLuong;

            ct.GiamGiaTrenThanhTien = ctNew.GiamGiaTrenThanhTien;
            ct.ThanhTien            = ct.ThanhTien * (1 - (decimal)ct.GiamGiaTrenThanhTien.Value);

            try
            {
                db.SubmitChanges();
                decimal delta = ct.ThanhTien.Value - originTT;
                HoaDonBanHangDAO.CapNhatTongTienHD(ct.MaHD, delta, ref deltaTT);
                XtraMessageBox.Show("Cập nhật thành công!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return(true);
            }
            catch (Exception e)
            {
                XtraMessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
Esempio n. 2
0
        public static bool ThemChiTietHD(CHITIETHOADONBANHANG ct, ref decimal result)
        {
            QLCuaHangDDSDataContext db = new QLCuaHangDDSDataContext();

            db.CHITIETHOADONBANHANGs.InsertOnSubmit(ct);

            try
            {
                db.SubmitChanges();
                HoaDonBanHangDAO.CapNhatTongTienHD(ct.MaHD, ct.ThanhTien.Value, ref result);
                XtraMessageBox.Show("Thêm thành công!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return(true);
            }
            catch (Exception e)
            {
                XtraMessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
Esempio n. 3
0
        public static bool XoaChiTietHD(int id1, string id2, ref decimal result)
        {
            QLCuaHangDDSDataContext db = new QLCuaHangDDSDataContext();
            var ct = db.CHITIETHOADONBANHANGs.Single(p => p.MaHD == id1 && p.TenMH == id2);

            db.CHITIETHOADONBANHANGs.DeleteOnSubmit(ct);

            try
            {
                db.SubmitChanges();
                HoaDonBanHangDAO.CapNhatTongTienHD(ct.MaHD, -ct.ThanhTien.Value, ref result);
                XtraMessageBox.Show("Xóa thành công!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return(true);
            }
            catch (Exception e)
            {
                XtraMessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }