示例#1
0
    private int UpdateImgUpload()
    {
        images = new ImagesBLL();
        string dateString  = DateTime.Now.ToString("MM-dd-yyyy");
        string dirFullPath = HttpContext.Current.Server.MapPath("../../images/Uploads/" + dateString + "/");

        if (!Directory.Exists(dirFullPath))   // CHECK IF THE FOLDER EXISTS. IF NOT, CREATE A NEW FOLDER.
        {
            Directory.CreateDirectory(dirFullPath);
        }
        string         fileName      = Path.GetFileName(FileUploadUpdateImg.PostedFile.FileName);
        ImageCodecInfo jgpEncoder    = null;
        string         str_image     = "";
        string         fileExtension = "";

        if (!string.IsNullOrEmpty(fileName))
        {
            fileExtension = Path.GetExtension(fileName);
            str_image     = dateString + "-" + RandomName + fileExtension;
            string pathToSave = HttpContext.Current.Server.MapPath("../../images/Uploads/" + dateString + "/") + str_image;
            //file.SaveAs(pathToSave);
            System.Drawing.Image image = System.Drawing.Image.FromStream(FileUploadUpdateImg.FileContent);
            if (image.RawFormat.Guid == System.Drawing.Imaging.ImageFormat.Gif.Guid)
            {
                jgpEncoder = GetEncoder(ImageFormat.Gif);
            }
            else if (image.RawFormat.Guid == System.Drawing.Imaging.ImageFormat.Jpeg.Guid)
            {
                jgpEncoder = GetEncoder(ImageFormat.Jpeg);
            }
            else if (image.RawFormat.Guid == System.Drawing.Imaging.ImageFormat.Bmp.Guid)
            {
                jgpEncoder = GetEncoder(ImageFormat.Bmp);
            }
            else if (image.RawFormat.Guid == System.Drawing.Imaging.ImageFormat.Png.Guid)
            {
                jgpEncoder = GetEncoder(ImageFormat.Png);
            }
            else
            {
                throw new System.ArgumentException("Invalid File Type");
            }
            Bitmap            bmp1                = new Bitmap(FileUploadUpdateImg.FileContent);
            Encoder           myEncoder           = Encoder.Quality;
            EncoderParameters myEncoderParameters = new EncoderParameters(1);
            EncoderParameter  myEncoderParameter  = new EncoderParameter(myEncoder, 30L);
            myEncoderParameters.Param[0] = myEncoderParameter;
            bmp1.Save(pathToSave, jgpEncoder, myEncoderParameters);
            this.images.NewImages(str_image, "images/Uploads/" + dateString + "/" + str_image, Session.GetCurrentUser().ID);
        }
        return((images.ListWithImagesName(str_image).FirstOrDefault() == null) ? 0 : images.ListWithImagesName(str_image).FirstOrDefault().ID);
    }
示例#2
0
 protected void btnChangeCTImages_Click(object sender, EventArgs e)
 {
     try
     {
         category = new CategoryBLL();
         images   = new ImagesBLL();
         int    ctID    = Convert.ToInt32((gwCategory.SelectedRow.FindControl("lblCategoryID") as Label).Text);
         string http    = "http://" + Request.Url.Authority + "/";
         string ImgNAme = HidImgUrlCT.Value.Remove(0, HidImgUrlCT.Value.LastIndexOf("/") + 1);
         Images img     = images.ListWithImagesName(ImgNAme).FirstOrDefault();
         if (category.UpdateImage(ctID, img.ID))
         {
             this.GetPostCategoryPageWise(1);
         }
     }
     catch (Exception ex)
     {
         this.AlertPageValid(true, ex.ToString(), alertPageValid, lblPageValid);
     }
 }
示例#3
0
    protected void btnSaveNewCategory_Click(object sender, EventArgs e)
    {
        try
        {
            category = new CategoryBLL();
            images   = new ImagesBLL();

            string titleVN = txtCategoryNameVN.Text;
            string titleEN = txtCategoryNameEN.Text;
            int    Parent  = Convert.ToInt32(dlParent.SelectedValue);
            //ItemIndex
            int    itemindex = (Convert.ToInt32(dlParent.SelectedValue) == 0) ? category.MaxItemindexWithParentNull() + 1 : category.MaxItemindexWithParent(Convert.ToInt32(dlParent.SelectedValue)) + 1;
            string permlink  = txtPermalink.Text;
            string seotitle  = txtSeoTitle.Text;
            //Images
            List <Images> lstI  = images.ListWithImagesName(txtImageTemp.Text);
            Images        img   = lstI.FirstOrDefault();
            int           ImgID = (img == null) ? 0 : img.ID;
            //Create By
            string  metatile       = txtMetaTitle.Text;
            string  metakeyword    = txtMetaKeywords.Text;
            string  metadecription = txtMetaDescriptions.Text;
            Boolean showonhome     = (chkShowOnHome.Checked == true) ? true : false;
            if (category.NewCategory(titleVN, titleEN, Parent, itemindex, permlink, seotitle, ImgID, Session.GetCurrentUser().ID, Convert.ToDateTime("12/12/1900"), 0, metatile, metakeyword, metadecription, true, showonhome))
            {
                Response.Redirect(Request.Url.AbsoluteUri);
            }
            else
            {
                this.AlertPageValid(true, "False to create category . Error to connect server !", alertPageValid, lblPageValid);
            }
        }
        catch (Exception ex)
        {
            this.AlertPageValid(true, ex.ToString(), alertPageValid, lblPageValid);
        }
    }
示例#4
0
    protected void btndelete_ServerClick(object sender, EventArgs e)
    {
        images = new ImagesBLL();

        try
        {
            //this.images.DeleteImages(HiddenImages.Value);
            List <Images> lst      = images.ListWithImagesName(HiddenImages.Value);
            Images        img      = lst.FirstOrDefault();
            string        filename = Server.MapPath("../" + img.ImagesUrl);
            if (!string.IsNullOrWhiteSpace(filename))
            {
                if ((System.IO.File.Exists(filename)))
                {
                    System.IO.File.Delete(filename);
                    Response.Redirect(Request.Url.AbsoluteUri);
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + ex.ToString() + "')</script>");
        }
    }