Пример #1
0
    // them :
    private void them()
    {
        string     b       = "";
        sanphamBLL bs      = new sanphamBLL();
        DateTime   datet   = DateTime.Now;
        string     namePic = "";
        string     ext     = Path.GetExtension(fuPicture.FileName);

        if (fuPicture.HasFile)
        {
            if (CheckFileType(fuPicture.FileName) == true)
            {
                namePic = string.Format("{0:yyyy-M-d-HH-mm-ss}", datet) + ext;
                String filePath = "~/uploads/" + namePic;

                fuPicture.SaveAs(MapPath(filePath));
                lbErrorPic.Text = filePath;
            }
            else
            {
                lbErrorPic.Text = "Hình ảnh phải ở dạng đuôi *.png, *.jpg";
            }
        }
        if (rbYes.Checked == true)
        {
            b = "true";
        }
        else
        {
            b = "false";
        }
        if (bs.check(txtTen.Text) == true)
        {
            lbTen.Text = "Sản phẩm này đã tồn tại.";
        }
        else
        {
            bool tf = bs.add(txtTen.Text.Trim(), Convert.ToInt32(txtSoLuong.Text), namePic, Convert.ToInt32(ddlDM.SelectedValue), txtTT.Text, Convert.ToDecimal(txtGia.Text), b);
            if (tf == true)
            {
                Response.Redirect("sanpham.aspx?add=t");
            }
            else
            {
                lbError.Text = "<div class='error'>"
                               + "<div class='tl'></div><div class='tr'></div>"
                               + "<div class='desc'>"
                               + "<p>Thêm bị lỗi !</p>"
                               + "</div>"
                               + "<div class='bl'></div><div class='br'></div>"
                               + "</div>";
            }
        }
    }
Пример #2
0
    // sua :
    private void sua()
    {
        string     b       = "";
        sanphamBLL bs      = new sanphamBLL();
        DateTime   datet   = DateTime.Now;
        string     namePic = lbHinh.ToolTip;
        string     ext     = Path.GetExtension(fuPicture.FileName);

        if (rbYes.Checked == true)
        {
            b = "true";
        }
        else
        {
            b = "false";
        }
        string  ten     = txtTen.Text.Trim();
        int     soluong = Convert.ToInt32(txtSoLuong.Text);
        int     idd     = Convert.ToInt32(ddlDM.SelectedValue);
        string  tt      = txtTT.Text;
        decimal gia     = Convert.ToDecimal(txtGia.Text);
        int     id_sp   = Convert.ToInt32(Request.QueryString["id"]);

        if (bs.check(txtTen.Text, id_sp) == true)
        {
            lbTen.Text = "Sản phẩm này đã tồn tại.";
        }
        else
        {
            if (fuPicture.HasFile)
            {
                if (CheckFileType(fuPicture.FileName) == true)
                {
                    namePic = string.Format("{0:yyyy-M-d-HH-mm-ss}", datet) + ext;
                    String filePath = "~/uploads/" + namePic;

                    fuPicture.SaveAs(MapPath(filePath));
                    lbErrorPic.Text = filePath;
                }
                else
                {
                    lbErrorPic.Text = "Hình ảnh phải ở dạng đuôi *.png, *.jpg";
                }
            }
            bool tf = bs.edit(ten, soluong, namePic, idd, tt, gia, b, id_sp);
            if (tf == true)
            {
                Response.Redirect("sanpham.aspx?edit=t");
            }
            else
            {
                lbError.Text = "<div class='error'>"
                               + "<div class='tl'></div><div class='tr'></div>"
                               + "<div class='desc'>"
                               + "<p>Thêm bị lỗi !</p>"
                               + "</div>"
                               + "<div class='bl'></div><div class='br'></div>"
                               + "</div>";
            }
        }
    }