Exemple #1
0
        public ChiTietPhieuNhap getByID(int MaPhieuNhap, int MaSach)
        {
            String query = "select MaPhieuNhap,MaSach,SoLuongNhap from ChiTietPhieuNhap where MaPhieuNhap=@MaPhieuNhap and MaSach=@MaSach";
            List <SqlParameter> sqlParameters = new List <SqlParameter>();

            SqlParameter param_MaPhieuNhap = new SqlParameter("MaPhieuNhap", MaPhieuNhap);

            SqlParameter param_MaSach = new SqlParameter("MaSach", MaSach);

            sqlParameters.Add(param_MaPhieuNhap);
            sqlParameters.Add(param_MaSach);

            DataTable dt = this.dp.ExecuteQuery(query, sqlParameters);

            if (dt.Rows.Count == 0)
            {
                return(null);
            }
            else
            {
                ChiTietPhieuNhap chiTietPhieuNhap = new ChiTietPhieuNhap();
                chiTietPhieuNhap.MaPhieuNhap = (int)dt.Rows[0]["MaPhieuNhap"];
                chiTietPhieuNhap.MaSach      = (int)dt.Rows[0]["MaSach"];
                chiTietPhieuNhap.SoLuongNhap = (int)dt.Rows[0]["SoLuongNhap"];


                return(chiTietPhieuNhap);
            }
        }
Exemple #2
0
        public Boolean delete(ChiTietPhieuNhap chiTietPhieuNhap)
        {
            String query = "delete from ChiTietPhieuNhap where MaPhieuNhap = @MaPhieuNhap";
            List <SqlParameter> sqlParameters = new List <SqlParameter>();
            SqlParameter        parameter     = new SqlParameter("MaPhieuNhap", chiTietPhieuNhap.MaPhieuNhap);

            sqlParameters.Add(parameter);
            return(this.dp.ExecuteNonQuery(query, sqlParameters));
        }
Exemple #3
0
        public int LuuBangChiTietPhieuNhap(ChiTietPhieuNhap ct_phieunhap)
        {
            String sql = String.Format("insert into chitietphieunhap(maphieunhap,mahang,soluong,gianhap) " +
                                       "values({0},{1},{2},{3})",
                                       ct_phieunhap.MaPhieuNhap, ct_phieunhap.MaHang, ct_phieunhap.SoLuong, ct_phieunhap.GiaNhap);
            int effect = dataProvider.ExecuteNonQuery(sql);

            return(effect);
        }
Exemple #4
0
        public Boolean update(ChiTietPhieuNhap chiTietPhieuNhap)
        {
            String query = "update ChiTietPhieuNhap set MaSach = @MaSach, SoLuongNhap = @SoLuongNhap where MaPhieuNhap = @MaPhieuNhap";
            List <SqlParameter> sqlParameters = new List <SqlParameter>();

            SqlParameter param_MaSach      = new SqlParameter("MaSach", chiTietPhieuNhap.MaSach);
            SqlParameter param_SoLuongNhap = new SqlParameter("SoLuongNhap", chiTietPhieuNhap.SoLuongNhap);
            SqlParameter param_MaPhieuNhap = new SqlParameter("MaPhieuNhap", chiTietPhieuNhap.MaPhieuNhap);

            sqlParameters.Add(param_MaSach);
            sqlParameters.Add(param_SoLuongNhap);
            sqlParameters.Add(param_MaPhieuNhap);
            return(this.dp.ExecuteNonQuery(query, sqlParameters));
        }
Exemple #5
0
        public Boolean insert(ChiTietPhieuNhap chiTietPhieuNhap)
        {
            String query = "insert ChiTietPhieuNhap(MaPhieuNhap,MaSach,SoLuongNhap) values(@MaPhieuNhap, @MaSach, @SoLuongNhap)";
            List <SqlParameter> sqlParameters = new List <SqlParameter>();

            SqlParameter param_MaPhieuNhap = new SqlParameter("MaPhieuNhap", chiTietPhieuNhap.MaPhieuNhap);
            SqlParameter param_MaSach      = new SqlParameter("MaSach", chiTietPhieuNhap.MaSach);
            SqlParameter param_SoLuongNhap = new SqlParameter("SoLuongNhap", chiTietPhieuNhap.SoLuongNhap);

            sqlParameters.Add(param_MaPhieuNhap);
            sqlParameters.Add(param_MaSach);
            sqlParameters.Add(param_SoLuongNhap);

            return(this.dp.ExecuteNonQuery(query, sqlParameters));
        }
Exemple #6
0
        public void EditCTKho(ChiTietPhieuNhap ctpn)
        {
            var model = (from c in db.ChiTietPhieuNhaps
                         where c.ID == ctpn.ID
                         select c).FirstOrDefault();

            var thanhtien_cu = model.ThanhTien;
            var soluong_cu   = model.SoLuongNhap;

            model.MaSanPham   = ctpn.MaSanPham;
            model.DonGiaNhap  = ctpn.DonGiaNhap;
            model.SoLuongNhap = ctpn.SoLuongNhap;
            model.Thue        = ctpn.Thue;
            model.ThanhTien   = ctpn.ThanhTien;

            //tự động cập nhật Tổng tiền phiếu nhập
            if (model.ThanhTien > thanhtien_cu)
            {
                var model1 = db.PhieuNhaps.Find(model.MaPhieuNhap);
                model1.TongDonGia += (model.ThanhTien - thanhtien_cu);
            }
            else
            {
                if (model.ThanhTien < thanhtien_cu)
                {
                    var model1 = db.PhieuNhaps.Find(model.MaPhieuNhap);
                    model1.TongDonGia -= (thanhtien_cu - model.ThanhTien);
                }
            }

            //tự động cập nhật số lượng Xe
            if (model.SoLuongNhap > soluong_cu)
            {
                var model1 = db.Xes.Find(model.MaSanPham);
                model1.SoLuong += (model.SoLuongNhap - soluong_cu);
            }
            else
            {
                if (model.SoLuongNhap < soluong_cu)
                {
                    var model1 = db.Xes.Find(model.MaSanPham);
                    model1.SoLuong -= (soluong_cu - model.SoLuongNhap);
                }
            }

            db.Entry(model).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
        }
Exemple #7
0
        public List <ChiTietPhieuNhap> getAllReturnList()
        {
            String    query = "select MaPhieuNhap,MaSach,SoLuongNhap from ChiTietPhieuNhap";
            DataTable dt    = this.dp.ExecuteQuery(query);

            List <ChiTietPhieuNhap> lstChiTietPhieuNhap = new List <ChiTietPhieuNhap>();

            foreach (DataRow dr in dt.Rows)
            {
                ChiTietPhieuNhap chiTietPhieuNhap = new ChiTietPhieuNhap();
                chiTietPhieuNhap.MaPhieuNhap = (int)dr["MaPhieuNhap"];
                chiTietPhieuNhap.MaSach      = (int)dr["MaSach"];

                chiTietPhieuNhap.SoLuongNhap = (int)dr["SoLuongNhap"];

                lstChiTietPhieuNhap.Add(chiTietPhieuNhap);
            }
            return(lstChiTietPhieuNhap);
        }
Exemple #8
0
        public static List <ChiTietPhieuNhap> LoadCTKho(int id)
        {
            QLCHXeEntity db     = new QLCHXeEntity();
            var          result = (
                from c in db.ChiTietPhieuNhaps
                join x in db.Xes on c.MaSanPham equals x.MaXe
                where c.MaPhieuNhap == id
                select new
            {
                ID = c.ID,
                MaPhieuNhap = c.MaPhieuNhap,
                MaSanPham = c.MaSanPham,
                DonGiaNhap = c.DonGiaNhap,
                SoLuongNhap = c.SoLuongNhap,
                Thue = c.Thue,
                ThanhTien = c.ThanhTien,
                TenXe = x.TenXe
            }
                ).ToList();
            List <ChiTietPhieuNhap> listReturn = new List <ChiTietPhieuNhap>();

            foreach (var item in result)
            {
                ChiTietPhieuNhap ctphieunhap_list = new ChiTietPhieuNhap();

                Xe x = new Xe();
                x.TenXe             = item.TenXe;
                ctphieunhap_list.Xe = x;

                ctphieunhap_list.ID          = item.ID;
                ctphieunhap_list.MaPhieuNhap = item.MaPhieuNhap;
                ctphieunhap_list.MaSanPham   = item.MaSanPham;
                ctphieunhap_list.DonGiaNhap  = item.DonGiaNhap;
                ctphieunhap_list.SoLuongNhap = item.SoLuongNhap;
                ctphieunhap_list.Thue        = item.Thue;
                ctphieunhap_list.ThanhTien   = item.ThanhTien;

                listReturn.Add(ctphieunhap_list);
            }

            return(listReturn);
        }
Exemple #9
0
        public List <ChiTietPhieuNhap> getByMaPhieuNhap(int MaPhieuNhap)
        {
            String query = "select MaPhieuNhap,MaSach,SoLuongNhap from ChiTietPhieuNhap where MaPhieuNhap=@MaPhieuNhap";
            List <SqlParameter> sqlParameters = new List <SqlParameter>();
            SqlParameter        param         = new SqlParameter("MaPhieuNhap", MaPhieuNhap);

            sqlParameters.Add(param);
            DataTable dt = this.dp.ExecuteQuery(query, sqlParameters);
            List <ChiTietPhieuNhap> lstChiTietPhieuNhap = new List <ChiTietPhieuNhap>();

            foreach (DataRow dr in dt.Rows)
            {
                ChiTietPhieuNhap chiTietPhieuNhap = new ChiTietPhieuNhap();
                chiTietPhieuNhap.MaPhieuNhap = (int)dr["MaPhieuNhap"];
                chiTietPhieuNhap.MaSach      = (int)dr["MaSach"];
                chiTietPhieuNhap.SoLuongNhap = (int)dr["SoLuongNhap"];
                lstChiTietPhieuNhap.Add(chiTietPhieuNhap);
            }
            return(lstChiTietPhieuNhap);
        }
Exemple #10
0
 public void AddCTKho(ChiTietPhieuNhap ctpn)
 {
     db.ChiTietPhieuNhaps.Add(ctpn);
     db.SaveChanges();
 }