Example #1
0
    private void LoadData(int CurrentPage)
    {
        try
        {
            string KeySearch = GetKeySearch();
            int RowStart = (CurrentPage - 1)*PageSize + 1;
            SanPhamMau sanpham = new SanPhamMau();
            DataSet ds;
            if (CurrentPage == 0)
            {
                ds = sanpham.SelectAllSanPhamMau();
            }
            else
            {
                ds = sanpham.SelectAllSanPhamMauPaging(KeySearch, RowStart, PageSize);
                int NoOfPage = (int) Math.Ceiling(double.Parse(ds.Tables[1].Rows[0][0].ToString())/PageSize);

                grdSanPhamMau.DisplayLayout.Pager.PageCount = NoOfPage;
                grdSanPhamMau.DisplayLayout.Pager.Pattern = "Trang  [prev]  [default]  [next]";
                if (CurrentPage + 100 < NoOfPage)
                    grdSanPhamMau.DisplayLayout.Pager.Pattern += " [page:" + (CurrentPage + 100) +
                                                                 ": Thêm 100 trang]  Tổng số [pagecount] trang";
                //grdSanPhamMau.DisplayLayout.Pager.
                //int TotalShowPage = NoOfPage > 10 ? 11 : NoOfPage;
                //string[] custompages = new string[TotalShowPage];

                //int StartPage = CurrentPage > 10 ? CurrentPage - 5 : 1;
                //int EndPage = CurrentPage > 10 ? 11 : TotalShowPage;

                //if (NoOfPage > 10)
                //{
                //    custompages[0] = StartPage;
                //    for (int i = 0; i < NoOfPage; i++)
                //    {
                //        custompages[i] = (i + 1).ToString();
                //    }
                //    custompages[
                //}
                //else
                //{
                //    for (int i = 0; i < NoOfPage; i++)
                //    {
                //        custompages[i] = (i + 1).ToString();
                //    }
                //}
                //grdSanPhamMau.DisplayLayout.Pager.CustomLabels = custompages;
            }
            //}
            DataTable dt = ds.Tables[0];

            grdSanPhamMau.DataSource = dt;
            grdSanPhamMau.DataBind();
        }
        catch (Exception ex)
        {
            Response.Redirect("../message.aspx?msg=" + ex.ToString().Replace("\r\n", " "));
        }
    }
