public void DeleteSelectedItems() { int nbDeletedRows = 0; int nbSelectedRows = 0; for (int i = 0; i < documents.Items.Count; i++) { CheckBox cb = (CheckBox)documents.Items[i].Cells[0].FindControl("g_sd"); if (cb.Checked) { HyperCatalog.Business.DAM.Resource CurrentResource = HyperCatalog.Business.DAM.Resource.GetByKey(_CurrentLibrary.Id, Convert.ToInt32(documents.DataKeys[i])); if (SessionState.User.HasCapability(Business.CapabilitiesEnum.MANAGE_RESOURCES) && CurrentResource != null) { //if (SessionState.User.IsReadOnly || CurrentResource.Delete()) //{ // //SetMessage(propertiesMsgLbl, "Resource \"" + CurrentResource.Name + "\" deleted", MessageLevel.Information); // LoadGrid(); //} //else //{ // //SetMessage(propertiesMsgLbl, "Resource \"" + CurrentResource.Name + "\" could not be deleted", MessageLevel.Error); // LoadGrid(); //} CurrentResource.Delete(); } } } LoadGrid(); }
protected void pTb_ButtonClicked(object sender, Infragistics.WebUI.UltraWebToolbar.ButtonEvent be) { switch (be.Button.Key.ToLower()) { case "save": if (Shared.SessionState.User.HasCapability(Business.CapabilitiesEnum.MANAGE_RESOURCES)) { if (Shared.SessionState.User.IsReadOnly) { return; } if (txtResourceNameValue.Text == null || txtResourceNameValue.Text.Length == 0) { SetMessage(propertiesMsgLbl, "Resource must have a name", MessageLevel.Error); break; } string[][] attrs = new string[1][]; try { HyperCatalog.Business.DAM.Resource newResource = CurrentLibrary.AddResource(txtResourceNameValue.Text + Path.GetExtension(txtFileBinaryValue.PostedFile.FileName), txtResourceDescriptionValue.Value, Convert.ToInt32(txtResourceTypeValue.SelectedValue), HyperCatalog.Shared.SessionState.MasterCulture.Code, txtFileBinaryValue.PostedFile.InputStream, attrs); LoadGrid(); } catch (Exception ex) { SetMessage(propertiesMsgLbl, "InValid file format. Please select the correct file.", MessageLevel.Error); LoadGrid(); break; } } break; } }
private void BindLibrary() { if (CurrentResource != null && !CurrentResource.Match(resourceFilter)) { _currentResourceId = -1; } if (_currentResourceId < 0) { HyperCatalog.Business.DAM.Resource resource = resources.GetByIndex(0); if (resource != null) { _currentResourceId = resource.Id; } } rGd.DataSource = resources; rGd.DataBind(); rGd.Visible = completePanel.Visible = rGd.Rows.Count > 0; emptyLibPanel.Visible = rGd.Rows.Count == 0; if (_currentResourceId >= 0) { UltraGridRow row = null; for (int index = 0; index < rGd.DataKeys.Count; index++) { if ((int)rGd.DataKeys[index] == _currentResourceId) { row = rGd.Rows[index]; } } if (row != null) { row.Selected = true; } } txtResourceTypeValue.DataSource = resourceTypes; resourceTypesAttributes.DataSource = resourceTypes; txtResourceTypeValue.DataBind(); resourceTypesAttributes.DataBind(); if (DisplayMode == Mode.Complete) { BindResource(); } }
private void propertiesToolbar_ButtonClicked(object sender, ButtonEvent be) { switch (be.Button.Key) { #region case "CRT": case "CRT": if (CurrentResource != null && CurrentResource.Type.Name == "Template") { Response.Redirect(CurrentResource.URI + "?CRT=1"); // HyperCatalog.Business.DAM.Specific.HOTTemplate template = new HyperCatalog.Business.DAM.Specific.HOTTemplate(currentResource.MasterVariant.CurrentFile); // HyperComponents.IO.Streaming.SendStream(Response,template.CRTStream,currentResource.Name + ".pdf"); Response.End(); } break; #endregion #region case "Del": case "Del": if (SessionState.User.HasCapability(Business.CapabilitiesEnum.MANAGE_RESOURCES) && CurrentResource != null) { if (SessionState.User.IsReadOnly || CurrentResource.Delete()) { SetMessage(propertiesMsgLbl, "Resource \"" + CurrentResource.Name + "\" deleted", MessageLevel.Information); libraryList.SelectedItem.Text = String.Format(libraryListPattern, CurrentLibrary.Name, CurrentLibrary.ResourceCount); _currentResourceId = -1; BindLibrary(); } else { SetMessage(propertiesMsgLbl, "Resource \"" + CurrentResource.Name + "\" could not be deleted", MessageLevel.Error); } } break; #endregion #region case "Save": case "Save": if (txtFileBinaryValue.PostedFile.ContentLength > 0) { SetMessage(propertiesMsgLbl, "You must provide a file", MessageLevel.Warning); return; } if (SessionState.User.HasCapability(Business.CapabilitiesEnum.MANAGE_RESOURCES)) { if (SessionState.User.IsReadOnly) { return; } if (resourceTypesAttributes.Items.Count > txtResourceTypeValue.SelectedIndex) { if (txtResourceNameValue.Text == null || txtResourceNameValue.Text.Length == 0) { SetMessage(propertiesMsgLbl, "Resource must have a name", MessageLevel.Error); break; } string[][] attrs = getAttributeValues(resourceTypesAttributes.Items[txtResourceTypeValue.SelectedIndex]); if (CurrentResource != null) { CurrentResource.Name = txtResourceNameValue.Text; CurrentResource.Description = txtResourceDescriptionValue.Value; if (CurrentResource.Save()) { SetMessage(propertiesMsgLbl, "Resource \"" + txtResourceNameValue.Text + "\" updated", MessageLevel.Information); if (addVariant) { bool success = false; string errorMsg = "Variant for \"" + txtResourceNameValue.Text + "\" could not be created"; try { success = CurrentResource.AddVariant(txtVariantCultureValue.SelectedValue, txtFileBinaryValue.PostedFile.InputStream, Path.GetExtension(txtFileBinaryValue.PostedFile.FileName), attrs) != null; } catch (AlreadyExistingVariantException) { errorMsg += ": this variant already exists."; } if (success) { SetMessage(propertiesMsgLbl, "Variant for \"" + txtResourceNameValue.Text + "\" created", MessageLevel.Information); } else { SetMessage(propertiesMsgLbl, errorMsg, MessageLevel.Error); } } BindLibrary(); } else { SetMessage(propertiesMsgLbl, "Resource \"" + txtResourceNameValue.Text + "\" could not be updated", MessageLevel.Error); } } else { HyperCatalog.Business.DAM.Resource newResource = CurrentLibrary.AddResource(txtResourceNameValue.Text + Path.GetExtension(txtFileBinaryValue.PostedFile.FileName), txtResourceDescriptionValue.Value, Convert.ToInt32(txtResourceTypeValue.SelectedValue), txtVariantCultureValue.SelectedValue, txtFileBinaryValue.PostedFile.InputStream, attrs); if (newResource != null) { SetMessage(propertiesMsgLbl, "Resource \"" + txtResourceNameValue.Text + "\" created", MessageLevel.Information); libraryList.SelectedItem.Text = String.Format(libraryListPattern, CurrentLibrary.Name, CurrentLibrary.ResourceCount); _currentResourceId = newResource.Id; BindLibrary(); } else { SetMessage(propertiesMsgLbl, "Resource \"" + txtResourceNameValue.Text + "\" could not be created", MessageLevel.Error); } } } } break; #endregion } }
protected override void OnLoad(EventArgs e) { if (this.Visible) { if (DisplayMode == Mode.Complete && !SessionState.User.HasCapability(Business.CapabilitiesEnum.MANAGE_RESOURCES)) { UITools.DenyAccess(DenyMode.Frame); } #region init grids Utils.InitGridSort(ref rGd); //Utils.InitGridSort(ref variantsGrid); #endregion propertiesMsgLbl.Visible = false; mTb.Items.FromKeyButton("Add").Visible = completePanel.Visible = (DisplayMode == Mode.Complete); minimalCell.ColSpan = (DisplayMode == Mode.Complete ? 1 : 3); if (!IsPostBack) { HyperCatalog.Business.CultureList cultures = HyperCatalog.Business.Culture.GetAll(); _currentCultureCode = HyperCatalog.Shared.SessionState.MasterCulture.Code; if (cultures != null) { cultures.Sort("Name ASC"); } txtVariantCultureValue.DataSource = cultures; txtVariantCultureValue.DataBind(); _currentResourceId = -1; _currentLibrary = null; _resourceTypes = null; if (Request["l"] != null) { try { _currentLibraryId = Convert.ToInt32(Request["l"]); } catch { } } else if (Request["resource"] != null) { try { string[] splitted = Request["resource"].Split('/'); if (splitted.Length == 2) { _currentLibrary = Library.GetByKey(splitted[0]); if (_currentLibrary != null) { _currentResource = _currentLibrary.Resources[splitted[1].Split('.')[0]]; } } } catch { } } if (Request["culture"] != null) { CurrentCultureCode = Request["culture"]; } if (_currentLibraryId < 0 && Session["DAM_currentLibraryId"] is int) { _currentLibraryId = (int)Session["DAM_currentLibraryId"]; } BindDAM(); } } base.OnLoad(e); //Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "ChgLib", "function ChgLib(libId){window.location='" + Request.Url.PathAndQuery.Substring(0, Request.Url.PathAndQuery.Length - Request.Url.Query.Length) + "?w=" + WorkspaceId.ToString() + "&l=' + libId;}", true); //libraryList.Attributes.Add("onchange", "ChgLib(this.value)"); }