protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "QuickUpdate")
        {
            string VideoCategoryID, Priority, IsShowOnMenu, IsShowOnHomePage, IsAvailable;
            var    oVideoCategory = new VideoCategory();

            foreach (GridDataItem item in RadGrid1.Items)
            {
                VideoCategoryID  = item.GetDataKeyValue("VideoCategoryID").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();

                oVideoCategory.VideoCategoryQuickUpdate(
                    VideoCategoryID,
                    IsShowOnMenu,
                    IsShowOnHomePage,
                    IsAvailable,
                    Priority
                    );
            }
        }
        else if (e.CommandName == "DeleteSelected")
        {
            var    oVideoCategory = new VideoCategory();
            string errorList = "", VideoCategoryName = "";

            foreach (GridDataItem item in RadGrid1.SelectedItems)
            {
                try
                {
                    var VideoCategoryID = item.GetDataKeyValue("VideoCategoryID").ToString();
                    VideoCategoryName = ((Label)item.FindControl("lblVideoCategoryName")).Text;
                    oVideoCategory.VideoCategoryDelete(VideoCategoryID);
                }
                catch (Exception ex)
                {
                    if (ex.Message == ((int)ErrorNumber.ConstraintConflicted).ToString())
                    {
                        errorList += ", " + VideoCategoryName;
                    }
                }
            }
            if (!string.IsNullOrEmpty(errorList))
            {
                e.Canceled = true;
                string strAlertMessage = "Danh mục <b>\"" + errorList.Remove(0, 1).Trim() + " \"</b> đang chứa video.<br /> Xin xóa video trong danh mục này hoặc thiết lập hiển thị = \"không\".";
                lblError.Text = strAlertMessage;
            }
            RadGrid1.Rebind();
        }
        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 strVideoCategoryName          = ((RadTextBox)row.FindControl("txtVideoCategoryName")).Text.Trim();
            string strVideoCategoryNameEn        = ((RadTextBox)row.FindControl("txtVideoCategoryNameEn")).Text.Trim();
            string strConvertedVideoCategoryName = Common.ConvertTitle(strVideoCategoryName);
            string strDescription       = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtDescription")).Content.Trim()));
            string strDescriptionEn     = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtDescriptionEn")).Content.Trim()));
            string strContent           = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtContent")).Content.Trim()));
            string strContentEn         = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtContentEn")).Content.Trim()));
            string strMetaTitle         = ((RadTextBox)row.FindControl("txtMetaTitle")).Text.Trim();
            string strMetaTitleEn       = ((RadTextBox)row.FindControl("txtMetaTitleEn")).Text.Trim();
            string strMetaDescription   = ((RadTextBox)row.FindControl("txtMetaDescription")).Text.Trim();
            string strMetaDescriptionEn = ((RadTextBox)row.FindControl("txtMetaDescriptionEn")).Text.Trim();
            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 oVideoCategory = new VideoCategory();

            if (e.CommandName == "PerformInsert")
            {
                strImageName = oVideoCategory.VideoCategoryInsert(
                    strImageName,
                    strVideoCategoryName,
                    strVideoCategoryNameEn,
                    strConvertedVideoCategoryName,
                    strDescription,
                    strDescriptionEn,
                    strContent,
                    strContentEn,
                    strMetaTitle,
                    strMetaTitleEn,
                    strMetaDescription,
                    strMetaDescriptionEn,
                    strIsShowOnMenu,
                    strIsShowOnHomePage,
                    strIsAvailable,
                    strPriority
                    );

                string strFullPath = "~/res/videocategory/" + strImageName;

                if (!string.IsNullOrEmpty(strImageName))
                {
                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    ResizeCropImage.ResizeByCondition(strFullPath, 40, 40);
                }
                RadGrid1.Rebind();
            }
            else
            {
                var dsUpdateParam      = ObjectDataSource1.UpdateParameters;
                var strVideoCategoryID = row.GetDataKeyValue("VideoCategoryID").ToString();
                var strOldImageName    = ((HiddenField)row.FindControl("hdnImageName")).Value;
                var strOldImagePath    = Server.MapPath("~/res/videocategory/" + strOldImageName);

                dsUpdateParam["VideoCategoryName"].DefaultValue          = strVideoCategoryName;
                dsUpdateParam["VideoCategoryNameEn"].DefaultValue        = strVideoCategoryNameEn;
                dsUpdateParam["ConvertedVideoCategoryName"].DefaultValue = strConvertedVideoCategoryName;
                dsUpdateParam["Description"].DefaultValue      = strDescription;
                dsUpdateParam["DescriptionEn"].DefaultValue    = strDescriptionEn;
                dsUpdateParam["Content"].DefaultValue          = strContent;
                dsUpdateParam["ContentEn"].DefaultValue        = strContentEn;
                dsUpdateParam["ImageName"].DefaultValue        = strImageName;
                dsUpdateParam["IsShowOnMenu"].DefaultValue     = strIsShowOnMenu;
                dsUpdateParam["IsShowOnHomePage"].DefaultValue = strIsShowOnHomePage;
                dsUpdateParam["IsAvailable"].DefaultValue      = strIsAvailable;

                if (!string.IsNullOrEmpty(strImageName))
                {
                    var strFullPath = "~/res/videocategory/" + strConvertedVideoCategoryName + "-" + strVideoCategoryID + strImageName.Substring(strImageName.LastIndexOf('.'));

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

                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    ResizeCropImage.ResizeByCondition(strFullPath, 40, 40);
                }
            }
        }
        if (e.CommandName == "DeleteImage")
        {
            var oVideoCategory = new VideoCategory();
            var lnkDeleteImage = (LinkButton)e.CommandSource;
            var s = lnkDeleteImage.Attributes["rel"].ToString().Split('#');
            var strVideoCategoryID = s[0];
            var strImageName       = s[1];

            oVideoCategory.VideoCategoryImageDelete(strVideoCategoryID);
            DeleteImage(strImageName);
            RadGrid1.Rebind();
        }
    }