protected void btnSendEmail_Click(object sender, EventArgs e)
    {
        lblSucess.Text = "";
        var    dvEmail     = (OdsNewsletter.Select() as DataView);
        string strHost     = "tranlegroup.com";
        int    iPort       = 25;
        string strMailFrom = "*****@*****.**";
        string strPassword = "******";
        string strMailTo   = (from DataRowView drv in dvEmail select drv["Email"].ToString()).ToList <string>().Aggregate((a, b) => a + ',' + b);
        string strCC       = "";
        string strSubject  = txtSubject.Text.Trim();
        string strBody     = FCKEditorFix.Fix(txtBody.Content.Trim());
        bool   bEnableSsl  = false;

        TLLib.Common.SendMail(
            strHost,
            iPort,
            strMailFrom,
            strPassword,
            strMailTo,
            strCC,
            strSubject,
            strBody,
            bEnableSsl
            );

        lblSucess.Text = "Email has been send.";
    }
    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, 26, 26);
                }
                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, 26, 26);
                }
                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();
        }
    }
    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["CompanyName"].DefaultValue = value;
            ObjectDataSource1.DataBind();
            RadGrid1.Rebind();
        }
        else if (e.CommandName == "QuickUpdate")
        {
            string AdsBannerID, Priority, IsAvailable;
            var    oAdsBanner = new AdsBanner();

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

                oAdsBanner.AdsBannerQuickUpdate(
                    AdsBannerID,
                    Priority,
                    IsAvailable
                    );
            }
        }
        else if (e.CommandName == "DeleteSelected")
        {
            var oAdsBanner = new AdsBanner();

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

                if (!string.IsNullOrEmpty(strFileName))
                {
                    string strSavePath = Server.MapPath("~/res/advertisement/" + strFileName);
                    if (File.Exists(strSavePath))
                    {
                        File.Delete(strSavePath);
                    }
                }
            }
        }
        else if (e.CommandName == "PerformInsert" || e.CommandName == "Update")
        {
            var command      = e.CommandName;
            var row          = command == "PerformInsert" ? (GridEditFormInsertItem)e.Item : (GridEditFormItem)e.Item;
            var FileFileName = (RadUpload)row.FindControl("FileFileName");
            var dpFromDate   = (RadDatePicker)row.FindControl("dpFromDate");
            var dpToDate     = (RadDatePicker)row.FindControl("dpToDate");

            string strCompanyName = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtCompanyName")).Content.Trim()));//((TextBox)row.FindControl("txtCompanyName")).Text.Trim();
            //string strTitle = ((TextBox)row.FindControl("txtTitle")).Text.Trim();
            //string strDescription = ((TextBox)row.FindControl("txtDescription")).Text.Trim();
            string strConvertedAdsBannerName = Common.ConvertTitle(strCompanyName);
            string strFileName      = FileFileName.UploadedFiles.Count > 0 ? FileFileName.UploadedFiles[0].GetName() : "";
            string strIsAvailable   = ((CheckBox)row.FindControl("chkIsAvailable")).Checked.ToString();
            string strPriority      = ((RadNumericTextBox)row.FindControl("txtPriority")).Text.Trim();
            string strFromDate      = dpFromDate.SelectedDate.HasValue ? dpFromDate.SelectedDate.Value.ToString("MM/dd/yyyy") : "";
            string strToDate        = dpToDate.SelectedDate.HasValue ? dpToDate.SelectedDate.Value.ToString("MM/dd/yyyy") : "";
            string strAdsCategoryID = "10";// ((RadComboBox)row.FindControl("ddlCategory")).SelectedValue;
            string strWebsite       = ((TextBox)row.FindControl("txtWebsite")).Text.Trim();
            double ratio            = 0;

            if (!string.IsNullOrEmpty(strFileName))
            {
                string strTempPath = Server.MapPath(FileFileName.TargetFolder + strFileName);
                if (IsImageFormat(strFileName))
                {
                    System.Drawing.Image img = System.Drawing.Image.FromFile(strTempPath);
                    ratio = (double)img.Width / (img.Height == 0 ? 1 : img.Height);
                    img.Dispose();
                }
                else
                {
                    SwfParser swfParser = new SwfParser();
                    Rectangle rectangle = swfParser.GetDimensions(strTempPath);
                    ratio = (double)rectangle.Width / (rectangle.Height == 0 ? 1 : rectangle.Height);
                }
                string[] files = Directory.GetFiles(Server.MapPath(FileFileName.TargetFolder));

                foreach (string filePath in files)
                {
                    File.Delete(filePath);
                }
            }

            var oAdsBanner = new AdsBanner();

            if (e.CommandName == "PerformInsert")
            {
                strFileName = oAdsBanner.AdsBannerInsert(
                    strFileName,
                    strConvertedAdsBannerName,
                    strAdsCategoryID,
                    strCompanyName,
                    strWebsite,
                    strFromDate,
                    strToDate,
                    strPriority,
                    strIsAvailable,
                    ratio == 0 ? "" : ratio.ToString().Replace(',', '.')
                    );

                string strFullPath = "~/res/advertisement/" + strFileName;

                if (!string.IsNullOrEmpty(strFileName))
                {
                    FileFileName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    if (IsImageFormat(strFileName))
                    {
                        //ResizeCropImage.ResizeByCondition(strFullPath, 800, 800);
                    }
                }
                RadGrid1.Rebind();
            }
            else
            {
                var dsUpdateParam   = ObjectDataSource1.UpdateParameters;
                var strAdsBannerID  = row.GetDataKeyValue("AdsBannerID").ToString();
                var strOldFileName  = ((HiddenField)row.FindControl("hdnFileName")).Value;
                var strOldImagePath = Server.MapPath("~/res/advertisement/" + strOldFileName);

                dsUpdateParam["FileName"].DefaultValue = strFileName;
                dsUpdateParam["ConvertedAdsBannerName"].DefaultValue = strConvertedAdsBannerName;
                dsUpdateParam["AdsCategoryID"].DefaultValue          = strAdsCategoryID;
                dsUpdateParam["FromDate"].DefaultValue    = strFromDate;
                dsUpdateParam["ToDate"].DefaultValue      = strToDate;
                dsUpdateParam["IsAvailable"].DefaultValue = strIsAvailable;
                dsUpdateParam["Ratio"].DefaultValue       = ratio == 0 ? "" : ratio.ToString().Replace(',', '.');

                if (!string.IsNullOrEmpty(strFileName))
                {
                    var strFullPath = "~/res/advertisement/" + (string.IsNullOrEmpty(strConvertedAdsBannerName) ? "" : strConvertedAdsBannerName + "-") + strAdsBannerID + strFileName.Substring(strFileName.LastIndexOf('.'));

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

                    FileFileName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    if (IsImageFormat(strFileName))
                    {
                        //ResizeCropImage.ResizeByCondition(strFullPath, 654, 654);
                    }
                }
            }
        }
        if (e.CommandName == "DeleteImage")
        {
            var oAdsBanner     = new AdsBanner();
            var lnkDeleteImage = (LinkButton)e.CommandSource;
            var s = lnkDeleteImage.Attributes["rel"].ToString().Split('#');
            var strAdsBannerID = s[0];
            var strFileName    = s[1];

            oAdsBanner.AdsBannerDelete(strAdsBannerID);
            DeleteImage(strFileName);
            RadGrid1.Rebind();
        }
    }
