private void Page_Load(object sender, EventArgs e) { // If Esperantus.Esperantus.Localize. page is being requested Esperantus.Esperantus.Localize. first time, determine if a // picture itemID value is specified, and if so populate page // contents with Esperantus.Esperantus.Localize. picture details Metadata = new XmlDocument(); if (Page.IsPostBack == false) { BulkDir.Visible = false; // make bulk load controls not visible for now BulkDirLiteral.Visible = false; if (ItemID != 0) { // Obtain a single row of picture information PicturesDB pictures = new PicturesDB(); SqlDataReader dr = pictures.GetSinglePicture(ItemID, WorkFlowVersion.Staging); try { // Read first row from database if (dr.Read()) { ShortDescription.Text = (string) dr["ShortDescription"]; MetadataXml = (string) dr["MetadataXml"]; Metadata.LoadXml(MetadataXml); Keywords.Text = GetMetadata("Keywords"); LongDescription.Text = GetMetadata("LongDescription"); Caption.Text = GetMetadata("Caption"); DisplayOrder.Text = ((int) dr["DisplayOrder"]).ToString(); ThumbnailFilename = GetMetadata("ThumbnailFilename"); ModifiedFilename = GetMetadata("ModifiedFilename"); } } finally { // Close data reader dr.Close(); } } else { Metadata.AppendChild(Metadata.CreateElement("Metadata")); MetadataXml = Metadata.OuterXml; if (((SettingItem<bool, CheckBox>)this.ModuleSettings["AllowBulkLoad"]).Value) { // Esperantus.Esperantus.Localize.y are adding, and we are allowed to bulk load so // make Esperantus.Esperantus.Localize. controls visible BulkDir.Visible = true; BulkDirLiteral.Visible = true; } } } else { Metadata.LoadXml(MetadataXml); } }
/// <summary> /// The Page_Load event handler on this Page is used to /// obtain obtain the contents of a picture from the /// Pictures table, construct an HTTP Response of the /// correct type for the picture, and then stream the /// picture contents to the response. It uses the /// Appleseed.PictureDB() data component to encapsulate /// the data access functionality. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> private void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack && ModuleID > 0 && ItemID > 0) { // Obtain a single row of picture information PicturesDB pictures = new PicturesDB(); WorkFlowVersion version = Request.QueryString["wversion"] == "Staging" ? WorkFlowVersion.Staging : WorkFlowVersion.Production; SqlDataReader dr = pictures.GetSinglePicture(ItemID, version); PictureItem pictureItem; XmlDocument metadata = new XmlDocument(); try { // Read first row from database if (dr.Read()) { pictureItem = (PictureItem) Page.LoadControl(Path.ApplicationRoot + "/Design/PictureLayouts/" + this.ModuleSettings["ImageLayout"]); metadata.LoadXml((string) dr["MetadataXml"]); XmlAttribute albumPath = metadata.CreateAttribute("AlbumPath"); albumPath.Value = ((SettingItem<string, TextBox>) this.ModuleSettings["AlbumPath"]).FullPath; XmlAttribute itemID = metadata.CreateAttribute("ItemID"); itemID.Value = ((int) dr["ItemID"]).ToString(); XmlAttribute moduleID = metadata.CreateAttribute("ModuleID"); moduleID.Value = ModuleID.ToString(); XmlAttribute wVersion = metadata.CreateAttribute("WVersion"); wVersion.Value = version.ToString(); if (dr["PreviousItemID"] != DBNull.Value) { XmlAttribute previousItemID = metadata.CreateAttribute("PreviousItemID"); previousItemID.Value = ((int) dr["PreviousItemID"]).ToString(); metadata.DocumentElement.Attributes.Append(previousItemID); } if (dr["NextItemID"] != DBNull.Value) { XmlAttribute nextItemID = metadata.CreateAttribute("NextItemID"); nextItemID.Value = ((int) dr["NextItemID"]).ToString(); metadata.DocumentElement.Attributes.Append(nextItemID); } metadata.DocumentElement.Attributes.Append(albumPath); metadata.DocumentElement.Attributes.Append(itemID); metadata.DocumentElement.Attributes.Append(moduleID); metadata.DocumentElement.Attributes.Append(wVersion); if (version == WorkFlowVersion.Production) { XmlNode modifiedFilenameNode = metadata.DocumentElement.SelectSingleNode("@ModifiedFilename"); XmlNode thumbnailFilenameNode = metadata.DocumentElement.SelectSingleNode("@ThumbnailFilename"); modifiedFilenameNode.Value = modifiedFilenameNode.Value.Replace(".jpg", ".Production.jpg"); thumbnailFilenameNode.Value = thumbnailFilenameNode.Value.Replace(".jpg", ".Production.jpg"); } pictureItem.Metadata = metadata; pictureItem.DataBind(); Picture.Controls.Add(pictureItem); } } catch { lblError.Visible = true; Picture.Visible = false; return; } finally { // Close datareader dr.Close(); } DataBind(); } }
/// <summary> /// Esperantus.Esperantus.Localize. DeleteBtn_Click event handler on this Page is used to delete /// a picture. It uses Esperantus.Esperantus.Localize. Appleseed.PicturesDB() /// data component to encapsulate all data functionality. /// </summary> protected override void OnDelete(EventArgs e) { base.OnDelete(e); // Only attempt to delete Esperantus.Esperantus.Localize. item if it is an existing item // (new items will have "ItemID" of 0) if (ItemID != 0) { PicturesDB pictures = new PicturesDB(); string PathToDelete = Server.MapPath(((SettingItem<string, TextBox>)this.ModuleSettings["AlbumPath"]).FullPath) + "\\"; SqlDataReader dr = pictures.GetSinglePicture(ItemID, WorkFlowVersion.Staging); string filename = string.Empty; string thumbnailFilename = string.Empty; try { // Read first row from database if (dr.Read()) { Metadata.LoadXml((string) dr["MetadataXml"]); filename = GetMetadata("ModifiedFilename"); thumbnailFilename = GetMetadata("ThumbnailFilename"); } } finally { // Close datareader dr.Close(); } try { //Delete Esperantus.Esperantus.Localize. files File.Delete(PathToDelete + filename); File.Delete(PathToDelete + thumbnailFilename); } catch { // We don't really have much to do at this point } //Delete Esperantus.Esperantus.Localize. record from database. pictures.DeletePicture(ItemID); } // Redirect back to Esperantus.Esperantus.Localize. portal home page RedirectBackToReferringPage(); }