/// <summary> /// The Page_Load event handler on this User Control is used to /// obtain a DataReader of Article information from the Articles /// table, and then databind the results to a templated DataList /// server control. It uses the Rainbow.ArticleDB() /// data component to encapsulate all data functionality. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { // Obtain Articles information from the Articles table // and bind to the datalist control ArticlesDB Articles = new ArticlesDB(); myDataList.DataSource = Articles.GetArticles(ModuleID); myDataList.DataBind(); } }
/// <summary> /// The DeleteBtn_Click event handler on this Page is used to delete an /// a Article. It uses the Rainbow.ArticlesDB() /// data component to encapsulate all data functionality. /// </summary> /// <param name="e"></param> override protected void OnDelete(EventArgs e) { base.OnDelete(e); // Only attempt to delete the item if it is an existing item // (new items will have "ItemID" of 0) if (ItemID != 0) { ArticlesDB Articles = new ArticlesDB(); Articles.DeleteArticle(ItemID); } this.RedirectBackToReferringPage(); }
/// <summary> /// The BindData method is used to obtain details of a message /// from the Articles table, and update the page with /// the message content. /// </summary> void BindData() { // Obtain the selected item from the Articles table ArticlesDB Article = new ArticlesDB(); SqlDataReader dr = Article.GetSingleArticle(ItemID); try { // Load first row from database if (dr.Read()) { // Update labels with message contents Title.Text = (string)dr["Title"].ToString(); //[email protected] 5/24/04 added subtitle to ArticlesView. if (dr["Subtitle"].ToString().Length > 0) { Subtitle.Text = "(" + (string)dr["Subtitle"].ToString() + ")"; } StartDate.Text = ((DateTime)dr["StartDate"]).ToShortDateString(); Description.Text = Server.HtmlDecode((string)dr["Description"].ToString()); CreatedDate.Text = ((DateTime)dr["CreatedDate"]).ToShortDateString(); CreatedBy.Text = (string)dr["CreatedByUser"].ToString(); // 15/7/2004 added localization by Mario Endara [email protected] if (CreatedBy.Text == "unknown") { CreatedBy.Text = Esperantus.Localize.GetString("UNKNOWN", "unknown"); } //Chris Farrell, [email protected], 5/24/2004 if (!bool.Parse(moduleSettings["MODULESETTINGS_SHOW_MODIFIED_BY"].ToString())) { CreatedLabel.Visible = false; CreatedDate.Visible = false; OnLabel.Visible = false; CreatedBy.Visible = false; } } } finally { // close the datareader dr.Close(); } }
/// <summary> /// Is used to either create or update an Article. /// It uses the Rainbow.ArticlesDB() /// data component to encapsulate all data functionality. /// </summary> override protected void OnUpdate(EventArgs e) { base.OnUpdate(e); // Only Update if Input Data is Valid if (Page.IsValid == true) { ArticlesDB Articles = new ArticlesDB(); if (AbstractField.Text == string.Empty) { AbstractField.Text = ((HTMLText)DesktopText.Text).GetAbstractText(100); } if (ItemID == 0) { Articles.AddArticle(ModuleID, PortalSettings.CurrentUser.Identity.Email, ((HTMLText)TitleField.Text).InnerText, ((HTMLText)SubtitleField.Text).InnerText, AbstractField.Text, Server.HtmlEncode(DesktopText.Text), DateTime.Parse(StartField.Text), DateTime.Parse(ExpireField.Text), true, string.Empty); } else { Articles.UpdateArticle(ModuleID, ItemID, PortalSettings.CurrentUser.Identity.Email, ((HTMLText)TitleField.Text).InnerText, ((HTMLText)SubtitleField.Text).InnerText, AbstractField.Text, Server.HtmlEncode(DesktopText.Text), DateTime.Parse(StartField.Text), DateTime.Parse(ExpireField.Text), true, string.Empty); } this.RedirectBackToReferringPage(); } }
/// <summary> /// The Page_Load event on this Page is used to obtain the ModuleID /// and ItemID of the Article to edit. /// It then uses the Rainbow.ArticlesDB() data component /// to populate the page's edit controls with the Article details. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Page_Load(object sender, System.EventArgs e) { // Add the setting HtmlEditorDataType h = new HtmlEditorDataType(); h.Value = moduleSettings["Editor"].ToString(); DesktopText = h.GetEditor(PlaceHolderHTMLEditor, ModuleID, bool.Parse(moduleSettings["ShowUpload"].ToString()), portalSettings); // Construct the page DesktopText.Width = new System.Web.UI.WebControls.Unit(moduleSettings["Width"].ToString()); DesktopText.Height = new System.Web.UI.WebControls.Unit(moduleSettings["Height"].ToString()); // Construct the page // Added css Styles by Mario Endara <*****@*****.**> (2004/10/26) updateButton.CssClass = "CommandButton"; PlaceHolderButtons.Controls.Add(updateButton); PlaceHolderButtons.Controls.Add(new LiteralControl(" ")); cancelButton.CssClass = "CommandButton"; PlaceHolderButtons.Controls.Add(cancelButton); PlaceHolderButtons.Controls.Add(new LiteralControl(" ")); deleteButton.CssClass = "CommandButton"; PlaceHolderButtons.Controls.Add(deleteButton); // If the page is being requested the first time, determine if an // Article itemID value is specified, and if so populate page // contents with the Article details if (Page.IsPostBack == false) { if (ItemID != 0) { // Obtain a single row of Article information ArticlesDB Articles = new ArticlesDB(); SqlDataReader dr = Articles.GetSingleArticle(ItemID); try { // Load first row into Datareader if (dr.Read()) { StartField.Text = ((DateTime)dr["StartDate"]).ToShortDateString(); ExpireField.Text = ((DateTime)dr["ExpireDate"]).ToShortDateString(); TitleField.Text = (string)dr["Title"].ToString(); SubtitleField.Text = (string)dr["Subtitle"].ToString(); AbstractField.Text = (string)dr["Abstract"].ToString(); DesktopText.Text = Server.HtmlDecode(dr["Description"].ToString()); CreatedBy.Text = (string)dr["CreatedByUser"].ToString(); CreatedDate.Text = ((DateTime)dr["CreatedDate"]).ToString(); // 15/7/2004 added localization by Mario Endara [email protected] if (CreatedBy.Text == "unknown") { CreatedBy.Text = Esperantus.Localize.GetString("UNKNOWN", "unknown"); } } } finally { dr.Close(); } } else { //New article - set defaults StartField.Text = DateTime.Now.ToShortDateString(); ExpireField.Text = DateTime.Now.AddDays(int.Parse(moduleSettings["DefaultVisibleDays"].ToString())).ToShortDateString(); CreatedBy.Text = PortalSettings.CurrentUser.Identity.Email; CreatedDate.Text = DateTime.Now.ToString(); } } }