Esempio n. 4
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();
        }
    }
Esempio n. 5
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["ArticleTitle"].DefaultValue = value;
            ObjectDataSource1.DataBind();
            RadGrid1.Rebind();
        }
        else if (e.CommandName == "QuickUpdate")
        {
            string ArticleID, Priority, IsShowOnHomePage, IsHot, IsNew, IsAvailable;
            var    oArticle = new Article();

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

                oArticle.ArticleQuickUpdate(
                    ArticleID,
                    IsShowOnHomePage,
                    IsHot,
                    IsNew,
                    IsAvailable,
                    Priority
                    );
            }
        }
        else if (e.CommandName == "DeleteSelected")
        {
            string OldImageName;
            var    oArticle = new Article();

            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 oArticle      = new Article();

            string strArticleID             = ((HiddenField)row.FindControl("hdnArticleID")).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            = ((TextBox)row.FindControl("txtMetaTittle")).Text.Trim();
            string strMetaDescription       = ((TextBox)row.FindControl("txtMetaDescription")).Text.Trim();
            string strArticleTitle          = ((TextBox)row.FindControl("txtArticleTitle")).Text.Trim();
            string strConvertedArticleTitle = Common.ConvertTitle(strArticleTitle);
            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               = ((TextBox)row.FindControl("txtTag")).Text.Trim();
            string strArticleCategoryID = "1";// ((RadComboBox)row.FindControl("ddlCategory")).SelectedValue;
            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();
            string strMetaTittleEn      = ((TextBox)row.FindControl("txtMetaTittleEn")).Text.Trim();
            string strMetaDescriptionEn = ((TextBox)row.FindControl("txtMetaDescriptionEn")).Text.Trim();
            string strArticleTitleEn    = ((TextBox)row.FindControl("txtArticleTitleEn")).Text.Trim();
            string strDescriptionEn     = ((RadEditor)row.FindControl("txtDescriptionEn")).Content.Trim();
            string strContentEn         = ((RadEditor)row.FindControl("txtContentEn")).Content.Trim();
            string strTagEn             = ((TextBox)row.FindControl("txtTagEn")).Text.Trim();


            if (e.CommandName == "PerformInsert")
            {
                strImageName = oArticle.ArticleInsert(
                    strImageName,
                    strMetaTittle,
                    strMetaDescription,
                    strArticleTitle,
                    strConvertedArticleTitle,
                    strDescription,
                    strContent,
                    strTag,
                    strMetaTittleEn,
                    strMetaDescriptionEn,
                    strArticleTitleEn,
                    strDescriptionEn,
                    strContentEn,
                    strTagEn,
                    strArticleCategoryID,
                    strIsShowOnHomePage,
                    strIsHot,
                    strIsNew,
                    strIsAvailable,
                    strPriority
                    );

                string strFullPath = "~/res/article/" + strImageName;
                if (!string.IsNullOrEmpty(strImageName))
                {
                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    //ResizeCropImage.ResizeByCondition(strFullPath, 800, 800);
                    ResizeCropImage.CreateThumbNailByCondition("~/res/article/", "~/res/article/thumbs/", strImageName, 120, 120);
                }
                RadGrid1.Rebind();
            }
            else
            {
                var dsUpdateParam        = ObjectDataSource1.UpdateParameters;
                var strOldImagePath      = Server.MapPath("~/res/article/" + strOldImageName);
                var strOldThumbImagePath = Server.MapPath("~/res/article/thumbs/" + strOldImageName);

                dsUpdateParam["ArticleTitle"].DefaultValue          = strArticleTitle;
                dsUpdateParam["ConvertedArticleTitle"].DefaultValue = strConvertedArticleTitle;
                dsUpdateParam["ImageName"].DefaultValue             = strImageName;
                dsUpdateParam["ArticleCategoryID"].DefaultValue     = strArticleCategoryID;
                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(strConvertedArticleTitle) ? "" : strConvertedArticleTitle + "-") + strArticleID + strImageName.Substring(strImageName.LastIndexOf('.'));

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

                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    //ResizeCropImage.ResizeByCondition(strFullPath, 800, 800);
                    ResizeCropImage.CreateThumbNailByCondition("~/res/article/", "~/res/article/thumbs/", strImageName, 120, 120);
                }
            }
        }
        if (e.CommandName == "DeleteImage")
        {
            var oArticle       = new Article();
            var lnkDeleteImage = (LinkButton)e.CommandSource;
            var s            = lnkDeleteImage.Attributes["rel"].ToString().Split('#');
            var strArticleID = s[0];
            var strImageName = s[1];

            oArticle.ArticleImageDelete(strArticleID);
            DeleteImage(strImageName);
            RadGrid1.Rebind();
        }
    }
