コード例 #1
0
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "alpha" || e.CommandName == "NoFilter")
        {
            String value = null;
            switch (e.CommandName)
            {
            case ("alpha"):
            {
                value = string.Format("{0}%", e.CommandArgument);
                break;
            }

            case ("NoFilter"):
            {
                value = "%";
                break;
            }
            }
            ObjectDataSource1.SelectParameters["ProductOptionTitle"].DefaultValue = value;
            ObjectDataSource1.DataBind();
            RadGrid1.Rebind();
        }
        else if (e.CommandName == "QuickUpdate")
        {
            string ProductOptionID, Priority, IsShowOnHomePage, IsHot, IsNew, IsAvailable;
            var    oProductOption = new ProductOption();

            foreach (GridDataItem item in RadGrid1.Items)
            {
                ProductOptionID  = item.GetDataKeyValue("ProductOptionID").ToString();
                Priority         = ((RadNumericTextBox)item.FindControl("txtPriority")).Text.Trim();
                IsShowOnHomePage = ((CheckBox)item.FindControl("chkIsShowOnHomePage")).Checked.ToString();
                IsHot            = ((CheckBox)item.FindControl("chkIsHot")).Checked.ToString();
                IsNew            = ((CheckBox)item.FindControl("chkIsNew")).Checked.ToString();
                IsAvailable      = ((CheckBox)item.FindControl("chkIsAvailable")).Checked.ToString();

                oProductOption.ProductOptionQuickUpdate(
                    ProductOptionID,
                    IsShowOnHomePage,
                    IsHot,
                    IsNew,
                    IsAvailable,
                    Priority
                    );
            }
        }
        else if (e.CommandName == "DeleteSelected")
        {
            string OldImageName;
            var    oProductOption = new ProductOption();

            foreach (GridDataItem item in RadGrid1.SelectedItems)
            {
                OldImageName = ((HiddenField)item.FindControl("hdnImageName")).Value;
                DeleteImage(OldImageName);
            }
        }
        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");
            var oProductOption = new ProductOption();

            string strProductOptionID             = ((HiddenField)row.FindControl("hdnProductOptionID")).Value;
            string strOldImageName                = ((HiddenField)row.FindControl("hdnOldImageName")).Value;
            string strImageName                   = FileImageName.UploadedFiles.Count > 0 ? FileImageName.UploadedFiles[0].GetName() : "";
            string strPriority                    = ((RadNumericTextBox)row.FindControl("txtPriority")).Text.Trim();
            string strMetaTittle                  = ((RadTextBox)row.FindControl("txtMetaTittle")).Text.Trim();
            string strMetaDescription             = ((RadTextBox)row.FindControl("txtMetaDescription")).Text.Trim();
            string strProductOptionTitle          = ((RadTextBox)row.FindControl("txtProductOptionTitle")).Text.Trim();
            string strConvertedProductOptionTitle = Common.ConvertTitle(strProductOptionTitle);
            string strDescription                 = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtDescription")).Content.Trim()));
            string strContent = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtContent")).Content.Trim()));
            string strTag     = ((RadTextBox)row.FindControl("txtTag")).Text.Trim();
            //string strProductOptionCategoryID = ((RadComboBox)row.FindControl("ddlCategory")).SelectedValue;
            string strProductOptionCategoryID = string.IsNullOrEmpty(Request.QueryString["poi"])
                                                    ? ""
                                                    : Request.QueryString["poi"];
            string strIsShowOnHomePage = ((CheckBox)row.FindControl("chkIsShowOnHomePage")).Checked.ToString();
            string strIsHot            = ((CheckBox)row.FindControl("chkIsHot")).Checked.ToString();
            string strIsNew            = ((CheckBox)row.FindControl("chkIsNew")).Checked.ToString();
            string strIsAvailable      = ((CheckBox)row.FindControl("chkIsAvailable")).Checked.ToString();


            if (e.CommandName == "PerformInsert")
            {
                strImageName = oProductOption.ProductOptionInsert(
                    strImageName,
                    strMetaTittle,
                    strMetaDescription,
                    strProductOptionTitle,
                    strConvertedProductOptionTitle,
                    strDescription,
                    strContent,
                    strTag,
                    "",
                    "",
                    "",
                    "",
                    "",
                    "",
                    strProductOptionCategoryID,
                    strIsShowOnHomePage,
                    strIsHot,
                    strIsNew,
                    strIsAvailable,
                    strPriority
                    );

                string strFullPath = "~/res/productoption/" + strImageName;
                if (!string.IsNullOrEmpty(strImageName))
                {
                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    string bgColor = "#ffffff";
                    ResizeCropImage.CreateThumbNailWithBackGroundColor("~/res/productoption/", "~/res/productoption/thumbs/", strImageName, 70, 82, bgColor);
                    ResizeCropImage.ResizeWithBackGroundColor(strFullPath, 550, 650, bgColor);
                    //ResizeCropImage.ResizeByCondition(strFullPath, 800, 800);
                    //ResizeCropImage.CreateThumbNailByCondition("~/res/productoption/", "~/res/productoption/thumbs/", strImageName, 120, 120);
                }
                RadGrid1.Rebind();
            }
            else
            {
                var dsUpdateParam        = ObjectDataSource1.UpdateParameters;
                var strOldImagePath      = Server.MapPath("~/res/productoption/" + strOldImageName);
                var strOldThumbImagePath = Server.MapPath("~/res/productoption/thumbs/" + strOldImageName);

                dsUpdateParam["ProductOptionTitle"].DefaultValue          = strProductOptionTitle;
                dsUpdateParam["ConvertedProductOptionTitle"].DefaultValue = strConvertedProductOptionTitle;
                dsUpdateParam["ImageName"].DefaultValue = strImageName;
                dsUpdateParam["ProductOptionCategoryID"].DefaultValue = strProductOptionCategoryID;
                dsUpdateParam["IsShowOnHomePage"].DefaultValue        = strIsShowOnHomePage;
                dsUpdateParam["IsHot"].DefaultValue       = strIsHot;
                dsUpdateParam["IsNew"].DefaultValue       = strIsNew;
                dsUpdateParam["IsAvailable"].DefaultValue = strIsAvailable;

                if (!string.IsNullOrEmpty(strImageName))
                {
                    if (File.Exists(strOldImagePath))
                    {
                        File.Delete(strOldImagePath);
                    }
                    if (File.Exists(strOldThumbImagePath))
                    {
                        File.Delete(strOldThumbImagePath);
                    }

                    strImageName = (string.IsNullOrEmpty(strConvertedProductOptionTitle) ? "" : strConvertedProductOptionTitle + "-") + strProductOptionID + strImageName.Substring(strImageName.LastIndexOf('.'));

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

                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    string bgColor = "#ffffff";
                    ResizeCropImage.CreateThumbNailWithBackGroundColor("~/res/productoption/", "~/res/productoption/thumbs/", strImageName, 70, 82, bgColor);
                    ResizeCropImage.ResizeWithBackGroundColor(strFullPath, 550, 650, bgColor);
                    //ResizeCropImage.ResizeByCondition(strFullPath, 800, 800);
                    //ResizeCropImage.CreateThumbNailByCondition("~/res/productoption/", "~/res/productoption/thumbs/", strImageName, 120, 120);
                }
            }
        }
        if (e.CommandName == "DeleteImage")
        {
            var oProductOption = new ProductOption();
            var lnkDeleteImage = (LinkButton)e.CommandSource;
            var s = lnkDeleteImage.Attributes["rel"].ToString().Split('#');
            var strProductOptionID = s[0];
            var strImageName       = s[1];

            oProductOption.ProductOptionImageDelete(strProductOptionID);
            DeleteImage(strImageName);
            RadGrid1.Rebind();
        }
    }
