Browser.proc.DailyCount.Page_Load C# (CSharp) Method

Page_Load() protected method

protected Page_Load ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.ContentType = "text/xml";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            int project_uid;
            short fromDate = 0;
            short toDate = 0;

            if (int.TryParse(Request.QueryString["project"], out project_uid) == false)
                project_uid = 1;

            if (short.TryParse(Request.QueryString["from"], out fromDate) == false)
                fromDate = 0;

            if (short.TryParse(Request.QueryString["to"], out toDate) == false)
                toDate = 0;

            if (toDate > fromDate)
                return;

            using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("Counts");

                Dictionary<string, int> dailyCountList = new Dictionary<string, int>();

                for (int i = toDate; i < fromDate; i++)
                {
                    TimeSpan oneDay = new TimeSpan(i, 0, 0, 0);
                    DateTime saveDate = DateTime.Now.Subtract(oneDay);

                    string date = string.Format("{0:0000}-{1:00}-{2:00}", saveDate.Year, saveDate.Month, saveDate.Day);

                    dailyCountList[date] = 0;
                }

                DB.LoadDailyCount(project_uid, fromDate, toDate,
                    delegate(string date, int count)
                    {
                        dailyCountList[date] = count;
                    }
                );

                foreach (KeyValuePair<string,int> v in dailyCountList)
                {
                    writer.WriteStartElement("Count");
                    writer.WriteAttributeString("date", v.Key);
                    writer.WriteAttributeString("count", v.Value.ToString());
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Flush();
                writer.Close();
            }
        }
DailyCount