protected void RadListView1_ItemCommand(object sender, RadListViewCommandEventArgs e) { try { if (e.CommandName == "PerformInsert") { var item = e.ListViewItem; var FileImageName = (RadUpload)item.FindControl("FileImageName"); var strProductName = ((Label)FormView1.FindControl("lblProductName")).Text.Trim(); var strConvertedProductName = Common.ConvertTitle(strProductName); var strImageName = FileImageName.UploadedFiles.Count > 0 ? Guid.NewGuid().GetHashCode().ToString("X") + FileImageName.UploadedFiles[0].GetExtension() : ""; var strTitle = ((RadTextBox)item.FindControl("txtTitle")).Text.Trim(); var strDescription = ((RadTextBox)item.FindControl("txtDescription")).Text.Trim(); var strTitleEn = ((RadTextBox)item.FindControl("txtTitleEn")).Text.Trim(); var strDescriptionEn = ((RadTextBox)item.FindControl("txtDescriptionEn")).Text.Trim(); var IsAvailable = ((CheckBox)item.FindControl("chkAddIsAvailable")).Checked.ToString(); var Priority = ((RadNumericTextBox)item.FindControl("txtPriority")).Text.Trim(); var oProductOption = new ProductOption(); oProductOption.ProductOptionInsert( strImageName, "", "", strTitle, strConvertedProductName, strDescription, "", "", "", "", strTitleEn, strDescriptionEn, "", "", Request.QueryString["poi"], "1", "0", "0", IsAvailable, "", Priority); string strFullPath = "~/res/productoption/" + strImageName; if (!string.IsNullOrEmpty(strImageName)) { FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath)); string bgColor = "#ffffff"; ResizeCropImage.CreateThumbNailWithBackGroundColor("~/res/productoption/", "~/res/productoption/thumbs/", strImageName, 95, 96, bgColor); ResizeCropImage.ResizeWithBackGroundColor(strFullPath, 486, 487, bgColor); //ResizeCropImage.ResizeByCondition(strFullPath, 600, 600); //ResizeCropImage.CreateThumbNailByCondition("~/res/productoption/", "~/res/productoption/thumbs/", strImageName, 120, 120); } RadListView1.InsertItemPosition = RadListViewInsertItemPosition.None; } else if (e.CommandName == "Update") { var item = e.ListViewItem; var FileImageName = (RadUpload)item.FindControl("FileImageName"); var dsUpdateParam = ObjectDataSource1.UpdateParameters; var strProductOptionID = ((HiddenField)item.FindControl("hdnProductOptionID")).Value; //var strProductName = ((Label)FormView1.FindControl("lblProductName")).Text.Trim(); //var strConvertedProductName = Common.ConvertTitle(strProductName); var strOldImageName = ((HiddenField)item.FindControl("hdnImageName")).Value; var strIsAvailable = ((CheckBox)item.FindControl("chkAddIsAvailable")).Checked.ToString(); var strImageName = FileImageName.UploadedFiles.Count > 0 ? Guid.NewGuid().GetHashCode().ToString("X") + FileImageName.UploadedFiles[0].GetExtension() : ""; var strProductOptionCategoryID = string.IsNullOrEmpty(Request.QueryString["poi"]) ? "" : Request.QueryString["poi"]; dsUpdateParam["ImageName"].DefaultValue = !string.IsNullOrEmpty(strImageName) ? strImageName : strOldImageName; //dsUpdateParam["ConvertedProductName"].DefaultValue = strConvertedProductName; dsUpdateParam["IsAvailable"].DefaultValue = strIsAvailable; dsUpdateParam["ProductOptionCategoryID"].DefaultValue = strProductOptionCategoryID; if (!string.IsNullOrEmpty(strImageName)) { var strOldImagePath = Server.MapPath("~/res/productoption/" + strOldImageName); var strOldThumbImagePath = Server.MapPath("~/res/productoption/thumbs/" + strOldImageName); if (File.Exists(strOldImagePath)) { File.Delete(strOldImagePath); } if (File.Exists(strOldThumbImagePath)) { File.Delete(strOldThumbImagePath); } //strImageName = (string.IsNullOrEmpty(strConvertedProductName) ? "" : strConvertedProductName + "-") + strProductOptionID + strImageName.Substring(strImageName.LastIndexOf('.')); string strFullPath = "~/res/productoption/" + strImageName; FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath)); string bgColor = "#ffffff"; ResizeCropImage.CreateThumbNailWithBackGroundColor("~/res/productoption/", "~/res/productoption/thumbs/", strImageName, 95, 96, bgColor); ResizeCropImage.ResizeWithBackGroundColor(strFullPath, 486, 487, bgColor); //ResizeCropImage.ResizeByCondition(strFullPath, 600, 600); //ResizeCropImage.CreateThumbNailByCondition("~/res/productoption/", "~/res/productoption/thumbs/", strImageName, 120, 120); } } else if (e.CommandName == "Delete") { var strOldImageName = ((HiddenField)e.ListViewItem.FindControl("hdnImageName")).Value; DeleteImage(strOldImageName); } else if (e.CommandName == "QuickUpdate") { string ProductOptionID, Priority, IsAvailable; var oProductOption = new ProductOption(); foreach (RadListViewDataItem item in RadListView1.Items) { ProductOptionID = item.GetDataKeyValue("ProductOptionID").ToString(); Priority = ((RadNumericTextBox)item.FindControl("txtPriority")).Text.Trim(); IsAvailable = ((CheckBox)item.FindControl("chkIsAvailable")).Checked.ToString(); oProductOption.ProductOptionQuickUpdate( ProductOptionID, "1", "0", "0", IsAvailable, Priority ); } } else if (e.CommandName == "DeleteSelected") { var oProductOption = new ProductOption(); string ProductOptionID, OldImageName; foreach (RadListViewDataItem item in RadListView1.Items) { var chkSelect = (CheckBox)item.FindControl("chkSelect"); if (chkSelect.Checked) { ProductOptionID = item.GetDataKeyValue("ProductOptionID").ToString(); OldImageName = ((HiddenField)item.FindControl("hdnImageName")).Value; DeleteImage(OldImageName); oProductOption.ProductOptionDelete(ProductOptionID); } } } RadListView1.Rebind(); } catch (Exception ex) { lblError.Text = ex.Message; } }