|
using System;
using System.Drawing;
using System.Xml;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Fireball.Web.Controls
{
public class AddPostControl:WebControl
{
public AddPostControl()
{
//NOP
}
protected override void Render(HtmlTextWriter writer)
{
if(Page.Session["login"] == null)
{
Page.Response.Redirect("login.aspx");
}
this.RenderBeginTag(writer);
writer.Write("<table border='0' cellpadding='0' cellspacing='1' width='100%' class=\"news_table\">");
writer.Write("<td class='news_title'>");
writer.Write("Add Post");
writer.Write("</td></tr>");
writer.Write("<tr><td class='addpost_content'>");
if(Page.Request.QueryString["send"] == null)
{
writer.Write("<form id='form1' method='post' runat='server' action='addpost.aspx?send=0'>");
writer.Write("<div>Title:</div>");
writer.Write("<input type='text' name='title' STYLE='width:100%'/>");
writer.Write("<div>Message:</div>");
writer.Write("<textarea name='message' STYLE='width:100%'></textarea>");
//writer.Write("<input type='hidden' id='hidden' value='val' />");
writer.Write("<input type='submit' id='submit' value='Add Post' STYLE='width:150px'/>");
writer.Write("</form>");
}
else
{
string title = Page.Request.Form["title"];
string message = Page.Request.Form["message"];
string username = Page.Session["login"].ToString();
bool errors = false;
if(title == null && (title == string.Empty))
errors = true;
if(message == null && (message == string.Empty))
errors = true;
if(errors != true)
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load("./data/posts.xml");
XmlNode xnode = xdoc.CreateElement("article");
//title attribute
XmlAttribute xtitle = xdoc.CreateAttribute("title");
xtitle.Value = title;
xnode.Attributes.Append(xtitle);
//title attribute
//postdate attribute
XmlAttribute xpost = xdoc.CreateAttribute("postDate");
xpost.Value = DateTime.Now.ToString();
xnode.Attributes.Append(xpost);
//postdate attribute
//postdate attribute
XmlAttribute xby = xdoc.CreateAttribute("by");
xby.Value = username;
xnode.Attributes.Append(xby);
//postdate attribute
xnode.InnerText = message;
XmlNode xposts = xdoc.SelectSingleNode("posts");
if(xposts.HasChildNodes == true)
{
xposts.InsertBefore(xnode,xposts.ChildNodes[0]);
}
else
{
xposts.AppendChild(xnode);
}
xdoc.Save("./data/posts.xml");
writer.Write("<p align='center'>Post Added Succefully</p>");
}
else
{
writer.Write("<p align='center'>Error on Adding the post</p>");
}
writer.Write("<p><a href='addpost.aspx'>Return to AddPost Page</a></p>");
}
writer.Write("</td></tr>");
writer.Write("</table>");
this.RenderEndTag(writer);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.