コード例 #2
0
    protected void RadListView1_ItemCommand(object sender, RadListViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "PerformInsert")
            {
                var item          = e.ListViewItem;
                var FileImageName = (RadUpload)item.FindControl("FileImageName");

                var strProductName          = ((Label)FormView1.FindControl("lblProductName")).Text.Trim();
                var strConvertedProductName = Common.ConvertTitle(strProductName);
                var strImageName            = FileImageName.UploadedFiles.Count > 0 ? Guid.NewGuid().GetHashCode().ToString("X") + FileImageName.UploadedFiles[0].GetExtension() : "";
                var strTitle         = ((RadTextBox)item.FindControl("txtTitle")).Text.Trim();
                var strDescription   = ((RadTextBox)item.FindControl("txtDescription")).Text.Trim();
                var strTitleEn       = ((RadTextBox)item.FindControl("txtTitleEn")).Text.Trim();
                var strDescriptionEn = ((RadTextBox)item.FindControl("txtDescriptionEn")).Text.Trim();
                var IsAvailable      = ((CheckBox)item.FindControl("chkAddIsAvailable")).Checked.ToString();
                var Priority         = ((RadNumericTextBox)item.FindControl("txtPriority")).Text.Trim();
                var oProductOption   = new ProductOption();

                oProductOption.ProductOptionInsert(
                    strImageName,
                    "",
                    "",
                    strTitle,
                    strConvertedProductName,
                    strDescription,
                    "",
                    "",
                    "",
                    "",
                    strTitleEn,
                    strDescriptionEn,
                    "",
                    "",
                    Request.QueryString["poi"],
                    "1",
                    "0",
                    "0",
                    IsAvailable,
                    "",
                    Priority);

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

                if (!string.IsNullOrEmpty(strImageName))
                {
                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));

                    string bgColor = "#ffffff";
                    ResizeCropImage.CreateThumbNailWithBackGroundColor("~/res/productoption/", "~/res/productoption/thumbs/", strImageName, 95, 96, bgColor);
                    ResizeCropImage.ResizeWithBackGroundColor(strFullPath, 486, 487, bgColor);
                    //ResizeCropImage.ResizeByCondition(strFullPath, 600, 600);
                    //ResizeCropImage.CreateThumbNailByCondition("~/res/productoption/", "~/res/productoption/thumbs/", strImageName, 120, 120);
                }
                RadListView1.InsertItemPosition = RadListViewInsertItemPosition.None;
            }
            else if (e.CommandName == "Update")
            {
                var item          = e.ListViewItem;
                var FileImageName = (RadUpload)item.FindControl("FileImageName");
                var dsUpdateParam = ObjectDataSource1.UpdateParameters;

                var strProductOptionID = ((HiddenField)item.FindControl("hdnProductOptionID")).Value;
                //var strProductName = ((Label)FormView1.FindControl("lblProductName")).Text.Trim();
                //var strConvertedProductName = Common.ConvertTitle(strProductName);
                var strOldImageName            = ((HiddenField)item.FindControl("hdnImageName")).Value;
                var strIsAvailable             = ((CheckBox)item.FindControl("chkAddIsAvailable")).Checked.ToString();
                var strImageName               = FileImageName.UploadedFiles.Count > 0 ? Guid.NewGuid().GetHashCode().ToString("X") + FileImageName.UploadedFiles[0].GetExtension() : "";
                var strProductOptionCategoryID = string.IsNullOrEmpty(Request.QueryString["poi"])
                                                    ? ""
                                                    : Request.QueryString["poi"];
                dsUpdateParam["ImageName"].DefaultValue = !string.IsNullOrEmpty(strImageName) ? strImageName : strOldImageName;
                //dsUpdateParam["ConvertedProductName"].DefaultValue = strConvertedProductName;
                dsUpdateParam["IsAvailable"].DefaultValue             = strIsAvailable;
                dsUpdateParam["ProductOptionCategoryID"].DefaultValue = strProductOptionCategoryID;

                if (!string.IsNullOrEmpty(strImageName))
                {
                    var strOldImagePath      = Server.MapPath("~/res/productoption/" + strOldImageName);
                    var strOldThumbImagePath = Server.MapPath("~/res/productoption/thumbs/" + strOldImageName);

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

                    //strImageName = (string.IsNullOrEmpty(strConvertedProductName) ? "" : strConvertedProductName + "-") + strProductOptionID + strImageName.Substring(strImageName.LastIndexOf('.'));
                    string strFullPath = "~/res/productoption/" + strImageName;

                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    string bgColor = "#ffffff";
                    ResizeCropImage.CreateThumbNailWithBackGroundColor("~/res/productoption/", "~/res/productoption/thumbs/", strImageName, 95, 96, bgColor);
                    ResizeCropImage.ResizeWithBackGroundColor(strFullPath, 486, 487, bgColor);
                    //ResizeCropImage.ResizeByCondition(strFullPath, 600, 600);
                    //ResizeCropImage.CreateThumbNailByCondition("~/res/productoption/", "~/res/productoption/thumbs/", strImageName, 120, 120);
                }
            }
            else if (e.CommandName == "Delete")
            {
                var strOldImageName = ((HiddenField)e.ListViewItem.FindControl("hdnImageName")).Value;
                DeleteImage(strOldImageName);
            }
            else if (e.CommandName == "QuickUpdate")
            {
                string ProductOptionID, Priority, IsAvailable;
                var    oProductOption = new ProductOption();

                foreach (RadListViewDataItem item in RadListView1.Items)
                {
                    ProductOptionID = item.GetDataKeyValue("ProductOptionID").ToString();
                    Priority        = ((RadNumericTextBox)item.FindControl("txtPriority")).Text.Trim();
                    IsAvailable     = ((CheckBox)item.FindControl("chkIsAvailable")).Checked.ToString();

                    oProductOption.ProductOptionQuickUpdate(
                        ProductOptionID,
                        "1",
                        "0",
                        "0",
                        IsAvailable,
                        Priority
                        );
                }
            }
            else if (e.CommandName == "DeleteSelected")
            {
                var    oProductOption = new ProductOption();
                string ProductOptionID, OldImageName;

                foreach (RadListViewDataItem item in RadListView1.Items)
                {
                    var chkSelect = (CheckBox)item.FindControl("chkSelect");

                    if (chkSelect.Checked)
                    {
                        ProductOptionID = item.GetDataKeyValue("ProductOptionID").ToString();
                        OldImageName    = ((HiddenField)item.FindControl("hdnImageName")).Value;

                        DeleteImage(OldImageName);
                        oProductOption.ProductOptionDelete(ProductOptionID);
                    }
                }
            }
            RadListView1.Rebind();
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }