예제 #1
0
    protected void FileImageAlbum_FileUploaded(object sender, FileUploadedEventArgs e)
    {
        var FileImageAlbum = (RadAsyncUpload)sender;
        var Parent         = FileImageAlbum.NamingContainer;
        var ProductID      = ((HiddenField)Parent.FindControl("hdnProductID")).Value;
        var RadListView1   = (RadListView)Parent.FindControl("RadListView1");
        var RadListView2   = (RadListView)Parent.FindControl("RadListView2");

        string targetFolder = "~/res/product/album/";
        string newName      = Guid.NewGuid().GetHashCode().ToString("X") + e.File.GetExtension();

        e.File.SaveAs(Server.MapPath(targetFolder + newName));

        ResizeCropImage.ResizeByCondition(targetFolder + newName, 800, 800);
        ResizeCropImage.CreateThumbNailByCondition("~/res/product/album/", "~/res/product/album/thumbs/", newName, 120, 120);

        if (string.IsNullOrEmpty(ProductID))
        {
            TempImage.Rows.Add(new object[] { newName });

            RadListView2.DataSource = TempImage;
            RadListView2.DataBind();
        }
        else
        {
            var oProductImage = new ProductImage();

            oProductImage.ProductImageInsert(newName, "", "", "", "", "", ProductID, "True", "");
            RadListView1.Rebind();
        }
    }
