示例#1
0
        public DataView GetPhotoAlbumCategories(string cond)
        {
            AlbumsDS     _ds = new AlbumsDS();
            IDataAdapter Adp = base.GetAdapter(cte.PhotoAlbumCategoriesAdp);

            return(((AlbumsDS)base.FillData(Adp, _ds, cond)).PhotoAlbumsCategories.DefaultView);
        }
示例#2
0
        /// <summary>
        /// Returns list of images available in the photo Albums database
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public DataView GetImages(string cond)
        {
            AlbumsDS     _ds    = new AlbumsDS();
            IDataAdapter Adp    = base.GetAdapter(cte.PhotoAlbumImagesAdp);
            DataView     images = ((AlbumsDS)base.FillData(Adp, _ds, cond)).PhotoAlbumImages.DefaultView;

            images.Sort = "sort asc";

            DataTable dt = images.Table;


            dt.Columns.Add("Thumb");
            dt.Columns.Add("Large");
            dt.Columns.Add("Original");

            if (dt.Rows.Count > 0)
            {
                int    albumId = (int)dt.Rows[0]["AlbumId"];
                string path    = PhotoAlbumsManager.GetImagesPath(albumId);

                foreach (DataRow dr in dt.Rows)
                {
                    dr["Thumb"]    = string.Format("{0}/Thumb/{1}", path, dr["FileName"]);
                    dr["Large"]    = string.Format("{0}/Large/{1}", path, dr["FileName"]);
                    dr["Original"] = string.Format("{0}/Original/{1}", path, dr["FileName"]);
                }
            }

            dt.AcceptChanges();

            return(dt.DefaultView);
        }
示例#3
0
        public int AddCategory(string name)
        {
            AlbumsDS _ds = new AlbumsDS();

            IDataAdapter Adp = base.GetAdapter(cte.PhotoAlbumCategoriesAdp);

            AlbumsDS.PhotoAlbumsCategoriesRow row = _ds.PhotoAlbumsCategories.NewPhotoAlbumsCategoriesRow();

            row.CategoryName = name;
            row.UniqueName   = StringUtils.ToURL(name);

            _ds.PhotoAlbumsCategories.AddPhotoAlbumsCategoriesRow(row);
            base.UpdateData(Adp, _ds);

            return(row.CategoryId);
        }
示例#4
0
        /// <summary>
        /// Deletes a PhotoAlbum from the database and all its related images
        /// TODO: Delete photo album relations
        /// </summary>
        /// <param name="AlbumId">AlbumId</param>
        /// <returns>true on success</returns>
        public bool DeleteAlbum(int AlbumId)
        {
            //disable the album, in case something went wrong
            UpdateAlbumStatus(AlbumId, false);

            string path = WebContext.Server.MapPath("~/" + lw.CTE.Folders.PhotoAlbums);

            path = System.IO.Path.Combine(path, string.Format("Album{0}", AlbumId));

            AlbumsDS _ds = new AlbumsDS();

            string sql = String.Format("Delete from PhotoAlbums where Id={0}", AlbumId);

            DBUtils.ExecuteQuery(sql, cte.lib);

            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }


            return(true);
        }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="AlbumId"></param>
        /// <param name="Caption"></param>
        /// <param name="image"></param>
        /// <returns></returns>
        ///

        /*
         * <Parameters>
         *      <key>PhotoAlbum_Thumb_Image_Option</key>
         *      <value>Resize</value> or <value>Crop</value>
         * </Parameters>
         */

        public DataRow AddImage(int AlbumId, string Caption, string image)
        {
            AlbumsDS _ds = new AlbumsDS();

            IDataAdapter Adp = base.GetAdapter(cte.PhotoAlbumImagesAdp);

            AlbumsDS.PhotoAlbumImagesRow row = _ds.PhotoAlbumImages.NewPhotoAlbumImagesRow();

            row.AlbumId      = AlbumId;
            row.Caption      = Caption;
            row.Sort         = 100;
            row.DateAdded    = DateTime.Now;
            row.DateModified = DateTime.Now;

            _ds.PhotoAlbumImages.AddPhotoAlbumImagesRow(row);
            base.UpdateData(Adp, _ds);

            string path = WebContext.Server.MapPath("~/" + lw.CTE.Folders.PhotoAlbums);

            path = System.IO.Path.Combine(path, string.Format("Album{0}", AlbumId));
            string largePath    = Path.Combine(path, "Large");
            string thumbPath    = Path.Combine(path, "Thumb");
            string originalPath = Path.Combine(path, "Original");


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

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

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

            Config cfg = new Config();

            string ext      = StringUtils.GetFileExtension(image);
            string fileName = StringUtils.GetFriendlyFileName(image);

            string _ImageName = string.Format("{0}_{1}.{2}", fileName, row.Id, ext);

            string ImageName      = string.Format("{0}\\{1}", originalPath, _ImageName);
            string largeImageName = string.Format("{0}\\{1}", largePath, _ImageName);
            string thumbImageName = string.Format("{0}\\{1}", thumbPath, _ImageName);

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

            System.IO.File.Copy(image, ImageName);

            try
            {
                Dimension largeImageSize = new Dimension(cte.ImageDefaultSize);
                Dimension thumbImageSize = new Dimension(cte.ImageDefaultThumbSize);

                if (!string.IsNullOrWhiteSpace(cfg.GetKey(cte.ImageSize)))
                {
                    largeImageSize = new Dimension(cfg.GetKey(cte.ImageSize));
                }
                if (!string.IsNullOrWhiteSpace(cfg.GetKey(cte.ImageThumbSize)))
                {
                    thumbImageSize = new Dimension(cfg.GetKey(cte.ImageThumbSize));
                }

                lw.GraphicUtils.ImageUtils.Resize(ImageName, largeImageName, largeImageSize.IntWidth, largeImageSize.IntHeight);

                if (!string.IsNullOrWhiteSpace(cfg.GetKey(cte.ImageThumbOption)) && cfg.GetKey(cte.ImageThumbOption) == "Crop")
                {
                    lw.GraphicUtils.ImageUtils.CropImage(ImageName, thumbImageName, thumbImageSize.IntWidth, thumbImageSize.IntHeight, ImageUtils.AnchorPosition.Default);
                }
                else
                {
                    lw.GraphicUtils.ImageUtils.Resize(ImageName, thumbImageName, thumbImageSize.IntWidth, thumbImageSize.IntHeight);
                }
            }
            catch (Exception ex)
            {
                ErrorContext.Add("resize-image", "Unable to resize album image.<br><span class=hid>" + ex.Message + "</span>");
            }

            row.FileName = _ImageName;
            base.UpdateData(Adp, _ds);

            UpdateAlbumModified(AlbumId, DateTime.Now);

            return(row);
        }
