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 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 } }