예제 #2
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["ProductName"].DefaultValue = value;
            ObjectDataSource1.DataBind();
            RadGrid1.Rebind();
        }
        else if (e.CommandName == "QuickUpdate")
        {
            string ProductID, Priority, InStock, IsHot, IsNew, IsBestSeller, IsSaleOff, IsShowOnHomePage, IsAvailable;
            var    oProduct = new Product();

            foreach (GridDataItem item in RadGrid1.Items)
            {
                ProductID        = item.GetDataKeyValue("ProductID").ToString();
                Priority         = ((RadNumericTextBox)item.FindControl("txtPriority")).Text.Trim();
                InStock          = ((CheckBox)item.FindControl("chkInStock")).Checked.ToString();
                IsHot            = ((CheckBox)item.FindControl("chkIsHot")).Checked.ToString();
                IsNew            = ((CheckBox)item.FindControl("chkIsNew")).Checked.ToString();
                IsBestSeller     = ((CheckBox)item.FindControl("chkIsBestSeller")).Checked.ToString();
                IsSaleOff        = ((CheckBox)item.FindControl("chkIsSaleOff")).Checked.ToString();
                IsShowOnHomePage = ((CheckBox)item.FindControl("chkIsShowOnHomePage")).Checked.ToString();
                IsAvailable      = ((CheckBox)item.FindControl("chkIsAvailable")).Checked.ToString();

                oProduct.ProductQuickUpdate(
                    ProductID,
                    InStock,
                    IsHot,
                    IsNew,
                    IsBestSeller,
                    IsSaleOff,
                    IsShowOnHomePage,
                    Priority,
                    IsAvailable
                    );
            }
        }
        else if (e.CommandName == "DeleteSelected")
        {
            string OldImageName;
            var    oProduct         = new Product();
            var    oProductImage    = new ProductImage();
            var    oProductDownload = new ProductDownload();

            string errorList = "", ProductName = "";

            foreach (GridDataItem item in RadGrid1.SelectedItems)
            {
                try
                {
                    var ProductID = item.GetDataKeyValue("ProductID").ToString();
                    ProductName = item["ProductName"].Text;

                    oProductImage.ProductImageDeleteByProduct(ProductID);
                    oProductDownload.ProductDownloadDeleteByProduct(ProductID);
                    oProduct.ProductDelete(ProductID);

                    OldImageName = ((HiddenField)item.FindControl("hdnImageName")).Value;
                    DeleteImage(OldImageName);
                }
                catch (Exception ex)
                {
                    lblError.Text = ex.Message;
                    if (ex.Message == ((int)ErrorNumber.ConstraintConflicted).ToString())
                    {
                        errorList += ", " + ProductName;
                    }
                }
            }
            if (!string.IsNullOrEmpty(errorList))
            {
                e.Canceled = true;
                string strAlertMessage = "Sản phẩm <b>\"" + errorList.Remove(0, 1).Trim() + " \"</b> đang chứa thư viện ảnh hoặc file download .<br /> Xin xóa ảnh hoặc file trong sản phẩm này hoặc thiết lập hiển thị = \"không\".";
                lblError.Text = strAlertMessage;
            }
            RadGrid1.Rebind();
        }
        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 ProductID            = ((HiddenField)row.FindControl("hdnProductID")).Value;
            string OldImageName         = ((HiddenField)row.FindControl("hdnOldImageName")).Value;
            string ImageName            = FileImageName.UploadedFiles.Count > 0 ? FileImageName.UploadedFiles[0].GetName() : "";
            string Priority             = ((RadNumericTextBox)row.FindControl("txtPriority")).Text.Trim();
            string MetaTittle           = ((RadTextBox)row.FindControl("txtMetaTittle")).Text.Trim();
            string MetaDescription      = ((RadTextBox)row.FindControl("txtMetaDescription")).Text.Trim();
            string ProductName          = ((RadTextBox)row.FindControl("txtProductName")).Text.Trim();
            string ConvertedProductName = Common.ConvertTitle(ProductName);
            string Description          = ((RadTextBox)row.FindControl("txtDescription")).Text.Trim();//HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtDescription")).Content.Trim()));
            string Content    = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtContent")).Content.Trim()));
            string Price      = ((RadNumericTextBox)row.FindControl("txtPrice")).Text.Trim();
            string OtherPrice = ((RadTextBox)row.FindControl("txtOtherPrice")).Text.Trim();
            string SavePrice  = ((RadNumericTextBox)row.FindControl("txtSavePrice")).Text.Trim();
            string Discount   = ((RadNumericTextBox)row.FindControl("txtDiscount")).Text.Trim();
            string Tag        = ((RadTextBox)row.FindControl("txtTag")).Text.Trim();
            string CategoryID = ((RadComboBox)row.FindControl("ddlCategory")).SelectedValue;
            if ("".Equals(CategoryID))
            {
                CategoryID = "7";
            }
            string ManufacturerID    = ((RadComboBox)row.FindControl("ddlManufacturer")).SelectedValue;
            string OriginID          = ((RadComboBox)row.FindControl("ddlOrigin")).SelectedValue;
            string InStock           = ((CheckBox)row.FindControl("chkInStock")).Checked.ToString();
            string IsHot             = ((CheckBox)row.FindControl("chkIsHot")).Checked.ToString();
            string IsNew             = ((CheckBox)row.FindControl("chkIsNew")).Checked.ToString();
            string IsBestSeller      = ((CheckBox)row.FindControl("chkIsBestSeller")).Checked.ToString();
            string IsSaleOff         = ((CheckBox)row.FindControl("chkIsSaleOff")).Checked.ToString();
            string IsShowOnHomePage  = ((CheckBox)row.FindControl("chkIsShowOnHomePage")).Checked.ToString();
            string IsAvailable       = ((CheckBox)row.FindControl("chkIsAvailable")).Checked.ToString();
            string MetaTittleEn      = ((RadTextBox)row.FindControl("txtMetaTittleEn")).Text.Trim();
            string MetaDescriptionEn = ((RadTextBox)row.FindControl("txtMetaDescriptionEn")).Text.Trim();
            string ProductNameEn     = ((RadTextBox)row.FindControl("txtProductNameEn")).Text.Trim();
            string DescriptionEn     = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtDescriptionEn")).Content.Trim()));
            string ContentEn         = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtContentEn")).Content.Trim()));
            string TagEn             = ((RadTextBox)row.FindControl("txtTagEn")).Text.Trim();

            if (e.CommandName == "PerformInsert")
            {
                var oProduct = new Product();

                ImageName = oProduct.ProductInsert(
                    ImageName,
                    MetaTittle,
                    MetaDescription,
                    ProductName,
                    ConvertedProductName,
                    Description,
                    Content,
                    Tag,
                    MetaTittleEn,
                    MetaDescriptionEn,
                    ProductNameEn,
                    DescriptionEn,
                    ContentEn,
                    TagEn,
                    Price,
                    OtherPrice,
                    SavePrice,
                    Discount,
                    CategoryID,
                    ManufacturerID,
                    OriginID,
                    InStock,
                    IsHot,
                    IsNew,
                    IsBestSeller,
                    IsSaleOff,
                    IsShowOnHomePage,
                    Priority,
                    IsAvailable
                    );

                ProductID = oProduct.ProductID;

                string strFullPath = "~/res/product/" + ImageName;
                if (!string.IsNullOrEmpty(ImageName))
                {
                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    //ResizeCropImage.ResizeByCondition(strFullPath, 277, 230);
                    ResizeCropImage.CreateThumbNailByCondition("~/res/product/", "~/res/product/thumbs/", ImageName, 120, 120);
                }

                if (TempImage.Rows.Count > 0)
                {
                    var oProductImage = new ProductImage();

                    foreach (DataRow dr in TempImage.Rows)
                    {
                        oProductImage.ProductImageInsert(dr["ImageName"].ToString(), "", "", "", "", "", ProductID, "True", "");
                    }
                }

                RadGrid1.Rebind();
            }
            else
            {
                var dsUpdateParam        = ObjectDataSource1.UpdateParameters;
                var strOldImagePath      = Server.MapPath("~/res/product/" + OldImageName);
                var strOldThumbImagePath = Server.MapPath("~/res/product/thumbs/" + OldImageName);

                dsUpdateParam["ConvertedProductName"].DefaultValue = ConvertedProductName;
                dsUpdateParam["ImageName"].DefaultValue            = ImageName;
                dsUpdateParam["CategoryID"].DefaultValue           = CategoryID;
                dsUpdateParam["ManufacturerID"].DefaultValue       = ManufacturerID;
                dsUpdateParam["OriginID"].DefaultValue             = OriginID;
                dsUpdateParam["InStock"].DefaultValue      = InStock;
                dsUpdateParam["IsHot"].DefaultValue        = IsHot;
                dsUpdateParam["IsNew"].DefaultValue        = IsNew;
                dsUpdateParam["IsBestSeller"].DefaultValue = IsBestSeller;
                dsUpdateParam["IsSaleOff"].DefaultValue    = IsSaleOff;

                dsUpdateParam["IsShowOnHomePage"].DefaultValue = IsShowOnHomePage;
                dsUpdateParam["IsAvailable"].DefaultValue      = IsAvailable;

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

                    ImageName = (string.IsNullOrEmpty(ConvertedProductName) ? "" : ConvertedProductName + "-") + ProductID + ImageName.Substring(ImageName.LastIndexOf('.'));

                    string strFullPath = "~/res/product/" + ImageName;

                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    //ResizeCropImage.ResizeByCondition(strFullPath, 277, 230);
                    ResizeCropImage.CreateThumbNailByCondition("~/res/product/", "~/res/product/thumbs/", ImageName, 120, 120);
                }
            }
        }
        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 oProduct       = new Product();
            var lnkDeleteImage = (LinkButton)e.CommandSource;
            var s            = lnkDeleteImage.Attributes["rel"].ToString().Split('#');
            var strProductID = s[0];
            var ImageName    = s[1];

            oProduct.ProductImageDelete(strProductID);
            DeleteImage(ImageName);
            RadGrid1.Rebind();
        }
    }