Example #2
0
    private void LoadSanPhamTheoMau(int spmid)
    {
        try
        {
            SanPhamMau spm = new SanPhamMau();
            DataSet ds = spm.SelectByID(spmid);

            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];

                int NhomSanPhamID = int.Parse(dr["NhomSanPhamID"].ToString());
                CuaHang ch = new CuaHang();
                DataSet dsch = ch.SelectByNguoiDungID(Common.NguoiDungID());
                int CuaHangID = int.Parse(dsch.Tables[0].Rows[0]["CuaHangID"].ToString());

                if (checkNhomSanPham(NhomSanPhamID, CuaHangID) == false)
                {
                    AddNhomSanPhamToCuaHang(NhomSanPhamID, CuaHangID);
                    ddlNhomSanPham.Items.Clear();
                    LoadDanhMucConForDropDown(0, CuaHangID, 0);
                    ddlNhomSanPham.SelectedValue = NhomSanPhamID.ToString();
                }

                ddlNhomSanPham.SelectedValue = dr["NhomSanPhamID"].ToString();

                txtTenSanPham.Text = dr["TenSanPham"].ToString();
                //txtMaSoSanPham.Text = dr["MaSoSanPham"].ToString();
                txtGiaSanPham.Text = dr["GiaSanPham"].ToString();
                ddlHangSanXuat.SelectedValue = dr["HangSanXuatID"].ToString();
                ddlKhuVuc.SelectedValue = dr["KhuVucID"].ToString();
                chkKhuyenMai.Checked = dr["KhuyenMai"].ToString() != "" ? bool.Parse(dr["KhuyenMai"].ToString()) : false;
                chkGiamGia.Checked = dr["GiamGia"].ToString() != "" ? bool.Parse(dr["GiamGia"].ToString()) : false;
                //txtMoTaSanPham.Text = dr["MoTaSanPham"].ToString();
                wheMoTaSanPham.Text = dr["MoTaSanPham"].ToString();
                imgAnhChinh.ImageUrl = "." + dr["AnhSanPham"];
                wheThongTinSanPham.Text = dr["ThongTinSanPham"].ToString();
                hidAnhChinh.Value = dr["AnhSanPham"].ToString();

                if (chkGiamGia.Checked)
                {
                    cvGiaMoi.Enabled = true;
                    txtGiaMoi.Enabled = true;
                    txtGiaMoi.Text = dr["GiaKhuyenMai"].ToString();
                }
                else
                {
                    txtGiaMoi.Enabled = false;
                }

                //txtDonViTienTe.Text = dr["DonViTienTe"].ToString();
                //txtThongTinSanPham.Text = dr["ThongTinSanPham"].ToString();

                LoadAnhPhuTheoMau(spmid);
                LoadThuocTinhCha();
                LoadThuocTinh();

                if (chkKhuyenMai.Checked)
                {
                    wdcBatDauKM.Enabled = true;
                    wdcBatDauKM.Value = DateTime.Parse(dr["BatDauKhuyenMai"].ToString());
                    wdcKetThucKM.Enabled = true;
                    wdcKetThucKM.Value = DateTime.Parse(dr["KetThucKhuyenMai"].ToString());
                    txtMoTaKhuyenMai.Enabled = true;
                    txtMoTaKhuyenMai.Text = dr["MoTaKhuyenMai"].ToString();
                    cvKhuyenMai.Enabled = true;
                }
                else
                {
                    txtMoTaKhuyenMai.Enabled = false;
                    wdcBatDauKM.Enabled = false;
                    wdcKetThucKM.Enabled = false;
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
    private void LoadData()
    {
        try
        {
            SanPhamMau sanpham = new SanPhamMau();
            DataSet ds = sanpham.SelectByID(int.Parse(ViewState["ID"].ToString()));
            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];

                txtTenSanPham.Text = dr["TenSanPham"].ToString();
                //txtMaSoSanPham.Text = dr["MaSoSanPham"].ToString();
                txtGiaSanPham.Text = dr["GiaSanPham"].ToString();
                ddlNhomSanPham.SelectedValue = dr["NhomSanPhamID"].ToString();
                ddlHangSanXuat.SelectedValue = dr["HangSanXuatID"].ToString();
                ddlKhuVuc.SelectedValue = dr["KhuVucID"].ToString();
                chkKhuyenMai.Checked = dr["KhuyenMai"].ToString() != "" ? bool.Parse(dr["KhuyenMai"].ToString()) : false;
                chkGiamGia.Checked = dr["GiamGia"].ToString() != "" ? bool.Parse(dr["GiamGia"].ToString()) : false;
                //txtMoTaSanPham.Text = dr["MoTaSanPham"].ToString();
                wheMoTaSanPham.Text = dr["MoTaSanPham"].ToString();
                imgAnhChinh.ImageUrl = "." + dr["AnhSanPham"];
                wheThongTinSanPham.Text = dr["ThongTinSanPham"].ToString();

                if (chkGiamGia.Checked)
                {
                    cvGiaMoi.Enabled = true;
                    txtGiaMoi.Enabled = true;
                    txtGiaMoi.Text = dr["GiaKhuyenMai"].ToString();
                }
                else
                {
                    txtGiaMoi.Enabled = false;
                }

                //txtDonViTienTe.Text = dr["DonViTienTe"].ToString();
                //txtThongTinSanPham.Text = dr["ThongTinSanPham"].ToString();

                LoadAnhPhu();
                LoadThuocTinhCha();
                //LoadThuocTinh();
                LoadThuocTinhSanPham(int.Parse(ViewState["ID"].ToString()));
                if (chkKhuyenMai.Checked)
                {
                    wdcBatDauKM.Enabled = true;
                    wdcBatDauKM.Value = DateTime.Parse(dr["BatDauKhuyenMai"].ToString());
                    wdcKetThucKM.Enabled = true;
                    wdcKetThucKM.Value = DateTime.Parse(dr["KetThucKhuyenMai"].ToString());
                    txtMoTaKhuyenMai.Enabled = true;
                    txtMoTaKhuyenMai.Text = dr["MoTaKhuyenMai"].ToString();
                    cvKhuyenMai.Enabled = true;
                }
                else
                {
                    txtMoTaKhuyenMai.Enabled = false;
                    wdcBatDauKM.Enabled = false;
                    wdcKetThucKM.Enabled = false;
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
    private bool LuuSanPham()
    {
        if (Page.IsValid)
        {
            SanPhamMau sanpham = new SanPhamMau();
            try
            {
                string relativePath = "";
                DateTime? NgayBDKM = null;
                DateTime? NgayKTKM = null;
                string strMoTaKhuyenMai = null;
                string path = Server.MapPath("../Upload/ProdImages");
                decimal? giamoi = null;
                string MaSoSanPham = null;

                if (chkKhuyenMai.Checked)
                {
                    NgayBDKM = DateTime.Parse(wdcBatDauKM.Value.ToString());
                    NgayKTKM = DateTime.Parse(wdcKetThucKM.Value.ToString());
                    txtMoTaKhuyenMai.Enabled = true;
                    strMoTaKhuyenMai = txtMoTaKhuyenMai.Text;
                }

                if (chkGiamGia.Checked)
                {
                    txtGiaMoi.Enabled = true;
                    cvGiaMoi.Enabled = true;
                    giamoi = decimal.Parse(txtGiaMoi.Text);
                }

                if (fileAnhChinh.PostedFile.FileName != "")
                {
                    try
                    {
                        //if (fileAnhChinh.PostedFile.ContentLength <= 100000)
                        //{
                        string randomString = "";
                        path += "\\" + Common.NguoiDungID();
                        relativePath = "./Upload/ProdImages" + "/" + Common.NguoiDungID() + "/";
                        int pos = fileAnhChinh.PostedFile.FileName.LastIndexOf('\\');
                        string absolutePath = path + "\\" + fileAnhChinh.PostedFile.FileName.Remove(0, pos + 1);

                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }

                        if (File.Exists(absolutePath))
                        {
                            randomString = DateTime.Now.Ticks + "_";
                            absolutePath = path + "\\" + randomString +
                                           fileAnhChinh.PostedFile.FileName.Remove(0, pos + 1);
                        }
                        //fileAnhChinh.PostedFile.SaveAs(absolutePath);
                        Common.ResizeFromStream(absolutePath, 320, fileAnhChinh.PostedFile.InputStream);
                        relativePath += randomString + fileAnhChinh.PostedFile.FileName.Remove(0, pos + 1);

                        if (ViewState["Action"].ToString() == "ADD")
                        {
                            ViewState["ID"] = sanpham.InsertFields(txtTenSanPham.Text, MaSoSanPham,
                                                                   decimal.Parse(txtGiaSanPham.Text), "VNĐ",
                                                                   wheMoTaSanPham.Text,
                                                                   wheThongTinSanPham.Text,
                                                                   int.Parse(ddlNhomSanPham.SelectedValue),
                                                                   int.Parse(ddlHangSanXuat.SelectedValue),
                                                                   Common.NguoiDungID(), relativePath,
                                                                   chkKhuyenMai.Checked, strMoTaKhuyenMai, giamoi,
                                                                   NgayBDKM, NgayKTKM,
                                                                   null, int.Parse(ddlKhuVuc.SelectedValue), null, null,
                                                                   chkGiamGia.Checked, null, DateTime.Now, null, null,
                                                                   null, 0, null, null, null, null);
                        }
                        else if (ViewState["Action"].ToString() == "EDIT")
                        {
                            sanpham.UpdateFields(int.Parse(ViewState["ID"].ToString()), txtTenSanPham.Text, null,
                                                 decimal.Parse(txtGiaSanPham.Text), null, wheMoTaSanPham.Text,
                                                 wheThongTinSanPham.Text, int.Parse(ddlNhomSanPham.SelectedValue),
                                                 int.Parse(ddlHangSanXuat.SelectedValue),
                                                 Common.NguoiDungID(), relativePath, chkKhuyenMai.Checked,
                                                 strMoTaKhuyenMai, giamoi, NgayBDKM, NgayKTKM,
                                                 null, int.Parse(ddlKhuVuc.SelectedValue), null, null,
                                                 chkGiamGia.Checked, null, DateTime.Now, null, null,
                                                 null, null, null, null, null, null);
                        }

                        imgAnhChinh.ImageUrl = "." + relativePath;
                        //}
                        //else
                        //{
                        //    lblAnhChinhErr.Text = "Kích cỡ ảnh quá lớn!";
                        //    return false;
                        //}
                    }
                    catch (Exception ex)
                    {
                        Response.Redirect("../message.aspx?msg=" + ex.Message.Replace("\r\n", ""), false);
                    }
                }
                else
                {
                    if (ViewState["Action"].ToString() == "ADD")
                    {
                        ViewState["ID"] = sanpham.InsertFields(txtTenSanPham.Text, MaSoSanPham,
                                                               decimal.Parse(txtGiaSanPham.Text), "VNĐ",
                                                               wheMoTaSanPham.Text,
                                                               wheThongTinSanPham.Text,
                                                               int.Parse(ddlNhomSanPham.SelectedValue),
                                                               int.Parse(ddlHangSanXuat.SelectedValue),
                                                               Common.NguoiDungID(), null, chkKhuyenMai.Checked,
                                                               strMoTaKhuyenMai, giamoi, NgayBDKM, NgayKTKM,
                                                               null, int.Parse(ddlKhuVuc.SelectedValue), null, null,
                                                               chkGiamGia.Checked, null, DateTime.Now, null, null,
                                                               null, 0, null, null, null, null);
                    }
                    else if (ViewState["Action"].ToString() == "EDIT")
                    {
                        sanpham.UpdateFields(int.Parse(ViewState["ID"].ToString()), txtTenSanPham.Text, null,
                                             decimal.Parse(txtGiaSanPham.Text), null, wheMoTaSanPham.Text,
                                             wheThongTinSanPham.Text, int.Parse(ddlNhomSanPham.SelectedValue),
                                             int.Parse(ddlHangSanXuat.SelectedValue),
                                             Common.NguoiDungID(), null, chkKhuyenMai.Checked, strMoTaKhuyenMai, giamoi,
                                             NgayBDKM, NgayKTKM,
                                             null, int.Parse(ddlKhuVuc.SelectedValue), null, null, chkGiamGia.Checked,
                                             null, DateTime.Now, null, null,
                                             null, null, null, null, null, null);
                    }
                }

                LuuThuocTinhSanPham();
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
            return true;
        }
        else
        {
            return false;
        }
    }
Example #5
0
    protected void btnXoa_Click(object sender, EventArgs e)
    {
        try
        {
            switch (ViewState["TYPE"].ToString())
            {
                case "thuoctinh":
                    if (Common.LoaiNguoiDungID() == 3)
                    {
                        ThuocTinh tt = new ThuocTinh();
                        tt.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "nhomsanpham":
                    if (Common.LoaiNguoiDungID() == 3)
                    {
                        NhomSanPham nhomsanpham = new NhomSanPham();
                        nhomsanpham.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "vitrisanpham":
                    if ((Common.LoaiNguoiDungID() == 3) || (Common.LoaiNguoiDungID() == 2))
                    {
                        ViTriSanPham vtsp = new ViTriSanPham();
                        vtsp.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "cuahangnhomsanpham":
                    if (Common.LoaiNguoiDungID() == 2)
                    {
                        deleteCuaHangNhomSanPham(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "nhomsanphamcuahang":
                    if (Common.LoaiNguoiDungID() == 2)
                    {
                        deleteNhomSanPhamCuaHang(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;

                case "nhanxetsanpham":
                    if (Common.LoaiNguoiDungID() != 1)
                    {
                        NhanXetSanPham nhanxet = new NhanXetSanPham();
                        nhanxet.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "tintuc":
                    if ((Common.LoaiNguoiDungID() == 3) || (Common.LoaiNguoiDungID() == 2))
                    {
                        TinTuc tt = new TinTuc();
                        tt.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "hotrotructuyen":
                    if ((Common.LoaiNguoiDungID() == 3) || (Common.LoaiNguoiDungID() == 2))
                    {
                        HoTroTrucTuyen ht = new HoTroTrucTuyen();
                        ht.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "hoidapsanpham":
                    if (Common.LoaiNguoiDungID() != 1)
                    {
                        HoiDapSanPham hoidap = new HoiDapSanPham();
                        hoidap.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "nguoidung":
                    if (Common.LoaiNguoiDungID() == 3)
                    {
                        if (CheckExistCuaHang(id) != true)
                        {
                            NguoiDung nguoidung = new NguoiDung();
                            nguoidung.Delete(id);
                        }
                        else
                        {
                            Response.Redirect("../message.aspx?msg=Không thể xóa người dùng đã có cửa hàng", false);
                        }
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "hangsanxuat":
                    if (Common.LoaiNguoiDungID() == 3)
                    {
                        HangSanXuat hsx = new HangSanXuat();
                        hsx.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "khuvuc":
                    if (Common.LoaiNguoiDungID() == 3)
                    {
                        KhuVuc kv = new KhuVuc();
                        kv.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "quangcao":
                    if (Common.LoaiNguoiDungID() == 2 || Common.LoaiNguoiDungID() == 3)
                    {
                        QuangCao qcao = new QuangCao();
                        DataSet ds = qcao.SelectByQuangCaoID(id);
                        if (ds.Tables[0].Rows.Count == 1)
                        {
                            if (Common.LoaiNguoiDungID() == 3)
                            {
                                //Administrator
                                if (ds.Tables[0].Rows[0]["LoaiNguoiDungID"].ToString() == "3") qcao.Delete(id);
                            }
                            else
                            {
                                //e-Store
                                if (ds.Tables[0].Rows[0]["LoaiNguoiDungID"].ToString() == "2"
                                    && ds.Tables[0].Rows[0]["NguoiDungID"].ToString() == Common.NguoiDungID().ToString())
                                    qcao.Delete(id);
                            }
                        }
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "sanpham":
                    {
                        SanPham sanpham = new SanPham();
                        DataSet dssp = sanpham.SelectBySanPhamID(id);
                        if (Common.LoaiNguoiDungID() == 2)
                        {
                            if (dssp.Tables[0].Rows.Count == 1)
                            {
                                //e-Store
                                if (dssp.Tables[0].Rows[0]["LoaiNguoiDungID"].ToString() ==
                                    Common.LoaiNguoiDungID().ToString()
                                    &&
                                    dssp.Tables[0].Rows[0]["NguoiDungID"].ToString() == Common.NguoiDungID().ToString())
                                {
                                    sanpham.Delete(id);
                                }
                            }
                        }
                        else if (Common.LoaiNguoiDungID() == 3)
                        {
                            if (dssp.Tables[0].Rows.Count == 1)
                            {
                                sanpham.Delete(id);
                            }
                        }
                        else
                        {
                            Response.Redirect("../message.aspx?msg=Access denied");
                        }
                    }
                    break;
                case "sanphammau":
                    {
                        SanPhamMau sanpham = new SanPhamMau();
                        DataSet dssp = sanpham.SelectByID(id);
                        if (Common.LoaiNguoiDungID() == 3)
                        {
                            if (dssp.Tables[0].Rows.Count == 1)
                            {
                                sanpham.Delete(id);
                            }
                        }
                        else
                        {
                            Response.Redirect("../message.aspx?msg=Access denied");
                        }
                    }
                    break;
                case "anhsanpham":
                    if ((Common.LoaiNguoiDungID() == 2) || (Common.LoaiNguoiDungID() == 3))
                    {
                        Anh anhsanpham = new Anh();
                        DataSet dssp = anhsanpham.SelectByID(id);
                        if (dssp.Tables[0].Rows.Count == 1)
                        {
                            anhsanpham.Delete(id);

                            if (File.Exists(Server.MapPath(Request.QueryString["src"])))
                            {
                                File.Delete(Server.MapPath(Request.QueryString["src"]));
                            }
                        }
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
            }
            string strScript = "<script language='JavaScript'>" + "window.parent.Refresh();</script>";
            ClientScript.RegisterStartupScript(Type.GetType("System.String"), "Refresh", strScript);
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }