protected void lnkDownOrder_Click(object sender, EventArgs e)
 {
     var lnkDownOrder = (LinkButton)sender;
     var strProductOptionCategoryID = lnkDownOrder.Attributes["rel"];
     var oProductOptionCategory = new ProductOptionCategory();
     oProductOptionCategory.ProductOptionCategoryDownOrder(strProductOptionCategoryID);
     RadGrid1.Rebind();
 }
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "QuickUpdate")
        {
            string ProductOptionCategoryID, IsShowOnMenu, IsShowOnHomePage, IsAvailable;
            var oProductOptionCategory = new ProductOptionCategory();

            foreach (GridDataItem item in RadGrid1.Items)
            {
                ProductOptionCategoryID = item.GetDataKeyValue("ProductOptionCategoryID").ToString();
                IsShowOnMenu = ((CheckBox)item.FindControl("chkIsShowOnMenu")).Checked.ToString();
                IsShowOnHomePage = ((CheckBox)item.FindControl("chkIsShowOnHomePage")).Checked.ToString();
                IsAvailable = ((CheckBox)item.FindControl("chkIsAvailable")).Checked.ToString();

                oProductOptionCategory.ProductOptionCategoryQuickUpdate(
                    ProductOptionCategoryID,
                    IsShowOnMenu,
                    IsShowOnHomePage,
                    IsAvailable
                );
            }
        }
        else if (e.CommandName == "DeleteSelected")
        {
            var oProductOptionCategory = new ProductOptionCategory();
            var errorList = "";

            foreach (GridDataItem item in RadGrid1.SelectedItems)
            {
                var isChildCategoryExist = oProductOptionCategory.ProductOptionCategoryIsChildrenExist(item.GetDataKeyValue("ProductOptionCategoryID").ToString());
                var ProductOptionCategoryName = ((Label)item.FindControl("lblProductOptionCategoryName")).Text;
                if (isChildCategoryExist)
                {
                    errorList += ", " + ProductOptionCategoryName;
                }
                else
                {
                    string strImageName = ((HiddenField)item.FindControl("hdnImageName")).Value;

                    if (!string.IsNullOrEmpty(strImageName))
                    {
                        string strSavePath = Server.MapPath("~/res/productoptioncategory/" + strImageName);
                        if (File.Exists(strSavePath))
                            File.Delete(strSavePath);
                    }
                }
            }
            if (!string.IsNullOrEmpty(errorList))
            {
                e.Canceled = true;
                string strAlertMessage = "Danh mục <b>\"" + errorList.Remove(0, 1).Trim() + "\"</b> đang có danh mục con.<br /> Xin xóa danh mục con trong danh mục này hoặc thiết lập hiển thị = \"không\".";
                lblError.Text = strAlertMessage;
            }
        }
        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 strProductOptionCategoryName = ((RadTextBox)row.FindControl("txtProductOptionCategoryName")).Text.Trim();
            string strProductOptionCategoryNameEn = "";
            string strConvertedProductOptionCategoryName = Common.ConvertTitle(strProductOptionCategoryName);
            string strDescription = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtDescription")).Content.Trim()));
            string strDescriptionEn = "";
            string strContent = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtContent")).Content.Trim()));
            string strContentEn = "";
            string strMetaTitle = ((RadTextBox)row.FindControl("txtMetaTitle")).Text.Trim();
            string strMetaTitleEn = "";
            string strMetaDescription = ((RadTextBox)row.FindControl("txtMetaDescription")).Text.Trim();
            string strMetaDescriptionEn = "";
            string strImageName = FileImageName.UploadedFiles.Count > 0 ? FileImageName.UploadedFiles[0].GetName() : "";
            string strParentID = ((RadComboBox)row.FindControl("ddlParent")).SelectedValue;
            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 strProductID = string.IsNullOrEmpty(Request.QueryString["pi"]) ? "" : Request.QueryString["pi"].ToString();

            var oProductOptionCategory = new ProductOptionCategory();

            if (e.CommandName == "PerformInsert")
            {
                strImageName = oProductOptionCategory.ProductOptionCategoryInsert(
                    strProductOptionCategoryName,
                    strProductOptionCategoryNameEn,
                    strConvertedProductOptionCategoryName,
                    strDescription,
                    strDescriptionEn,
                    strContent,
                    strContentEn,
                    strMetaTitle,
                    strMetaTitleEn,
                    strMetaDescription,
                    strMetaDescriptionEn,
                    strImageName,
                    strParentID,
                    strIsShowOnMenu,
                    strIsShowOnHomePage,
                    strIsAvailable,
                    strProductID
                );

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

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

                dsUpdateParam["ProductOptionCategoryName"].DefaultValue = strProductOptionCategoryName;
                dsUpdateParam["ConvertedProductOptionCategoryName"].DefaultValue = strConvertedProductOptionCategoryName;
                dsUpdateParam["Description"].DefaultValue = strDescription;
                dsUpdateParam["Content"].DefaultValue = strContent;
                dsUpdateParam["IsAvailable"].DefaultValue = strIsAvailable;
                dsUpdateParam["ImageName"].DefaultValue = strImageName;
                dsUpdateParam["ParentID"].DefaultValue = strParentID;
                dsUpdateParam["IsShowOnMenu"].DefaultValue = strIsShowOnMenu;
                dsUpdateParam["IsShowOnHomePage"].DefaultValue = strIsShowOnHomePage;
                dsUpdateParam["IsAvailable"].DefaultValue = strIsAvailable;
                dsUpdateParam["ProductID"].DefaultValue = strProductID;

                if (!string.IsNullOrEmpty(strImageName))
                {
                    var strFullPath = "~/res/productoptioncategory/" + strConvertedProductOptionCategoryName + "-" + strProductOptionCategoryID + strImageName.Substring(strImageName.LastIndexOf('.'));

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

                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    ResizeCropImage.ResizeByCondition(strFullPath, 21, 21);
                }
                RadGrid1.Rebind();
                lstChoosedColor.DataBind();
            }
        }
        if (e.CommandName == "DeleteImage")
        {
            var oProductOptionCategory = new ProductOptionCategory();
            var lnkDeleteImage = (LinkButton)e.CommandSource;
            var s = lnkDeleteImage.Attributes["rel"].ToString().Split('#');
            var strProductOptionCategoryID = s[0];
            var strImageName = s[1];

            oProductOptionCategory.ProductOptionCategoryImageDelete(strProductOptionCategoryID);
            DeleteImage(strImageName);
            RadGrid1.Rebind();
        }
    }