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 = "3"; } 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(); string DienTichToanKhu = ((RadTextBox)row.FindControl("txtDienTichToanKhu")).Text.Trim(); string SoCanHo = ((RadTextBox)row.FindControl("txtSoCanHo")).Text.Trim(); string SoTang = ((RadTextBox)row.FindControl("txtSoTang")).Text.Trim(); string Gia = ((RadTextBox)row.FindControl("txtGia")).Text.Trim(); string DatCho = ((RadTextBox)row.FindControl("txtDatCho")).Text.Trim(); string MatDoXayDung = ((RadTextBox)row.FindControl("txtMatDoXayDung")).Text.Trim(); string KhongGianXanh = ((RadTextBox)row.FindControl("txtKhongGianXanh")).Text.Trim(); string DienTichXayDung = ((RadTextBox)row.FindControl("txtDienTichXayDung")).Text.Trim(); string KhongGianSinhHoat = ((RadTextBox)row.FindControl("txtKhongGianSinhHoat")).Text.Trim(); if (e.CommandName == "PerformInsert") { var oProduct = new Product(); ImageName = oProduct.ProductInsert2( 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, DienTichToanKhu, SoCanHo, SoTang, Gia, DatCho, MatDoXayDung, KhongGianXanh, DienTichXayDung, KhongGianSinhHoat ); 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(); } }