示例#6
0
        public bool UpdateAlbum(int AlbumId, string Name, string DisplayName,
                                string Description,
                                bool status, int Sort,
                                bool HasIntroPage, int CategoryId,
                                bool DeleteImage, HttpPostedFile Image, Languages lan, DateTime?AlbumDate)
        {
            AlbumsDS _ds = new AlbumsDS();

            AlbumsDSTableAdapters.PhotoAlbumsTableAdapter adp = new AlbumsDSTableAdapters.PhotoAlbumsTableAdapter();

            DataRow album = this.GetPhotoAlbums(string.Format("Id={0}", AlbumId))[0].Row;

            album["Name"]         = StringUtils.ToURL(DisplayName);
            album["DisplayName"]  = DisplayName;
            album["Description"]  = Description;
            album["Status"]       = status;
            album["Sort"]         = Sort;
            album["HasIntroPage"] = HasIntroPage;
            album["CategoryId"]   = CategoryId;
            album["DateAdded"]    = (DateTime)album["DateAdded"];
            album["DateModified"] = DateTime.Now;
            album["Image"]        = album["Image"].ToString();
            album["Language"]     = (short)lan;
            if (AlbumDate != null)
            {
                album["AlbumDate"] = AlbumDate.Value;
            }

            adp.Update(album);


            string path = WebContext.Server.MapPath("~/" + lw.CTE.Folders.PhotoAlbums);

            path = System.IO.Path.Combine(path, string.Format("Album{0}", album["Id"]));

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

                Directory.CreateDirectory(Path.Combine(path, "Original"));
                Directory.CreateDirectory(Path.Combine(path, "Large"));
                Directory.CreateDirectory(Path.Combine(path, "Thumb"));
            }


            bool del = (DeleteImage || (Image != null && Image.ContentLength > 0)) &&
                       album["Image"].ToString() != "";

            bool updateData = false;

            if (DeleteImage)
            {
                string fileName = Path.Combine(path, album["Image"].ToString());
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }


                fileName = Path.Combine(path, "Large_" + album["Image"].ToString());
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                fileName = Path.Combine(path, "Thumb_" + album["Image"].ToString());
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                album["Image"] = "";
                updateData     = true;
            }

            //if (!DeleteImage && Image != null && Image.ContentLength > 0)
            if (Image != null && Image.ContentLength > 0)
            {
                Config cfg = new Config();

                string fileName = StringUtils.GetFileName(Image.FileName);

                string ImageName      = string.Format("{0}\\{1}", path, fileName);
                string largeImageName = string.Format("{0}\\Large_{1}", path, fileName);
                string thumbImageName = string.Format("{0}\\Thumb_{1}", path, fileName);

                Image.SaveAs(ImageName);

                if (cfg.GetKey("AlbumImage") == "on")
                {
                    try
                    {
                        Dimension largeImageSize = new Dimension(cte.CoverPhotoDefaultSize);
                        Dimension thumbImageSize = new Dimension(cte.CoverPhotoDefaultThumbSize);

                        if (!string.IsNullOrWhiteSpace(cfg.GetKey(cte.CoverPhotoSize)))
                        {
                            largeImageSize = new Dimension(cfg.GetKey(cte.CoverPhotoSize));
                        }
                        if (!string.IsNullOrWhiteSpace(cfg.GetKey(cte.CoverPhotoThumbSize)))
                        {
                            thumbImageSize = new Dimension(cfg.GetKey(cte.CoverPhotoThumbSize));
                        }

                        lw.GraphicUtils.ImageUtils.Resize(ImageName, largeImageName, largeImageSize.IntWidth, largeImageSize.IntHeight);
                        lw.GraphicUtils.ImageUtils.CropImage(ImageName, thumbImageName, thumbImageSize.IntWidth, thumbImageSize.IntHeight, ImageUtils.AnchorPosition.Default);
                    }
                    catch (Exception ex)
                    {
                        ErrorContext.Add("resize-image", "Unable to resize album image.<br><span class=hid>" + ex.Message + "</span>");
                    }
                }

                album["Image"] = fileName;
                updateData     = true;
            }

            if (updateData)
            {
                adp.Update(album);
            }

            return(true);
        }