Esempio n. 6
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["ProjectTitle"].DefaultValue = value;
            ObjectDataSource1.DataBind();
            RadGrid1.Rebind();
        }
        else if (e.CommandName == "QuickUpdate")
        {
            string ProjectID, Priority, IsShowOnHomePage, IsAvailable;
            var    oProject = new Project();

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

                oProject.ProjectQuickUpdate(
                    ProjectID,
                    IsShowOnHomePage,
                    IsAvailable,
                    Priority
                    );
            }
        }
        else if (e.CommandName == "DeleteSelected")
        {
            string OldImageName;
            var    oProject = new Project();

            string errorList = "", ProjectName = "";

            foreach (GridDataItem item in RadGrid1.SelectedItems)
            {
                try
                {
                    var ProjectID = item.GetDataKeyValue("ProjectID").ToString();
                    ProjectName = item["ProjectTitle"].Text;
                    oProject.ProjectDelete(ProjectID);

                    OldImageName = ((HiddenField)item.FindControl("hdnImageName")).Value;
                    DeleteImage(OldImageName);
                }
                catch (Exception ex)
                {
                    lblError.Text = ex.Message;
                    if (ex.Message == ((int)ErrorNumber.ConstraintConflicted).ToString())
                    {
                        errorList += ", " + ProjectName;
                    }
                }
            }
            if (!string.IsNullOrEmpty(errorList))
            {
                e.Canceled = true;
                string strAlertMessage = "Dự án <b>\"" + errorList.Remove(0, 1).Trim() + " \"</b> đang chứa thư viện ảnh, file download hoặc video .<br /> Xin xóa ảnh, file download hoặc video trong dự án 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 ProjectID             = ((HiddenField)row.FindControl("hdnProjectID")).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            = ((TextBox)row.FindControl("txtMetaTittle")).Text.Trim();
            string MetaDescription       = ((TextBox)row.FindControl("txtMetaDescription")).Text.Trim();
            string ProjectTitle          = ((TextBox)row.FindControl("txtProjectTitle")).Text.Trim();
            string ConvertedProjectTitle = Common.ConvertTitle(ProjectTitle);
            string Description           = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtDescription")).Content.Trim()));
            string Content           = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtContent")).Content.Trim()));
            string Tag               = ((TextBox)row.FindControl("txtTag")).Text.Trim();
            string ProjectCategoryID = ((RadComboBox)row.FindControl("ddlProjectCategory")).SelectedValue;
            string IsShowOnHomePage  = ((CheckBox)row.FindControl("chkIsShowOnHomePage")).Checked.ToString();
            string IsAvailable       = ((CheckBox)row.FindControl("chkIsAvailable")).Checked.ToString();

            string MetaTittleEn      = ((TextBox)row.FindControl("txtMetaTittleEn")).Text.Trim();
            string MetaDescriptionEn = ((TextBox)row.FindControl("txtMetaDescriptionEn")).Text.Trim();
            string ProjectTitleEn    = ((TextBox)row.FindControl("txtProjectTitleEn")).Text.Trim();
            string DescriptionEn     = ((RadEditor)row.FindControl("txtDescriptionEn")).Content.Trim();
            string ContentEn         = ((RadEditor)row.FindControl("txtContentEn")).Content.Trim();
            string TagEn             = ((TextBox)row.FindControl("txtTagEn")).Text.Trim();
            if (e.CommandName == "PerformInsert")
            {
                var oProject = new Project();

                ImageName = oProject.ProjectInsert(
                    ImageName,
                    MetaTittle,
                    MetaDescription,
                    ProjectTitle,
                    ConvertedProjectTitle,
                    Description,
                    Content,
                    Tag,
                    MetaTittleEn,
                    MetaDescriptionEn,
                    ProjectTitleEn,
                    DescriptionEn,
                    ContentEn,
                    TagEn,
                    ProjectCategoryID,
                    IsShowOnHomePage,
                    IsAvailable,
                    Priority
                    );

                string strFullPath = "~/res/project/" + ImageName;
                if (!string.IsNullOrEmpty(ImageName))
                {
                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    //ResizeCropImage.ResizeByCondition(strFullPath, 800, 800);
                    ResizeCropImage.CreateThumbNailByCondition("~/res/project/", "~/res/project/thumbs/", ImageName, 120, 120);
                }
                RadGrid1.Rebind();
            }
            else
            {
                var dsUpdateParam        = ObjectDataSource1.UpdateParameters;
                var strOldImagePath      = Server.MapPath("~/res/project/" + OldImageName);
                var strOldThumbImagePath = Server.MapPath("~/res/project/thumbs/" + OldImageName);

                dsUpdateParam["ConvertedProjectTitle"].DefaultValue = ConvertedProjectTitle;
                dsUpdateParam["ImageName"].DefaultValue             = ImageName;
                dsUpdateParam["ProjectCategoryID"].DefaultValue     = ProjectCategoryID;
                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(ConvertedProjectTitle) ? "" : ConvertedProjectTitle + "-") + ProjectID + ImageName.Substring(ImageName.LastIndexOf('.'));

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

                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    //ResizeCropImage.ResizeByCondition(strFullPath, 800, 800);
                    ResizeCropImage.CreateThumbNailByCondition("~/res/project/", "~/res/project/thumbs/", ImageName, 120, 120);
                }
            }
        }
        if (e.CommandName == "DeleteImage")
        {
            var oProject       = new Project();
            var lnkDeleteImage = (LinkButton)e.CommandSource;
            var s            = lnkDeleteImage.Attributes["rel"].ToString().Split('#');
            var strProjectID = s[0];
            var ImageName    = s[1];

            oProject.ProjectImageDelete(strProjectID);
            DeleteImage(ImageName);
            RadGrid1.Rebind();
        }
    }
