In C# Begin a new project named Customer Information and design a class named Pe
ID: 3734274 • Letter: I
Question
In C# Begin a new project named Customer Information and design a class named Person with the following
properties:
LastName (string)
FirstName (string)
Address (string)
City (string)
State (string)
Zip (string)
Phone (string)
Implement the properties as public property procedures. Create a form that allows you to assign values
to each property of a Person object.
Design a new class named Customer, which is derived from the Person class. The Customer class should
have the following properties:
CustomerNumber (integer)
MailingList (Boolean)
Comments (string)
The CustomerNumber property will be used to hold a unique number for each customer. The Mailing
List property will be set to True if the customer wishes to be on a mailing list, or False if the customer
does not wish to be on a mailing list. The Comments property holds miscellaneous comments about the
customer.
Modify the form so that it allows you to store data in each property of a Customer object. Add a button
to process a class object. This code should accept the data from the textboxes and store them in the
properties of the class. It should then display the data from the class to multiple message boxes. Be
sure to include an Exit button.
Add a second form to the project. Instead of outputting the data to message boxes, display the output
to a list box on this second form
Explanation / Answer
.ASPX CODE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm3 : System.Web.UI.Page
{
Customer obj = new Customer();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
obj.First_name = FirstNametext.Text;
obj.Last_name = LastNametext.Text;
obj.Address = Addresstext.Text;
obj.City = Citytext.Text;
obj.State = Statetext.Text;
obj.Zip = Ziptext.Text;
obj.Phone = Phonetext.Text;
obj.Customer_no =Convert.ToInt32(CustomerNumbertext.Text);
if(MailingListcheck.Checked)
{
obj.Mailing_list = true;
}
else
{
obj.Mailing_list = false;
}
obj.Comment = Comment.Text;
Show.Visible = true;
}
protected void ShowOnLabels_Click(object sender, EventArgs e)
{
Lastnamedata.Text +=obj.Last_name;
FirstNamedata.Text += obj.First_name;
Addressdata.Text += obj.Address;
Citydata.Text += obj.City;
Statedata.Text+=obj.State;
Zipdata.Text += obj.Zip;
Phonedata.Text +=obj.Phone;
CustomerNodata.Text += (obj.Customer_no).ToString();
if(obj.Mailing_list)
{
MailingListdata.Text += "YES";
}
else
{
MailingListdata.Text += "NO";
}
Commentsdata.Text += obj.Comment;
DataOnLabels.Visible = true;
}
protected void Exitlabeldata_Click(object sender, EventArgs e)
{
Lastnamedata.Text ="LastName:-";
FirstNamedata.Text = "FirstName:-";
Addressdata.Text = "Address:-";
Citydata.Text = "City:-";
Statedata.Text = "State:-";
Zipdata.Text = "Zip:-";
Phonedata.Text = "Phone:-";
CustomerNodata.Text = "CustomerNo:-";
MailingListdata.Text = "MailingList";
Commentsdata.Text = "Comment:-";
DataOnLabels.Visible = false;
}
protected void ShowOnListBox_Click(object sender, EventArgs e)
{
Console.Write("kjhdcb "+ obj.Last_name);
DataDropdown.Items.Add("Last Name:-"+obj.Last_name);
DataDropdown.Items.Add("First Name:-"+obj.First_name);
DataDropdown.Items.Add("Address:-"+obj.Address);
DataDropdown.Items.Add("City:-"+obj.City);
DataDropdown.Items.Add("State:-"+obj.State);
DataDropdown.Items.Add("Zip:-"+obj.Zip);
DataDropdown.Items.Add("Phone:-"+obj.Phone);
DataDropdown.Items.Add("Customer Number:-"+obj.Customer_no.ToString());
if(obj.Mailing_list)
{
DataDropdown.Items.Add("MailingList:-YES");
}
else
{
DataDropdown.Items.Add("MailingList:-NO");
}
DataDropdown.Items.Add("Comment:-"+obj.Comment);
DataOnlistbox.Visible = true;
}
protected void Exitdropdowndata_Click(object sender, EventArgs e)
{
DataDropdown.Items.Clear();
DataOnlistbox.Visible = false;
}
}
public class Person
{
private string f_name,l_name,city,state,address,zip,phone;
public string First_name
{
get { return f_name; }
set { f_name = value; }
}
public string Last_name
{
get { return l_name; }
set { l_name = value; }
}
public string Address
{
get { return address; }
set { address = value; }
}
public string State
{
get { return state; }
set { state = value; }
}
public string City
{
get { return city; }
set { city = value; }
}
public string Zip
{
get { return zip; }
set { zip = value; }
}
public string Phone
{
get { return phone; }
set { phone = value; }
}
}
public class Customer:Person
{
private int customerno;
private bool mail;
private string comment;
public int Customer_no
{
get { return customerno; }
set { customerno = value; }
}
public bool Mailing_list
{
get { return mail; }
set { mail = value; }
}
public string Comment
{
get { return comment; }
set { comment = value; }
}
}
}
DESIGN CODE
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs"
Inherits="WebApplication1.WebForm3" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="LastName" runat="server" Text="LastName:-
"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:TextBox ID="LastNametext"
runat="server"></asp:TextBox>
<br />
<asp:Label ID="FirstName" runat="server" Text="FirstName:-"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:TextBox ID="FirstNametext"
runat="server"></asp:TextBox>
<br />
<asp:Label ID="Address" runat="server" Text="Address:-"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:TextBox ID="Addresstext"
runat="server"></asp:TextBox>
<br />
<asp:Label ID="City" runat="server" Text="City:-"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="Citytext" runat="server"></asp:TextBox>
<br />
<asp:Label ID="State" runat="server" Text="State:-"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="Statetext" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Zip" runat="server" Text="Zip:-"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="Ziptext" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Phone" runat="server" Text="Phone:-"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:TextBox ID="Phonetext"
runat="server"></asp:TextBox>
<br />
<asp:Label ID="CustomerNumber" runat="server" Text="CustomerNo:-"></asp:Label>
<asp:TextBox ID="CustomerNumbertext" runat="server"></asp:TextBox><br />
<asp:Label ID="MailingList" runat="server" Text="MailingList:-"></asp:Label>
&nbsp;
<asp:CheckBox ID="MailingListcheck" runat="server" />
<br />
<asp:Label ID="Comments" runat="server" Text="Comments:-"></asp:Label>
&nbsp;&nbsp;
<asp:TextBox ID="Comment" runat="server"></asp:TextBox>
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
<asp:Button ID="Store" runat="server" Text="Store" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</div>
<div id="Show" runat="server" visible="false">
<asp:Button ID="ShowOnLabels" runat="server" Text="ShowOnLabels"
/><asp:Button ID="ShowOnListBox" runat="server"
Text="ShowOnListBox" />
<div id="DataOnLabels" runat="server" visible="false">
<asp:Label ID="Lastnamedata" runat="server" Text="LastName:-"></asp:Label>
<br />
<asp:Label ID="FirstNamedata" runat="server" Text="FirstName:-"></asp:Label>
<br />
<asp:Label ID="Addressdata" runat="server" Text="Address:-"></asp:Label>
<br />
<asp:Label ID="Citydata" runat="server" Text="City:-"></asp:Label>
<br />
<asp:Label ID="Statedata" runat="server" Text="State:-"></asp:Label>
<br />
<asp:Label ID="Zipdata" runat="server" Text="Zip:-"></asp:Label>
<br />
<asp:Label ID="Phonedata" runat="server" Text="Phone:-"></asp:Label>
<br />
<asp:Label ID="CustomerNodata" runat="server" Text="CustomerNo:-"></asp:Label>
<br />
<asp:Label ID="MailingListdata" runat="server" Text="MailingList:-"></asp:Label>
<br />
<asp:Label ID="Commentsdata" runat="server" Text="Comments:-"></asp:Label>
<br />
<asp:Button ID="Exitlabeldata" runat="server" Text="Exit" />
</div>
<div id="DataOnlistbox" runat="server" visible="false">
<asp:DropDownList ID="DataDropdown" runat="server"></asp:DropDownList>
<br />
<asp:Button ID="Exitdropdowndata" runat="server" Text="Exit"
style="height: 26px" />
</div>
</div>
</form>
</body>
</html>