Пример #1
0
 public void LoadAnhPhu()
 {
     try
     {
         // Load Anh Phu
         Anh anhphu = new Anh();
         DataSet dsAnh = anhphu.SelectBySanPhamID(int.Parse(ViewState["ID"].ToString()));
         if (dsAnh.Tables[0].Rows.Count > 0)
         {
             foreach (DataRow drAnh in dsAnh.Tables[0].Rows)
             {
                 HtmlImage img = new HtmlImage();
                 img.Src = "." + drAnh["DuongDan"];
                 img.Height = 50;
                 img.Width = 50;
                 img.ID = "img" + drAnh["AnhID"];
                 img.Attributes.Add("onclick",
                                    "return XoaAnhPhu('" + drAnh["AnhID"] + "', '" + img.Src + "', this.ID, this);");
                 pnlAnhPhu.Controls.Add(img);
             }
         }
     }
     catch (Exception ex)
     {
         Response.Write(ex.ToString());
     }
 }
Пример #2
0
    private bool LuuSanPham()
    {
        SanPham sanpham = new SanPham();
        try
        {
            string relativePath = "";
            DateTime? NgayBDKM = null;
            DateTime? NgayKTKM = null;
            string strMoTaKhuyenMai = null;
            string path = Server.MapPath("../Upload/ProdImages");
            decimal? giamoi = null;
            string MaSoSanPham = null;
            int spmid = 0;
            if (Request.QueryString["spmid"] != null)
            {
                spmid = int.Parse(Request.QueryString["spmid"]);
            }

            if (ViewState["Action"].ToString() == "ADD")
            {
                MaSoSanPham = GenerateMaSoSanPham();
            }

            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) || (Common.LoaiNguoiDungID() == 3))
                    {
                        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);
                        }

                        if (Common.LoaiNguoiDungID() != 3)
                            Common.ResizeFromStream(absolutePath, 320, fileAnhChinh.PostedFile.InputStream);
                        //fileAnhChinh.PostedFile.SaveAs(absolutePath);
                        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, spmid, DateTime.Now,
                                                                   txtTenPhu.Text);
                        }
                        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, null, null, null,
                                                 null, null, null, null, null, null, null, DateTime.Now, txtTenPhu.Text);
                        }

                        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 (Request.QueryString["spmid"] != null)
                {
                    if (hidAnhChinh.Value != "")
                    {
                        relativePath = hidAnhChinh.Value;
                    }
                    else
                    {
                        relativePath = null;
                    }
                }

                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, spmid, DateTime.Now,
                                                           txtTenPhu.Text);
                }
                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,
                                         null, null, null,
                                         null, null, null, null, null, null, null, DateTime.Now, txtTenPhu.Text);
                }
            }

            if (Request.QueryString["spmid"] != null)
            {
                //CuaHangNhomSanPham chnsp = new CuaHangNhomSanPham();
                //DataSet dsnsp = chnsp.s
                Anh anh = new Anh();
                DataSet dsAnh = anh.SelectBySanPhamMauID(int.Parse(Request.QueryString["spmid"]));
                for (int i = 0; i < dsAnh.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = dsAnh.Tables[0].Rows[i];
                    anh.InsertFields(int.Parse(ViewState["ID"].ToString()), dr["DuongDan"].ToString(),
                                     dr["Bak1"].ToString()
                                     , dr["Bak2"].ToString(), int.Parse("0" + dr["Bak3"]),
                                     int.Parse(Request.QueryString["spmid"]));
                }
            }
            LuuThuocTinhSanPham();
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
        return true;
    }
Пример #3
0
    private void ShowAnhSanPham()
    {
        try
        {
            Anh anh = new Anh();
            DataSet ds = anh.SelectBySanPhamID(int.Parse(ViewState["SanPhamID"].ToString()));

            pnlAnhSanPham.Controls.Clear();
            HtmlImage img = new HtmlImage();
            img.Height = 40;
            img.Width = 40;
            img.Src = imgSanPham.Src;
            img.Style.Add("cursor", "hand");
            img.Attributes.Add("onclick", "Enlarge(this.src);");

            pnlAnhSanPham.Controls.Add(img);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                img = new HtmlImage();
                img.Src = dr["DuongDan"].ToString();
                img.Height = 40;
                img.Width = 40;
                img.Style.Add("cursor", "hand");
                img.Attributes.Add("onclick", "Enlarge(this.src);");
                pnlAnhSanPham.Controls.Add(img);
            }
        }
        catch (Exception ex)
        {
            //Response.Redirect("Message.aspx?msg=" + ex.Message.Replace("\r\n", " "), false);
            Response.Write(ex.ToString());
        }
    }
Пример #4
0
    protected void btnUpLoad_Click(object sender, EventArgs e)
    {
        if (fileAnhPhu.PostedFile.FileName != "")
        {
            string relativePath = "";
            string path = Server.MapPath("../Upload/ProdImages");
            //path += "\\" + Common.NguoiDungID.ToString();
            try
            {
                if (fileAnhPhu.PostedFile.ContentLength <= 100000)
                {
                    string randomString = "";
                    path += "\\" + Common.NguoiDungID();
                    relativePath = "./Upload/ProdImages" + "/" + Common.NguoiDungID() + "/";
                    int pos = fileAnhPhu.PostedFile.FileName.LastIndexOf('\\');
                    string absolutePath = path + "\\" + fileAnhPhu.PostedFile.FileName.Remove(0, pos + 1);

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

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

                    Common.ResizeFromStream(absolutePath, 320, fileAnhPhu.PostedFile.InputStream);

                    relativePath += randomString + fileAnhPhu.PostedFile.FileName.Remove(0, pos + 1);

                    try
                    {
                        Anh anhphu = new Anh();
                        anhphu.InsertFields(int.Parse(ViewState["ID"].ToString()), relativePath, null, null, null, null);

                        LoadAnhPhu();
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex.ToString());
                    }
                }
                else
                {
                    lblAnhPhuErr.Text = "Kích cỡ ảnh quá lớn!";
                    LoadAnhPhu();
                    return;
                    //Response.Redirect("../message.aspx?msg=File size is too big!", false);
                }
            }
            catch (Exception ex)
            {
                Response.Redirect("../message.aspx?msg=" + ex.Message.Replace("\r\n", ""), false);
            }
        }
    }
Пример #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());
        }
    }