Esempio n. 7
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["ManufacturerName"].DefaultValue = value;
            ObjectDataSource1.DataBind();
            RadGrid1.Rebind();
        }
        else if (e.CommandName == "QuickUpdate")
        {
            string ManufacturerID, Priority, IsAvailable;
            var    oManufacturer = new Manufacturer1();

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

                oManufacturer.ManufacturerQuickUpdate(
                    ManufacturerID,
                    IsAvailable,
                    Priority
                    );
            }
        }
        else if (e.CommandName == "DeleteSelected")
        {
            var oManufacturer = new Manufacturer1();

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

                if (!string.IsNullOrEmpty(strManufacturerImage))
                {
                    string strSavePath = Server.MapPath("~/res/manufacturer/" + strManufacturerImage);
                    if (File.Exists(strSavePath))
                    {
                        File.Delete(strSavePath);
                    }
                }
            }
        }
        else if (e.CommandName == "PerformInsert" || e.CommandName == "Update")
        {
            var command = e.CommandName;
            var row     = command == "PerformInsert" ? (GridEditFormInsertItem)e.Item : (GridEditFormItem)e.Item;
            var FileManufacturerImage = (RadUpload)row.FindControl("FileManufacturerImage");

            string strManufacturerName          = ((TextBox)row.FindControl("txtManufacturerName")).Text.Trim();
            string strManufacturerNameEn        = ((TextBox)row.FindControl("txtManufacturerNameEn")).Text.Trim();
            string strConvertedManufacturerName = Common.ConvertTitle(strManufacturerName);
            string strManufacturerImage         = FileManufacturerImage.UploadedFiles.Count > 0 ? FileManufacturerImage.UploadedFiles[0].GetName() : "";
            string strIsAvailable = ((CheckBox)row.FindControl("chkIsAvailable")).Checked.ToString();
            string strPriority    = ((RadNumericTextBox)row.FindControl("txtPriority")).Text.Trim();
            string strProductID   = string.IsNullOrEmpty(Request.QueryString["pi"]) ? "" : Request.QueryString["pi"];
            string strContent     = FCKEditorFix.Fix(((RadEditor)row.FindControl("txtContent")).Content.Trim());
            string strContentEn   = FCKEditorFix.Fix(((RadEditor)row.FindControl("txtContentEn")).Content.Trim());

            var oManufacturer = new Manufacturer1();

            if (e.CommandName == "PerformInsert")
            {
                strManufacturerImage = oManufacturer.ManufacturerInsert(
                    strManufacturerName,
                    strManufacturerNameEn,
                    strConvertedManufacturerName,
                    strManufacturerImage,
                    strIsAvailable,
                    strPriority,
                    strProductID,
                    strContent,
                    strContentEn
                    );
                string strFullPath = "~/res/manufacturer/" + strManufacturerImage;

                if (!string.IsNullOrEmpty(strManufacturerImage))
                {
                    FileManufacturerImage.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    //string bgColor = "#ffffff";
                    //ResizeCropImage.ResizeWithBackGroundColor(strFullPath, 190, 120, bgColor);
                    //ResizeCropImage.ResizeByWidth(strFullPath, 180);
                    ResizeCropImage.ResizeByCondition(strFullPath, 229, 84);
                }
                RadGrid1.Rebind();
            }
            else
            {
                var dsUpdateParam           = ObjectDataSource1.UpdateParameters;
                var strManufacturerID       = row.GetDataKeyValue("ManufacturerID").ToString();
                var strOldManufacturerImage = ((HiddenField)row.FindControl("hdnManufacturerImage")).Value;
                var strOldImagePath         = Server.MapPath("~/res/manufacturer/" + strOldManufacturerImage);

                dsUpdateParam["ManufacturerName"].DefaultValue          = strManufacturerName;
                dsUpdateParam["ManufacturerNameEn"].DefaultValue        = strManufacturerNameEn;
                dsUpdateParam["ConvertedManufacturerName"].DefaultValue = strConvertedManufacturerName;
                dsUpdateParam["ManufacturerImage"].DefaultValue         = strManufacturerImage;
                dsUpdateParam["IsAvailable"].DefaultValue = strIsAvailable;
                dsUpdateParam["ProductID"].DefaultValue   = strProductID;

                if (!string.IsNullOrEmpty(strManufacturerImage))
                {
                    var strFullPath = "~/res/manufacturer/" + strConvertedManufacturerName + "-" + strManufacturerID + strManufacturerImage.Substring(strManufacturerImage.LastIndexOf('.'));

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

                    FileManufacturerImage.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    //string bgColor = "#ffffff";
                    //ResizeCropImage.ResizeWithBackGroundColor(strFullPath, 180, 120, bgColor);
                    ResizeCropImage.ResizeByCondition(strFullPath, 229, 84);
                    //ResizeCropImage.ResizeByWidth(strFullPath, 180);
                }
            }
        }
        if (e.CommandName == "DeleteImage")
        {
            var oManufacturer  = new Manufacturer1();
            var lnkDeleteImage = (LinkButton)e.CommandSource;
            var s = lnkDeleteImage.Attributes["rel"].ToString().Split('#');
            var strManufacturerID    = s[0];
            var strManufacturerImage = s[1];

            oManufacturer.ManufacturerImageDelete(strManufacturerID);
            DeleteImage(strManufacturerImage);
            RadGrid1.Rebind();
        }
    }
    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();
        }
    }
