public bool ThemDonHang(DonHang donHang)
        {
            SqlDataSource sqldata     = new SqlDataSource();
            KetNoiCSDL    chuoiketnoi = new KetNoiCSDL();

            sqldata.ConnectionString  = chuoiketnoi.GetSetChuoiKetNoi;
            sqldata.InsertCommandType = SqlDataSourceCommandType.StoredProcedure;
            sqldata.InsertCommand     = "DonHang_Insert";
            sqldata.InsertParameters.Add("NgayMua", donHang.ngayMua.ToString());
            sqldata.InsertParameters.Add("HoTen", donHang.HoTen.ToString());
            sqldata.InsertParameters.Add("SDT", donHang.SDT.ToString());
            sqldata.InsertParameters.Add("Email", donHang.Email.ToString());
            sqldata.InsertParameters.Add("DiaChi", donHang.diaChi.ToString());
            sqldata.InsertParameters.Add("Note", donHang.Note.ToString());

            try
            {
                sqldata.Insert();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public bool ThemSP(sanpham sp)
        {
            SqlDataSource sqldata     = new SqlDataSource();
            KetNoiCSDL    chuoiketnoi = new KetNoiCSDL();

            sqldata.ConnectionString  = chuoiketnoi.GetSetChuoiKetNoi;
            sqldata.InsertCommandType = SqlDataSourceCommandType.StoredProcedure;
            sqldata.InsertCommand     = "SanPham_Insert";
            sqldata.InsertParameters.Add("TenSanPham", sp.TenSP.ToString());
            sqldata.InsertParameters.Add("MoTa", sp.MoTa.ToString());
            sqldata.InsertParameters.Add("HinhAnh", sp.HinhAnh.ToString());
            sqldata.InsertParameters.Add("Gia", sp.GiaBan.ToString());
            sqldata.InsertParameters.Add("SLCon", sp.SLCon.ToString());
            sqldata.InsertParameters.Add("MaDanhMuc", sp.MaDanhMuc.ToString());
            sqldata.InsertParameters.Add("NgayBan", sp.ngayBan.ToString());
            try
            {
                sqldata.Insert();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public bool SuaSP(sanpham sanpham)
        {
            SqlDataSource sqldata     = new SqlDataSource();
            KetNoiCSDL    chuoiketnoi = new KetNoiCSDL();

            sqldata.ConnectionString  = chuoiketnoi.GetSetChuoiKetNoi;
            sqldata.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure;
            sqldata.UpdateCommand     = "SanPham_Update";
            sqldata.UpdateParameters.Add("MaSP", sanpham.MaSP.ToString());
            sqldata.UpdateParameters.Add("MaDanhMuc", sanpham.MaDanhMuc.ToString());
            sqldata.UpdateParameters.Add("MoTa", sanpham.MoTa.ToString());
            sqldata.UpdateParameters.Add("HinhAnh", sanpham.HinhAnh.ToString());
            sqldata.UpdateParameters.Add("Gia", sanpham.GiaBan.ToString());
            sqldata.UpdateParameters.Add("SLCon", sanpham.SLCon.ToString());
            sqldata.UpdateParameters.Add("TenSanPham", sanpham.TenSP.ToString());
            try
            {
                sqldata.Update();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public void LoadDuLieu()
        {
            KetNoiCSDL ketNoi = new KetNoiCSDL();
            DataTable  dt     = ketNoi.ThucThiLenhTraVeBang("Select MaSanPham,TenSanPham,HinhAnh,SUBSTRING(MoTa, 0, 56)+'...' as MoTa,Gia, SLCon,SLBan,NgayBan from SanPham where MaDanhMuc=" + Request.QueryString["id"].ToString());

            dataSanPham.DataSource = dt;
            dataSanPham.DataBind();
        }
Beispiel #5
0
        protected void btnTim_Click(object sender, EventArgs e)
        {
            string     sql    = "Select MaSanPham,TenSanPham,HinhAnh,SUBSTRING(MoTa, 0, 56)+'...' as MoTa,Gia, SLCon,SLBan,NgayBan from SanPham where TenSanPham like '%" + txtTuKhoa.Text + "%'";
            KetNoiCSDL ketNoi = new KetNoiCSDL();
            DataTable  dt     = ketNoi.ThucThiLenhTraVeBang(sql);

            dataSanPham.DataSource = dt;
            dataSanPham.DataBind();
        }
        public SqlDataSource Laydulieu(string procedue)
        {
            SqlDataSource sqldata     = new SqlDataSource();
            KetNoiCSDL    chuoiketnoi = new KetNoiCSDL();

            sqldata.ConnectionString  = chuoiketnoi.GetSetChuoiKetNoi;
            sqldata.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
            sqldata.SelectCommand     = procedue;
            return(sqldata);
        }
        public SqlDataSource LaydulieubyID(string GiaTriParaMetter, string TenThuTuc, string TenParametter)
        {
            SqlDataSource sqldata     = new SqlDataSource();
            KetNoiCSDL    chuoiketnoi = new KetNoiCSDL();

            sqldata.ConnectionString  = chuoiketnoi.GetSetChuoiKetNoi;
            sqldata.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
            sqldata.SelectCommand     = TenThuTuc;
            sqldata.SelectParameters.Add(TenParametter, GiaTriParaMetter);
            return(sqldata);
        }
        public void LoadDuLieu()
        {
            KetNoiCSDL ketNoi = new KetNoiCSDL();
            DataTable  dt     = ketNoi.ThucThiLenhTraVeBang("Select * from SanPham where MaSanPham=" + Request.QueryString["id"].ToString());

            lblTenSP.Text          = dt.Rows[0][1].ToString();
            lblMoTa.Text           = dt.Rows[0][2].ToString();
            img.ImageUrl           = "~/images/" + dt.Rows[0][3].ToString();
            lblGia.Text           += " " + dt.Rows[0][4].ToString() + "đ";
            lblSoLuongCon.Text     = dt.Rows[0][5].ToString();
            lblSoLuongDaBan.Text   = dt.Rows[0][6].ToString();
            lblNgayBan.Text        = dt.Rows[0][8].ToString();
            HyperLink1.NavigateUrl = "~/GioHang.aspx?ProID=" + Request.QueryString["id"].ToString();
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                String  hoTen   = txtHoTen.Text;
                String  SDT     = txtSDT.Text;
                String  email   = txtEmail.Text;
                String  diaChi  = txtDiaChi.Text;
                String  note    = txtNote.Text;
                DonHang donHang = new DonHang
                {
                    ngayMua = DateTime.Now,
                    HoTen   = hoTen,
                    SDT     = SDT,
                    Email   = email,
                    diaChi  = diaChi,
                    Note    = note
                };
                DonHangDAO DAO = new DonHangDAO();
                if (!DAO.ThemDonHang(donHang))
                {
                    Response.Write("Lỗi khi khởi tạo đơn hàng!!!!");
                }
                else
                {
                    String     sql    = "SELECT IDENT_CURRENT('DonHang') as LastID";
                    KetNoiCSDL ketNoi = new KetNoiCSDL();
                    DataTable  dt     = ketNoi.ThucThiLenhTraVeBang(sql);
                    string     maDH   = dt.Rows[0][0].ToString();
                    if (tbGioHang.Rows.Count > 0)
                    {
                        foreach (DataRow r in tbGioHang.Rows)
                        {
                            string idSP    = r["idSP"].ToString();
                            string SoLuong = r["SoLuong"].ToString();
                            DAO.ThemHang(maDH, idSP, SoLuong);
                        }

                        Session["GioHang"] = null;
                        Response.Write("Đặt hàng thành công!!!!");
                    }
                }
            }
        }
        public bool XoaDH(string id)
        {
            SqlDataSource sqldata     = new SqlDataSource();
            KetNoiCSDL    chuoiketnoi = new KetNoiCSDL();

            sqldata.ConnectionString  = chuoiketnoi.GetSetChuoiKetNoi;
            sqldata.DeleteCommandType = SqlDataSourceCommandType.StoredProcedure;
            sqldata.DeleteCommand     = "DonHang_Delete";
            sqldata.DeleteParameters.Add("MaDH", id);
            try
            {
                sqldata.Delete();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public bool SuaDanhMuc(DanhMuc danhMuc)
        {
            SqlDataSource sqldata     = new SqlDataSource();
            KetNoiCSDL    chuoiketnoi = new KetNoiCSDL();

            sqldata.ConnectionString  = chuoiketnoi.GetSetChuoiKetNoi;
            sqldata.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure;
            sqldata.UpdateCommand     = "DanhMuc_Update";
            sqldata.UpdateParameters.Add("MaDanhMuc", danhMuc.Iddanhmuc.ToString());
            sqldata.UpdateParameters.Add("TenDanhMuc", danhMuc.Tendanhmuc.ToString());

            try
            {
                sqldata.Update();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #12
0
        private void load_data()
        {
            if (Request.QueryString["ProID"] != null)
            {
                int        idSP       = int.Parse(Request.QueryString["ProID"]);
                KetNoiCSDL ketNoiCSDL = new KetNoiCSDL();
                DataTable  dt         = ketNoiCSDL.ThucThiLenhTraVeBang("select TenSanPham,Gia From SanPham WHERE MaSanPham =" + idSP);
                String     TenSP      = dt.Rows[0][0].ToString();
                int        Dongia     = int.Parse(dt.Rows[0][1].ToString());
                int        Soluong    = 1;
                ThemVaoGioHang(idSP, TenSP, Dongia, Soluong);
            }
            if (Session["GioHang"] == null)
            {
                Response.Redirect("GioHangRong.aspx");
            }
            tbGioHang = (DataTable)Session["GioHang"];
            var result = tbGioHang.AsEnumerable().Sum(x => Convert.ToInt32(x["ThanhTien"]));

            lblTongTien.Text     = "Thành tiền: " + result.ToString() + "đ";
            gvGioHang.DataSource = tbGioHang;
            gvGioHang.DataBind();
        }
        public bool ThemHang(string maDH, string maSP, string sl)
        {
            SqlDataSource sqldata     = new SqlDataSource();
            KetNoiCSDL    chuoiketnoi = new KetNoiCSDL();

            sqldata.ConnectionString  = chuoiketnoi.GetSetChuoiKetNoi;
            sqldata.InsertCommandType = SqlDataSourceCommandType.StoredProcedure;
            sqldata.InsertCommand     = "ChiTietDonHang_Insert";
            sqldata.InsertParameters.Add("MaDH", maDH);
            sqldata.InsertParameters.Add("MaSP", maSP);
            sqldata.InsertParameters.Add("SL", sl);

            try
            {
                sqldata.Insert();
                string sql = "update SanPham set SLCon=SLCon-" + sl + ", SLBan=SLBan+" + sl + " where MaSanPham=" + maSP;
                chuoiketnoi.Xoa(sql);
                return(true);
            }
            catch
            {
                return(false);
            }
        }