Thursday, April 7, 2016

Beginnings and Overview

Here is the HTML source code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 
Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="FirstStyle.css" rel="stylesheet" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <!--This is a web or xml comment-->
    <h1>Birthday Calculator</h1>
        <hr />
        <p>Choose your birthday</p>
        <asp:Calendar ID="Calendar1" runat="server" >

        </asp:Calendar>
        <p>Enter your name <asp:TextBox ID="NameTextBox" runat="server">
                                      </asp:TextBox>
        </p>
        <p>
            <asp:Button ID="SubmitButton" runat="server" Text="Submit" 
OnClick="SubmitButton_Click" />
            <asp:Label ID="ResultLabel" runat="server" Text="" 
CssClass="result"></asp:Label>
        </p>
    </div>
    </form>
</body>
</html>


The C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    /*This is a multiline comment. It's a good idea
    to put a header comment for every class */


    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void SubmitButton_Click(object sender, EventArgs e)
    {
        GetTimeTillBirthday();
    }

    protected void GetTimeTillBirthday()
    {
        DateTime birthDay;
        

        if (Calendar1.SelectedDate==null)
        {
            birthDay = DateTime.Now;
        }
        else
        {
            birthDay = Calendar1.SelectedDate;
        }
        Response.Write(birthDay);
        string name = NameTextBox.Text;

        //this calculates the time until the birthday
        TimeSpan daysUntilBirthday = birthDay.Subtract(DateTime.Now);
        ResultLabel.Text ="Days until Birthday " +
            Math.Abs(daysUntilBirthday.Days).ToString() +
            ". And this many hours " 
         + Math.Abs(daysUntilBirthday.Hours).ToString();
       


        

    }

}

Here is the minimal css

body {
}

h1{
    color:navy;
}

.result{
    color:green;
}

No comments:

Post a Comment