示例#7
0
        public int AddAlbum(string Name, string DisplayName,
                            string Description,
                            bool status, int Sort,
                            bool HasIntroPage,
                            int CategoryId, HttpPostedFile Image,
                            Languages lan, DateTime?AlbumDate, bool FixedSize)
        {
            AlbumsDS _ds = new AlbumsDS();

            IDataAdapter Adp = base.GetAdapter(cte.PhotoAlbumsAdp);

            AlbumsDS.PhotoAlbumsRow row = _ds.PhotoAlbums.NewPhotoAlbumsRow();

            row.Name         = StringUtils.ToURL(DisplayName);
            row.DisplayName  = DisplayName;
            row.Description  = Description;
            row.Status       = status;
            row.Sort         = Sort;
            row.HasIntroPage = HasIntroPage;
            row.CategoryId   = CategoryId;
            row.DateAdded    = DateTime.Now;
            row.DateModified = DateTime.Now;
            row.Language     = (short)lan;

            if (AlbumDate != null)
            {
                row.AlbumDate = AlbumDate.Value;
            }

            _ds.PhotoAlbums.AddPhotoAlbumsRow(row);
            base.UpdateData(Adp, _ds);

            string path = WebContext.Server.MapPath("~/" + lw.CTE.Folders.PhotoAlbums);

            path = System.IO.Path.Combine(path, string.Format("Album{0}", row.Id));


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

            Directory.CreateDirectory(Path.Combine(path, "Large"));
            Directory.CreateDirectory(Path.Combine(path, "Thumb"));
            Directory.CreateDirectory(Path.Combine(path, "Original"));

            if (Image != null && Image.ContentLength > 0)
            {
                Config cfg = new Config();

                string fileName = StringUtils.GetFileName(Image.FileName);

                string ImageName      = string.Format("{0}\\{1}", path, fileName);
                string largeImageName = string.Format("{0}\\Large_{1}", path, fileName);
                string thumbImageName = string.Format("{0}\\Thumb_{1}", path, fileName);

                Image.SaveAs(ImageName);

                try
                {
                    Dimension largeImageSize = new Dimension(cte.CoverPhotoDefaultSize);
                    Dimension thumbImageSize = new Dimension(cte.CoverPhotoDefaultThumbSize);

                    if (!string.IsNullOrWhiteSpace(cfg.GetKey(cte.CoverPhotoSize)))
                    {
                        largeImageSize = new Dimension(cfg.GetKey(cte.CoverPhotoSize));
                    }
                    if (!string.IsNullOrWhiteSpace(cfg.GetKey(cte.CoverPhotoThumbSize)))
                    {
                        thumbImageSize = new Dimension(cfg.GetKey(cte.CoverPhotoThumbSize));
                    }


                    ////ImageUtils.Resize(ImageName, ImageName, _Width, _Height);
                    //if (FixedSize)
                    //    lw.GraphicUtils.ImageUtils.CreateThumb(ImageName, largeImageName, largeImageSize.IntWidth, largeImageSize.IntHeight, FixedSize);
                    //else
                    //    lw.GraphicUtils.ImageUtils.CreateThumb(ImageName, largeImageName, largeImageSize.IntWidth, largeImageSize.IntHeight);


                    ////TODO: add a parameter to choose between the below
                    ////lw.GraphicUtils.ImageUtils.Resize(ImageName, thumbImageName, Width, Height);
                    //lw.GraphicUtils.ImageUtils.CreateThumb(ImageName, thumbImageName, thumbImageSize.IntWidth, thumbImageSize.IntHeight, FixedSize);

                    lw.GraphicUtils.ImageUtils.Resize(ImageName, largeImageName, largeImageSize.IntWidth, largeImageSize.IntHeight);
                    lw.GraphicUtils.ImageUtils.CropImage(ImageName, thumbImageName, thumbImageSize.IntWidth, thumbImageSize.IntHeight, ImageUtils.AnchorPosition.Default);
                }
                catch (Exception ex)
                {
                    ErrorContext.Add("resize-image", "Unable to resize album image.<br><span class=hid>" + ex.Message + "</span>");
                }


                row.Image = fileName;
                base.UpdateData(Adp, _ds);
            }

            return(row.Id);
        }