Esempio n. 9
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["Title"].DefaultValue = value;
            ObjectDataSource1.DataBind();
            RadGrid1.Rebind();
        }
        else if (e.CommandName == "QuickUpdate")
        {
            string CommentID, Priority, IsAvailable, IsApproved;
            var    oComment = new Comment();

            foreach (GridDataItem item in RadGrid1.Items)
            {
                CommentID   = item.GetDataKeyValue("CommentID").ToString();
                Priority    = ((RadNumericTextBox)item.FindControl("txtPriority")).Text.Trim();
                IsApproved  = ((CheckBox)item.FindControl("chkIsApproved")).Checked.ToString();
                IsAvailable = ((CheckBox)item.FindControl("chkIsAvailable")).Checked.ToString();

                oComment.CommentQuickUpdate(
                    CommentID,
                    IsApproved,
                    IsAvailable,
                    Priority
                    );
            }
        }
        //else if (e.CommandName == "DeleteSelected")
        //{
        //    string OldImageName;
        //    var oComment = new Comment();

        //    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 oComment      = new Comment();

            string strCommentID = ((HiddenField)row.FindControl("hdnCommentID")).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 strTitle = ((Label)row.FindControl("lblTitle")).Text.Trim();
            string strTitle    = ((TextBox)row.FindControl("txtTitle")).Text.Trim();
            string strTitleEn  = ((TextBox)row.FindControl("txtTitleEn")).Text.Trim();
            string strUserName = ((TextBox)row.FindControl("txtUserName")).Text.Trim();
            string strPhone    = ((TextBox)row.FindControl("txtPhone")).Text.Trim();
            string strEmail    = ((TextBox)row.FindControl("txtEmail")).Text.Trim();
            string strConvertedCommentTitle = Common.ConvertTitle(strTitle);
            string strContent     = ((TextBox)row.FindControl("txtContent")).Text.Trim();
            string strContentEn   = ((TextBox)row.FindControl("txtContentEn")).Text.Trim();
            string strAnswer      = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtAnswer")).Content.Trim()));
            string strAnswerEn    = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtAnswerEn")).Content.Trim()));
            string strIsAvailable = ((CheckBox)row.FindControl("chkIsAvailable")).Checked.ToString();
            string strIsApproved  = ((CheckBox)row.FindControl("chkIsApproved")).Checked.ToString();


            if (e.CommandName == "PerformInsert")
            {
                oComment.CommentInsert(
                    strUserName,
                    "",
                    strTitle,
                    strTitleEn,
                    strPhone,
                    strEmail,
                    strContent,
                    strContentEn,
                    strAnswer,
                    strAnswerEn,
                    strPriority,
                    strIsApproved,
                    strIsAvailable
                    );

                //string strFullPath = "~/res/comment/" + strImageName;
                //if (!string.IsNullOrEmpty(strImageName))
                //{
                //    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                //    ResizeCropImage.ResizeByCondition(strFullPath, 450, 306);
                //    string bgColor = "#ffffff";
                //    ResizeCropImage.CreateThumbNailWithBackGroundColor("~/res/comment/", "~/res/comment/thumbs/", strImageName, 156, 156, bgColor);
                //}
                RadGrid1.Rebind();
            }
            else
            {
                var dsUpdateParam = ObjectDataSource1.UpdateParameters;
                //var strOldImagePath = Server.MapPath("~/res/comment/" + strOldImageName);
                //var strOldThumbImagePath = Server.MapPath("~/res/comment/thumbs/" + strOldImageName);

                dsUpdateParam["UserName"].DefaultValue  = strUserName;
                dsUpdateParam["Title"].DefaultValue     = strTitle;
                dsUpdateParam["TitleEn"].DefaultValue   = strTitleEn;
                dsUpdateParam["Content"].DefaultValue   = strContent;
                dsUpdateParam["ContentEn"].DefaultValue = strContentEn;
                dsUpdateParam["Answer"].DefaultValue    = strAnswer;
                dsUpdateParam["AnswerEn"].DefaultValue  = strAnswerEn;
                //dsUpdateParam["ConvertedCommentTitle"].DefaultValue = strConvertedCommentTitle;
                //dsUpdateParam["ImageName"].DefaultValue = strImageName;
                dsUpdateParam["IsApproved"].DefaultValue  = strIsApproved;
                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(strConvertedCommentTitle) ? "" : strConvertedCommentTitle + "-") + strCommentID + strImageName.Substring(strImageName.LastIndexOf('.'));

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

                //    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                //    ResizeCropImage.ResizeByCondition(strFullPath, 450, 306);
                //    string bgColor = "#ffffff";
                //    ResizeCropImage.CreateThumbNailWithBackGroundColor("~/res/comment/", "~/res/comment/thumbs/", strImageName, 156, 156, bgColor);
                //}
            }
        }
        //if (e.CommandName == "DeleteImage")
        //{
        //    var oComment = new Comment();
        //    var lnkDeleteImage = (LinkButton)e.CommandSource;
        //    var s = lnkDeleteImage.Attributes["rel"].ToString().Split('#');
        //    var strCommentID = s[0];
        //    var strImageName = s[1];

        //    oComment.CommentImageDelete(strCommentID);
        //    DeleteImage(strImageName);
        //    RadGrid1.Rebind();
        //}
    }