protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         var odsPhotoAlbumCategory = new TLLib.PhotoAlbumCategory();
         var dv = odsPhotoAlbumCategory.PhotoAlbumCategorySelectOne(Request.QueryString["lib"]).DefaultView;
         lblName.Text = dv[0]["PhotoAlbumCategoryName"].ToString();
     }
 }
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "QuickUpdate")
        {
            string PhotoAlbumCategoryID, Priority, IsShowOnMenu, IsShowOnHomePage, IsAvailable;
            var oPhotoAlbumCategory = new PhotoAlbumCategory();

            foreach (GridDataItem item in RadGrid1.Items)
            {
                PhotoAlbumCategoryID = item.GetDataKeyValue("PhotoAlbumCategoryID").ToString();
                Priority = ((RadNumericTextBox)item.FindControl("txtPriority")).Text.Trim();
                IsShowOnMenu = ((CheckBox)item.FindControl("chkIsShowOnMenu")).Checked.ToString();
                IsShowOnHomePage = ((CheckBox)item.FindControl("chkIsShowOnHomePage")).Checked.ToString();
                IsAvailable = ((CheckBox)item.FindControl("chkIsAvailable")).Checked.ToString();

                oPhotoAlbumCategory.PhotoAlbumCategoryQuickUpdate(
                    PhotoAlbumCategoryID,
                    IsShowOnMenu,
                    IsShowOnHomePage,
                    IsAvailable,
                    Priority
                );
            }
        }
        else if (e.CommandName == "DeleteSelected")
        {
            var oPhotoAlbum = new PhotoAlbum();

            foreach (GridDataItem item in RadGrid1.SelectedItems)
            {
                string strImageName = ((HiddenField)item.FindControl("hdnImageName")).Value;

                DeleteImage(strImageName);

                var PhotoAlbumCategoryID = item["PhotoAlbumCategoryID"].Text;

                var dtPhotoAlbum = oPhotoAlbum.PhotoAlbumSelectAll("", "", "", PhotoAlbumCategoryID, "", "", "");

                if (dtPhotoAlbum.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtPhotoAlbum.Rows)
                    {
                        strImageName = dr["ImageName"].ToString();
                        DeletePhotoAlbum(strImageName);
                    }
                }
            }
        }
        else if (e.CommandName == "InitInsert" || e.CommandName == "EditSelected" || e.CommandName == "Edit")
        {
            TempImage.Rows.Clear();
        }
        else if (e.CommandName == "PerformInsert" || e.CommandName == "Update")
        {
            var command = e.CommandName;
            var row = command == "PerformInsert" ? (GridEditFormInsertItem)e.Item : (GridEditFormItem)e.Item;
            var FileImageName = (RadUpload)row.FindControl("FileImageName");

            string PhotoAlbumCategoryID = ((HiddenField)row.FindControl("hdnPhotoAlbumCategoryID")).Value;
            string strPhotoAlbumCategoryName = ((RadTextBox)row.FindControl("txtPhotoAlbumCategoryName")).Text.Trim();
            string strPhotoAlbumCategoryNameEn = ((RadTextBox)row.FindControl("txtPhotoAlbumCategoryNameEn")).Text.Trim();
            string strConvertedPhotoAlbumCategoryName = Common.ConvertTitle(strPhotoAlbumCategoryName);
            string strImageName = FileImageName.UploadedFiles.Count > 0 ? FileImageName.UploadedFiles[0].GetName() : "";
            string strIsAvailable = ((CheckBox)row.FindControl("chkIsAvailable")).Checked.ToString();
            string strIsShowOnMenu = ((CheckBox)row.FindControl("chkIsShowOnMenu")).Checked.ToString();
            string strIsShowOnHomePage = ((CheckBox)row.FindControl("chkIsShowOnHomePage")).Checked.ToString();
            string strPriority = ((RadNumericTextBox)row.FindControl("txtPriority")).Text.Trim();

            var oPhotoAlbumCategory = new PhotoAlbumCategory();

            if (e.CommandName == "PerformInsert")
            {
                strImageName = oPhotoAlbumCategory.PhotoAlbumCategoryInsert(
                    strImageName,
                    strPhotoAlbumCategoryName,
                    strPhotoAlbumCategoryNameEn,
                    strConvertedPhotoAlbumCategoryName,
                    strIsShowOnMenu,
                    strIsShowOnHomePage,
                    strIsAvailable,
                    strPriority
                    );
                string strFullPath = "~/res/photoalbumcategory/" + strImageName;

                if (!string.IsNullOrEmpty(strImageName))
                {
                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    ResizeCropImage.ResizeByCondition(strFullPath, 200, 200);
                }

                PhotoAlbumCategoryID = oPhotoAlbumCategory.PhotoAlbumCategoryID;

                //Insert Album's Images
                if (TempImage.Rows.Count > 0)
                {
                    var oPhotoAlbum = new PhotoAlbum();

                    foreach (DataRow dr in TempImage.Rows)
                        oPhotoAlbum.PhotoAlbumInsert(dr["ImageName"].ToString(), "", "", "", "", "", PhotoAlbumCategoryID, "True", "");
                }

                RadGrid1.Rebind();
            }
            else
            {
                var dsUpdateParam = ObjectDataSource1.UpdateParameters;
                var strPhotoAlbumCategoryID = row.GetDataKeyValue("PhotoAlbumCategoryID").ToString();
                var strOldImageName = ((HiddenField)row.FindControl("hdnImageName")).Value;
                var strOldImagePath = Server.MapPath("~/res/photoalbumcategory/" + strOldImageName);

                dsUpdateParam["PhotoAlbumCategoryName"].DefaultValue = strPhotoAlbumCategoryName;
                dsUpdateParam["ConvertedPhotoAlbumCategoryName"].DefaultValue = strConvertedPhotoAlbumCategoryName;
                dsUpdateParam["ImageName"].DefaultValue = strImageName;
                dsUpdateParam["IsShowOnMenu"].DefaultValue = strIsShowOnMenu;
                dsUpdateParam["IsShowOnHomePage"].DefaultValue = strIsShowOnHomePage;
                dsUpdateParam["IsAvailable"].DefaultValue = strIsAvailable;

                if (!string.IsNullOrEmpty(strImageName))
                {
                    var strFullPath = "~/res/photoalbumcategory/" + strConvertedPhotoAlbumCategoryName + "-" + strPhotoAlbumCategoryID + strImageName.Substring(strImageName.LastIndexOf('.'));

                    if (File.Exists(strOldImagePath))
                        File.Delete(strOldImagePath);

                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    ResizeCropImage.ResizeByCondition(strFullPath, 200, 200);
                }
            }
        }
        else if (e.CommandName == "Cancel")
        {
            if (TempImage.Rows.Count > 0)
            {
                foreach (DataRow row in TempImage.Rows)
                {
                    DeletePhotoAlbum(row["ImageName"].ToString());
                }
                TempImage.Rows.Clear();
            }
        }
        else if (e.CommandName == "DeleteImage")
        {
            var oPhotoAlbumCategory = new PhotoAlbumCategory();
            var lnkDeleteImage = (LinkButton)e.CommandSource;
            var s = lnkDeleteImage.Attributes["rel"].ToString().Split('#');
            var strPhotoAlbumCategoryID = s[0];
            var strImageName = s[1];

            oPhotoAlbumCategory.PhotoAlbumCategoryImageDelete(strPhotoAlbumCategoryID);
            DeleteImage(strImageName);
            RadGrid1.Rebind();
        }
    }