예제 #3
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         = ((TextBox)item.FindControl("txtTitle")).Text.Trim();
                var strDescription   = ((TextBox)item.FindControl("txtDescription")).Text.Trim();
                var strTitleEn       = ((TextBox)item.FindControl("txtTitleEn")).Text.Trim();
                var strDescriptionEn = ((TextBox)item.FindControl("txtDescriptionEn")).Text.Trim();
                var IsAvailable      = ((CheckBox)item.FindControl("chkAddIsAvailable")).Checked.ToString();
                var Priority         = ((RadNumericTextBox)item.FindControl("txtPriority")).Text.Trim();
                var oProductImage    = new ProductImage();

                oProductImage.ProductImageInsert(
                    strImageName,
                    strConvertedProductName,
                    strTitle,
                    strDescription,
                    strTitleEn,
                    strDescriptionEn,
                    Request.QueryString["PI"],
                    IsAvailable,
                    Priority);

                string strFullPath = "~/res/product/album/" + strImageName;

                if (!string.IsNullOrEmpty(strImageName))
                {
                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    ResizeCropImage.ResizeByCondition(strFullPath, 700, 445);
                    ResizeCropImage.CreateThumbNailByCondition("~/res/product/album/", "~/res/product/album/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 strProductImageID       = ((HiddenField)e.ListViewItem.FindControl("hdnProductImageID")).Value;
                var strProductName          = ((Label)FormView1.FindControl("lblProductName")).Text.Trim();
                var strConvertedProductName = Common.ConvertTitle(strProductName);
                var strOldImageName         = ((HiddenField)e.ListViewItem.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() : "";

                dsUpdateParam["ImageName"].DefaultValue            = !string.IsNullOrEmpty(strImageName) ? strImageName : strOldImageName;
                dsUpdateParam["ConvertedProductName"].DefaultValue = strConvertedProductName;
                dsUpdateParam["IsAvailable"].DefaultValue          = strIsAvailable;

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

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

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

                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    ResizeCropImage.ResizeByCondition(strFullPath, 700, 445);
                    ResizeCropImage.CreateThumbNailByCondition("~/res/product/album/", "~/res/product/album/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 ProductImageID, Priority, IsAvailable;
                var    oProductImage = new ProductImage();

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

                    oProductImage.ProductImageQuickUpdate(
                        ProductImageID,
                        IsAvailable,
                        Priority
                        );
                }
            }
            else if (e.CommandName == "DeleteSelected")
            {
                var    oProductImage = new ProductImage();
                string ProductImageID, OldImageName;

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

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

                        DeleteImage(OldImageName);
                        oProductImage.ProductImageDelete(ProductImageID);
                    }
                }
            }
            RadListView1.Rebind();
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }