58705/ScreenShots/1.PNG
58705/ScreenShots/10.PNG
58705/ScreenShots/11.PNG
58705/ScreenShots/12.PNG
58705/ScreenShots/13.PNG
58705/ScreenShots/2.PNG
58705/ScreenShots/4.png
58705/ScreenShots/5.png
58705/ScreenShots/7.PNG
58705/ScreenShots/8.PNG
58705/ScreenShots/9.PNG
58705/SmallBusinessApp/.vs/SmallBusinessApp/v16/.suo
58705/SmallBusinessApp/SmallBusinessApp/App.config
58705/SmallBusinessApp/SmallBusinessApp
in/Debug/CustomerData.txt
1111,Joe Smith,111-11-1111,11/25/1971,111 jay st,718-111-1111,
[email protected]1112,Joe Smith,111-11-1112,11/25/1971,111 jay st,718-111-1111,
[email protected]1113,Joe Smith,111-11-1113,11/25/1971,111 jay st,718-111-1111,
[email protected]1114,joe Smith,111-11-1114,11/25/1971,111 jay st,718-111-1111,
[email protected]1115,Joe Smith,111-11-1115,11/25/1971,111 jay st,718-111-1111,
[email protected]1116,Joe Smith,111-11-1116,11/25/1971,111 jay st,718-111-1111,
[email protected]1117,Joe Smith,111-11-1117,11/25/1971,111 jay st,718-111-1111,
[email protected]1118,Joe Smith,111-11-1118,11/25/1971,111 jay st,718-111-1111,
[email protected]1119,Joe Smith,111-11-1119,11/25/1971,111 jay st,718-111-1111,
[email protected]1120,Joe Smith,111-11-1120,11/25/1971,111 jay st,718-111-1111,
[email protected]58705/SmallBusinessApp/SmallBusinessApp
in/Debug/Network_Printer.txt
Customer Information ............
ID Number = 1111
Name = Joe Smith
Social Security Number = 111-11-1111
Date of Birth = 11/25/1971
Age = 48
Address = 111 jay st
Phone Number = 718-111-1111
Phone Number =
[email protected]Customer Information ............
ID Number = 1111
Name = Joe Smith
Social Security Number = 111-11-1111
Date of Birth = 11/25/1971
Age = 48
Address = 111 jay st
Phone Number = 718-111-1111
Phone Number =
[email protected]Customer Information ............
ID Number = 1111
Name = Joe Smith
Social Security Number = 111-11-1111
Date of Birth = 11/25/1971
Age = 48
Address = 111 jay st
Phone Number = 718-111-1111
Phone Number =
[email protected]Customer Information ............
ID Number = 1112
Name = Joe Smith
Social Security Number = 111-11-1112
Date of Birth = 11/25/1971
Age = 48
Address = 111 jay st
Phone Number = 718-111-1111
Phone Number =
[email protected]Customer Information ............
ID Number = 1113
Name = Joe Smith
Social Security Number = 111-11-1113
Date of Birth = 11/25/1971
Age = 48
Address = 111 jay st
Phone Number = 718-111-1111
Phone Number =
[email protected]Customer Information ............
ID Number = 1114
Name = joe Smith
Social Security Number = 111-11-1114
Date of Birth = 11/25/1971
Age = 48
Address = 111 jay st
Phone Number = 718-111-1111
Phone Number =
[email protected]Customer Information ............
ID Number = 1115
Name = Joe Smith
Social Security Number = 111-11-1115
Date of Birth = 11/25/1971
Age = 48
Address = 111 jay st
Phone Number = 718-111-1111
Phone Number =
[email protected]Customer Information ............
ID Number = 1116
Name = Joe Smith
Social Security Number = 111-11-1116
Date of Birth = 11/25/1971
Age = 48
Address = 111 jay st
Phone Number = 718-111-1111
Phone Number =
[email protected]Customer Information ............
ID Number = 1117
Name = Joe Smith
Social Security Number = 111-11-1117
Date of Birth = 11/25/1971
Age = 48
Address = 111 jay st
Phone Number = 718-111-1111
Phone Number =
[email protected]Customer Information ............
ID Number = 1118
Name = Joe Smith
Social Security Number = 111-11-1118
Date of Birth = 11/25/1971
Age = 48
Address = 111 jay st
Phone Number = 718-111-1111
Phone Number =
[email protected]Customer Information ............
ID Number = 1119
Name = Joe Smith
Social Security Number = 111-11-1119
Date of Birth = 11/25/1971
Age = 48
Address = 111 jay st
Phone Number = 718-111-1111
Phone Number =
[email protected]Customer Information ............
ID Number = 1120
Name = Joe Smith
Social Security Number = 111-11-1120
Date of Birth = 11/25/1971
Age = 48
Address = 111 jay st
Phone Number = 718-111-1111
Phone Number =
[email protected]58705/SmallBusinessApp/SmallBusinessApp
in/Debug/SmallBusinessApp.exe
58705/SmallBusinessApp/SmallBusinessApp
in/Debug/SmallBusinessApp.exe.config
58705/SmallBusinessApp/SmallBusinessApp
in/Debug/SmallBusinessApp.pd
58705/SmallBusinessApp/SmallBusinessApp/Customer.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Data;
Data Access (DataSet)
using System.Data.SqlClient;
SQL Client Provide
namespace SmallBusinessApp
{
public class Custome
{
#region "Connection String Declaration"
Data Access Connection string for database connnectivity
private string strConn = @"Data Source=ServerName\SQLEXPRESS;Database=DatabaseName;User ID=Username;Password=Password";
#endregion
Private INSTANCE Data declarations:
private string m_IDNumber;
private string m_Name;
private string m_SSNumber;
private string m_BirthDate;
private int m_Age;
private string m_Address;
private string m_Phone;
private string m_Email;
Private STATIC Data declaration:
private static int m_Count = 0;
/******************************************************************
Public INSTANCE & STATIC PROPERTIES Declarations
******************************************************************
Public INSTANCE Properties Declarations
public string IDNumbe
{
get { return m_IDNumber; }
set { m_IDNumber = value; }
}
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}
public string SSNumbe
{
get { return m_SSNumber; }
set { m_SSNumber = value; }
}
public string BirthDate
{
get { return m_BirthDate; }
set
{
m_BirthDate = value;
m_Age = CalculateAnyPersonAge(BirthDate);
}
}
READ-ONLY Age property
public int Age
{
get { return m_Age; }
}
public string Address
{
get { return m_Address; }
set { m_Address = value; }
}
public string Phone
{
get { return m_Phone; }
set { m_Phone = value; }
}
public string Email
{
get { return m_Email; }
set { m_Email = value; }
}
Public STATIC Properties Declarations
public static int Count
{
get { return m_Count; }
set { m_Count = value; }
}
/******************************************************************
Public CONSTRUCTORS Declarations (DEFAULT & PARAMETERIZED)
******************************************************************
Default Constructor Declaration
Private Instance Data members are set to default values
public Customer()
{
m_IDNumber = "";
m_Name = "";
m_SSNumber = "";
m_BirthDate = "00/00/0000";
m_Age = 0;
m_Address = "";
m_Phone = "";
m_Email = "";
Increment the Static Count
m_Count++;
}
Paremeterized Constructor Declaration
Properties are SET with Paremeters values.
Other data not part of paremeters are defaulted or required actions taken
public Customer(string IDNum, string strName, string strSSNum, string strBDate, string strAddress, string strPhone, string strEmail)
{
Private data being set by PROPERTIES thus setting private data indirectly
this.IDNumber = IDNum;
this.Name = strName;
this.SSNumber = strSSNum;
this.BirthDate = strBDate;
this.Address = strAddress;
this.Phone = strPhone;
this.Email = strEmail;
Increment the Static Count
++m_Count;
m_Count++;
}
Destructor Declaration
Any actions required when object is destroyed or deleted
/******************************************************************
Public DESTRUCTOR Declaration
******************************************************************
~Customer()
{
Any action you want to do when object is being destroyed
Example - Code to clean up memory to make sure all resources
eing used by an object are destroyed when object is destroyed
}
/******************************************************************
Public INSTANCE METHODS Declarations
******************************************************************
******************************************************************
Methods prints Employee's data to a File named Network_Printer.txt
public void Print()
{
Step 1-Create object to open/create file for appending
StreamWriter objPrinterFile = new StreamWriter("Network_Printer.txt", true);
Step 2-Write person's data to printer file
objPrinterFile.WriteLine("Customer Information ............");
objPrinterFile.WriteLine("ID Number = {0}", m_IDNumber);
objPrinterFile.WriteLine("Name = {0}", m_Name);
objPrinterFile.WriteLine("Social Security Number = {0}", m_SSNumber);
objPrinterFile.WriteLine("Date of Birth = {0}", m_BirthDate);
objPrinterFile.WriteLine("Age = {0}", m_Age);
objPrinterFile.WriteLine("Address = {0}", m_Address);
objPrinterFile.WriteLine("Phone Number = {0}", m_Phone);
objPrinterFile.WriteLine("Phone Number = {0}", m_Email);
objPrinterFile.WriteLine();
objPrinterFile.WriteLine();
Step 3-Close file
objPrinterFile.Close();
}
******************************************************************
STATIC HELPER method that Calculates a person's age based on
irth date passed as paramete
private static int CalculateAnyPersonAge(string strBirthDate)
{
varible created to store the age
int age;
Convert the birthdate string strBirthDate to DateTime object
DateTime objBirthDate = Convert.ToDateTime(strBirthDate);
CALCULATE age, using .NET DateTime Structure to SUBTRACT the
cu
ent date year portion from Birthdate object Year portion
age = DateTime.Now.Year - objBirthDate.Year;
Compare if today day of the year as a number is less than
the birthday day of the year as a numbe
If TRUE, subtract 1 day from the age, otherwise do nothing since
you already have the co
ect age
this calculation takes Leap Years into account within the DayOfYear property.
if (DateTime.Now.DayOfYear < objBirthDate.DayOfYear)
age = age - 1;
return age;
}
/******************************************************************
Public INSTANCE DATA ACCESS METHODS Declarations
******************************************************************
Method retrieves Customer's data from Database
Takes the ID or primary key as parameter that will be used to
construct the SELECT query
public bool Load(string IDNumber)
{
Step 0-Create a flag to determine if results are true or false
bool found = false;
Step 1-Create Connection, assign Connection to string
SqlConnection objConn = new SqlConnection(strConn);
Step A-Start E
or Trapping
try
{
Step 2-Open connection
objConn.Open();
Step 3-Create SQL string
string strSQL = "SELECT * FROM Customer WHERE Customer_IDNumber = @Customer_IDNumber";
string strSQL = "SELECT * FROM Customer WHERE Customer_IDNumber =" + "\'" + IDNumber + "\'";
Step 4-Create Command object, pass query and connection object
SqlCommand objCmd = new SqlCommand(strSQL, objConn);
Step 5-SET CommandType Property to text since we have a query string
NOT a Stored-Procedure
For stored procedures syntax is objCmd.CommandType = CommandType.StoredProcedure;
objCmd.CommandType = CommandType.Text;
Step 6-Add Parameter to. NOTE WE ARE ASSIGNING METHOD PARAMETER
objCmd.Parameters.Add("@Customer_IDNumber", SqlDbType.VarChar).Value = IDNumber;
Step 7-Create DATAREADER POINTER & Execute Query via
COMMAND OBJECT ExecuteReader Method which returns a populated
DATAREADER OBJECT with the results of the query
SqlDataReader objDR = objCmd.ExecuteReader();
Step 8-Test to make sure there is data in the DataReader Object
if (objDR.HasRows)
{
Step 8a-Call Read() Method to point and read the first record
objDR.Read();
Step 8b-Extract data from a row s Object Populates itself.
IMPORTANT! Note that data must be extracted in the ORDER
in which the QUERY RETURNS THE DATA.
this.IDNumber = objDR.GetString(0);
this.Name = objDR.GetString(1);
this.SSNumber = objDR.GetString(2);
this.BirthDate = objDR.GetString(3);
this.BirthDate = Convert.ToString(objDR.GetDateTime(3));
this.BirthDate = Convert.ToString(objDR.GetString(3));
this.Address = objDR.GetString(4);
this.Phone = objDR.GetString(5);
this.Email = objDR.GetString(6);
Step 9-Set found flag to true
found = true;
}
Step 12 - Terminate ADO Objects
objDR.Close();
objDR = null;
objCmd.Dispose();
objCmd = null;
Step13-return true or false
return found;
}
End of try
Step B-Trap for BO, App & General Exceptions
catch (System.Exception)
{
Step C- throw system exception since run time e
or has occured;
throw new System.Exception();
}
finally
{
Step 11-Terminate connection
objConn.Close();
objConn.Dispose();
objConn = null;
}
}
Emd of Load
******************************************************************
Method inserts a new Customer record to Database
public bool Insert()
{
Step 0-Create a flag to determine if results are true or false
bool found = false;
Step 1-Create Connection, assign Connection to string
SqlConnection objConn = new SqlConnection(strConn);
Step A-Start E
or Trapping
try
{
Step 2-Open connection
objConn.Open();
Step 3-Create SQL string
string strSQL;
strSQL = "INSERT INTO Customer ( Customer_IDNumber,Customer_Name,";
strSQL = strSQL + "Customer_SSNumber,Customer_BDate,Customer_Address,";
strSQL = strSQL + "Customer_Phone,Customer_Email)";
strSQL = strSQL + "VALUES(@Customer_IDNumber,";
strSQL = strSQL + "@Customer_Name,@Customer_SSNumber,@Customer_BDate,";
strSQL = strSQL + "@Customer_Address,@Customer_Phone,@Customer_Email)";
Step 4-Create Command object, pass query and connection object
SqlCommand objCmd = new SqlCommand(strSQL, objConn);
Step 5-SET CommandType Property to text since we have a query string
NOT a Stored-Procedure
For stored procedures syntax is objCmd.CommandType = CommandType.StoredProcedure;
objCmd.CommandType = CommandType.Text;
Step 6-Add Paramter to Pareameters Collection
IMPORTANT! Paramenter TOKENS @XXXXX name must match same name
Used in the INSER QUERY AND IN LISTED IN THE ORDER
LISTED IN UPDATE QUERY! NOTE WE ARE ASSIGNING ALL OBJECT'S DATA
objCmd.Parameters.Add("@Customer_IDNumber", SqlDbType.VarChar).Value = this.IDNumber;
objCmd.Parameters.Add("@Customer_Name", SqlDbType.VarChar).Value = this.Name;
objCmd.Parameters.Add("@Customer_SSNumber", SqlDbType.VarChar).Value = this.SSNumber;
objCmd.Parameters.Add("@Customer_BDate", SqlDbType.VarChar).Value = this.BirthDate;
objCmd.Parameters.Add("@Customer_Address", SqlDbType.VarChar).Value = this.Address;
objCmd.Parameters.Add("@Customer_Phone", SqlDbType.VarChar).Value = this.Phone;
objCmd.Parameters.Add("@Customer_Email", SqlDbType.VarChar).Value = this.Email;
Step 7-Execute Non-Row Query Test result and throw exception if failed
int intRecordsAffected = objCmd.ExecuteNonQuery();
Step 8-validate if INSERT QUERY was successful
if (intRecordsAffected == 1)
{
Step 9-Set found flag to true
found = true;
}
Step 11 - Terminate ADO Objects
objCmd.Dispose();
objCmd = null;
Step12-return true or false
return found;
}
End of try
Step B-Trap for BO, App & General Exceptions
catch (System.Exception ex)
{
Step C- throw system exception since run time e
or has occured;
throw ex;
}
finally
{
Step 11-Terminate connection
objConn.Close();
objConn.Dispose();
objConn = null;
}
}
End of Insert
******************************************************************
Method updates or modifies an existing Customer record in the Database
public bool Update()
{
Step 0-Create a flag to determine if results are true or false
bool found = false;
Step 1-Create Connection, assign Connection to string
SqlConnection objConn = new SqlConnection(strConn);
Step A-Start E
or Trapping
try
{
Step 2-Open connection
objConn.Open();
Step 3-Create SQL string
string strSQL;
strSQL = "UPDATE Customer ";
strSQL = strSQL + "SET Customer_Name=@Customer_Name,";
strSQL = strSQL + "Customer_SSNumber=@Customer_SSNumber,";
strSQL = strSQL + "Customer_BDate=@Customer_BDate,";
strSQL = strSQL + "Customer_Address=@Customer_Address,";
strSQL = strSQL + "Customer_Phone=@Customer_Phone,";
strSQL = strSQL + "Customer_Email=@Customer_Email";
strSQL = strSQL + " WHERE Customer_IDNumber=@Customer_IDNumber;";
Step 4-Create Command object, pass query and connection object
SqlCommand objCmd = new SqlCommand(strSQL, objConn);
Step 5-SET CommandType Property to text since we have a query string
NOT a Stored-Procedure
For stored procedures syntax is objCmd.CommandType = CommandType.StoredProcedure;
objCmd.CommandType = CommandType.Text;
Step 6-Add Paramter to Pareameters Collection
IMPORTANT! Paramente TOKENS @XXXXX name must match same name
Used in the UPDATE QUERY AND IN LISTED IN THE ORDER
LISTED IN UPDATE QUERY! NOTE WE ARE ASSIGNING ALL OBJECT'S DATA
objCmd.Parameters.Add("@Customer_Name", SqlDbType.VarChar).Value = this.Name;
objCmd.Parameters.Add("@Customer_SSNumber", SqlDbType.VarChar).Value = this.SSNumber;
objCmd.Parameters.Add("@Customer_BDate", SqlDbType.VarChar).Value = this.BirthDate;
objCmd.Parameters.Add("@Customer_Address", SqlDbType.VarChar).Value = this.Address;
objCmd.Parameters.Add("@Customer_Phone", SqlDbType.VarChar).Value = this.Phone;
objCmd.Parameters.Add("@Customer_Email", SqlDbType.VarChar).Value = this.Email;
objCmd.Parameters.Add("@Customer_IDNumber", SqlDbType.VarChar).Value = this.IDNumber;
Step 7-Execute Non-Row Query Test result and throw exception if failed
int intRecordsAffected = objCmd.ExecuteNonQuery();
Step 8-validate if INSERT QUERY was successful
if (intRecordsAffected == 1)
{
Step 9-Set found flag to true
found = true;
}
Step 11 - Terminate ADO Objects
objCmd.Dispose();
objCmd = null;
Step12-return true or false
return found;
}
End of try
Step B-Trap for BO, App & General Exceptions
catch (System.Exception)
{
Step C- throw system exception since run time e
or has occured;
throw new System.Exception();
}
finally
{
Step 11-Terminate connection
objConn.Close();
objConn.Dispose();
objConn = null;
}
}
******************************************************************
Method deletes a Customer record from Database
Takes the ID or primary key as parameter that will be used to
construct the DELETE query
public bool Delete(string IDNumber)
{
Step 0-Create a flag to determine if results are true or false
bool found = false;
Step 1-Create Connection, assign Connection to string
SqlConnection objConn = new SqlConnection(strConn);
Step A-Start E
or Trapping
try
{
Step 2-Open connection
objConn.Open();
Step 3-Create SQL string
string strSQL = "DELETE FROM Customer WHERE Customer_IDNumber = @Customer_IDNumber";
Step 4-Create Command object, pass query and connection object
SqlCommand objCmd = new SqlCommand(strSQL, objConn);
Step 5-SET CommandType Property to text since we have a query string
NOT a Stored-Procedure
For stored procedures syntax is objCmd.CommandType = CommandType.StoredProcedure;
objCmd.CommandType = CommandType.Text;
Step 6-Add Paramter to Pareameters Collection
IMPORTANT! Paramente TOKENS @XXXXX name must match same name
Used in the UPDATE QUERY AND IN LISTED IN THE ORDER
LISTED IN DELETE QUERY!
NOTE WE ARE ASSIGNING THE PARAMETER OF THIS DELETE FUNCTION & NOT ITS PRIVATE IDNUMBER
objCmd.Parameters.Add("@Customer_IDNumber", SqlDbType.VarChar).Value = IDNumber;
Step 7-Execute Non-Row Query Test result and throw exception if failed
int intRecordsAffected = objCmd.ExecuteNonQuery();
Step 8-validate if INSERT QUERY was successful
if (intRecordsAffected == 1)
{
Step 9-Set found flag to true
found = true;
}
Step 11 - Terminate ADO Objects
objCmd.Dispose();
objCmd = null;
Step12-return true or false
return found;
}
End of try
Step B-Trap for BO, App & General Exceptions
catch (System.Exception)
{
Step C- throw system exception since run time e
or has occured;
throw new System.Exception();
}
finally
{
Step 11-Terminate connection
objConn.Close();
objConn.Dispose();
objConn = null;
}
}
}
}
58705/SmallBusinessApp/SmallBusinessApp/CustomerList.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SmallBusinessApp
{
public class CustomerList
{
#region "Private Data Declarations"
/***********************************************************************
Declare private A
ay here
private const int SIZE = 10;
private Customer[] m_a
CustomerList;
#endregion
#region "Properties Declarations"
/***********************************************************************
Create Properties here. NO PROPERTIES AT THE MOMENT
#endregion
#region "Constructor Methods Declarations"
/***********************************************************************
Default Constructor method
public CustomerList()
{
m_a
CustomerList = new Customer[SIZE];
Creating A
ay of objects
}
/***********************************************************************
Parameterized Constructor. NO PARAMETERIZED CONSTRUCTOR
/***********************************************************************
Destructo
~CustomerList()
{
destructor code here
}
#endregion
==========================================================================
PROCESSING FUNCTIONS TO OPERATE ON ARRAY
==========================================================================
#region "Regular Methods"
/***********************************************************************
Name: Search Method
Purpose: Search for Customer object by ID
Parameter: Customer ID
Return Value: True if found, false otherwise
E
or-code: Trap for a
ay & general exceptions
public Customer Search(string ID)
{
Begin search for ID
for (int i = 0; i < SIZE; i++)
{
if cell is empty skip it
if (m_a
CustomerList[i] != null)
{
Ask if this is object you are looking for?
if (m_a
CustomerList[i].IDNumber == ID)
eturn a
ay pointe
return m_a
CustomerList[i];
}
}
searched all a
ay and did not find object. Return a null
return null;
}
/***********************************************************************
Name: Add Method
Purpose: Search for empty cell in a
ay and add Customer object
Parameter: Customer Object to be added
Return Value: True if empty cell found, false otherwise
E
or-code: Trap for a
ay & general exceptions
public bool Add(Customer objCustomer)
{
Begin search for empty cell
for (int i = 0; i < SIZE; i++)
{
find empty cell
if (m_a
CustomerList[i] == null)
{
Add object to a
ay
m_a
CustomerList[i] = objCustomer;
Success, return true
return true;
}
}
return false;
Searched a
ay, no empty cell found. Return false
}
/***********************************************************************
Name: Add Method (OVERLOADED)
Purpose: Create Customer Object. Populate Customer Object
with parameter values. Search for empty cell in a
ay,
Add Customer Object to A
ay
Parameter: Variables for customer name, ID, birthdate, address and age
Return Value: True if empty cell found, false otherwise
E
or-code: Trap & rethrow a
ay & general exceptions. In addition,
trap & rethrow under Age customer application exception
public bool Add(string idNum, string name, string SSNum, string bDate, string address, string phone, string email)
{
Create temp customer object
Customer objCustomer = new Customer();
Set Object with parameters values
objCustomer.IDNumber = idNum;
objCustomer.Name = name;
objCustomer.SSNumber = SSNum;
objCustomer.BirthDate = bDate;
objCustomer.Address = address;
objCustomer.Phone = phone;
objCustomer.Email = email;
Begin search for empty cell
for (int i = 0; i < SIZE; i++)
{
find empty cell
if (m_a
CustomerList[i] == null)
{
Add object to a
ay
m_a
CustomerList[i] = objCustomer;
Success, return true
return true;
}
}
return false;
Searched a
ay, no empty cell found. Return false
}
/***********************************************************************
Name: Edit Method
Purpose: Search for Customer Object by ID
When found replace existing object with object in paramete
Parameter: Customer Object to be added
Return Value: True if object found, false otherwise
E
or-code: Trap for a
ay & general exceptions
public bool Edit(Customer objCustomer)
{
Begin search for ID
for (int i = 0; i < SIZE; i++)
{
if cell is empty skip it
if (m_a
CustomerList[i] != null)
{
Ask if this is object you are looking for?
if (m_a
CustomerList[i].IDNumber == objCustomer.IDNumber)
{
Replace exiting object, by adding new one
Set each property & return true.
IMPORTANT. IDNUMBER NOT SET
m_a
CustomerList[i].Name = objCustomer.Name;
m_a
CustomerList[i].SSNumber = objCustomer.SSNumber;
m_a
CustomerList[i].BirthDate = objCustomer.BirthDate;
m_a
CustomerList[i].Address = objCustomer.Address;
m_a
CustomerList[i].Phone = objCustomer.Phone;
m_a
CustomerList[i].Email = objCustomer.Email;
Success, return true
return true;
}
}
}
searched all a
ay and did not find object. Return a null
return false;
}
/***********************************************************************
Name: Edit Method (OVERLOADED)
Purpose: Search for Customer Object by ID
When found keep existing object.
SET ALL PROPERTIES with values from paramete
original Object not replaced but original object gets modified
Parameter: Variables for customer name, ID, birthdate, address and age
Return Value: True if object found, false otherwise
E
or-code: Trap & rethrow a
ay & general exceptions. In addition,
trap & rethrow under Age customer application exception
public bool Edit(string idNum, string name, string SSNum, string bDate, string address, string phone, string email)
{
Begin search for ID
for (int i = 0; i < SIZE; i++)
{
if cell is empty skip it
if (m_a
CustomerList[i] != null)
{
Ask if this is object you are looking for?
if (m_a
CustomerList[i].IDNumber == idNum)
{
Set each property & return true.
IMPORTANT. IDNUMBER NOT SET
m_a
CustomerList[i].Name = name;
m_a
CustomerList[i].SSNumber = SSNum;
m_a
CustomerList[i].BirthDate = bDate;
m_a
CustomerList[i].Address = address;
m_a
CustomerList[i].Phone = phone;
m_a
CustomerList[i].Email = email;
Success, return true
return true;
}
}
}
searched all a
ay and did not find object. Return a null
return false;
}
/***********************************************************************
Name: Remove Method
Purpose: Search for Customer object by ID
Remove object from a
ay by setting a
ay pointer to null
Parameter: Customer ID
Return Value: True if found, false otherwise
E
or-code: Trap for a
ay & general exceptions
public bool Remove(string ID)
{
Begin search for ID
for (int i = 0; i < SIZE; i++)
{
if cell is empty skip it
if (m_a
CustomerList[i] != null)
{
Ask if this is object you are looking for?
if (m_a
CustomerList[i].IDNumber == ID)
{
Set A
ay pointer to NULL
m_a
CustomerList[i] = null;
Success, return true
return true;
}
}
}
searched all a
ay and did not find object. Return a null
return false;
}
/***********************************************************************
Name: Print Method
Purpose: Search for Customer object by ID
Call object.Print() method so it can print itself
Parameter: Customer ID
Return Value: True if found, false otherwise
E
or-code: Trap for a
ay & general exceptions
public bool Print(string ID)
{
Begin search for ID
for (int i = 0; i < SIZE; i++)
{
if cell is empty skip it
if (m_a
CustomerList[i] != null)
{
Ask if this is object you are looking for?
if (m_a
CustomerList[i].IDNumber == ID)
{
Call object.Print() method
m_a
CustomerList[i].Print();
return true;
Success, return true
}
}
}
searched all a
ay and did not find object. Return a null
return false;
}
/***********************************************************************
Name: PrintAll Method
Purpose: Search and print all customer by calling Print() method
Parameter: None
Return Value: None
E
or-code: Trap for a
ay & general exceptions
public void PrintAll()
{
Begin search
for (int i = 0; i < SIZE; i++)
{
if cell is empty skip it
if (m_a
CustomerList[i] != null)
{
Call object.Print() method
m_a
CustomerList[i].Print();
}
}
}
/***********************************************************************
Name: Clear Method
Purpose: Clears all elements of a
ay using A
ay Class method
Parameter: None
Return Value: None
E
or-code: Trap for general exceptions
public void Clear()
{
Call Clear Static Method - A
ay.Clear(a
ay, startIndex, count);
A
ay.Clear(m_a
CustomerList, m_a
CustomerList.GetLowerBound(0),
m_a
CustomerList.GetUpperBound(0) + 1);
}
/***********************************************************************
Name: GetA
ayCopy Method
Purpose: to get a copy of a
CustomerList & return the copy
Parameter: None
Return Value: Pointer of copy version of objCustomerList
E
or-code: Trap for general exceptions
public Customer[] GetA
ayCopy()
{
Create temp a
ay
Customer[] a
Temp = new Customer[SIZE];
m_a
CustomerList.CopyTo(a
Temp, m_a
CustomerList.GetLowerBound(0));
return a
Temp;
}
/***********************************************************************
Name: Load Method
Purpose: Populate A
ay with objects from File, Database etc
Parameter: None
Return Value: None
E
or-code: Trap for FILE ACCESS & general exceptions
public void Load()
{
string path = "CustomerData.txt";
Step 1-Verifying if file Does NOT exists, otherwise create
if (!File.Exists(path))
{
Create the file
File.Create(path);
Console.WriteLine("New file created");
}
Step 2-Create Object of the StreamReader Class to Open file for reading
StreamReader objFileReader = new StreamReader(path);
Step 3-Declare variable to store line from file
And a
ay POINTER to store the a
ay returned from String.Split()method
string strLine;
string[] strA
ay;
Step 4-Create delimite
Char[] delimiter = { ',' };
Step 5-Read first line from the file
strLine = objFileReader.ReadLine();
Step 6-Test for EOF
while (strLine != null)
{
Step 7-Split string and assign results to a
ay pointe
strA
ay = strLine.Split(delimiter);
Step 8-Create a new Object
Customer objCustomer = new Customer();
Step 9-Extract parsed data from a
ay and SET object
objCustomer.IDNumber = strA
ay[0];
objCustomer.Name = strA
ay[1];
objCustomer.SSNumber = strA
ay[2];
objCustomer.BirthDate = strA
ay[3];
objCustomer.Address = strA
ay[4];
objCustomer.Phone = strA
ay[5];
objCustomer.Email = strA
ay[6];
Step 10-ADD object to a
ay
this.Add(objCustomer);
Step 11-Read NEXT line from the file
strLine = objFileReader.ReadLine();
}
Step 11-EOF reached. Close the reade
objFileReader.Close();
}
End of Function
/***********************************************************************
Name: Save Method
Purpose: Populate A
ay with objects from File, Database etc
Parameter: None
Return Value: None
E
or-code: Trap for FILE ACCESS & general exceptions
public void Save()
{
string path = "CustomerData.txt";
Step 1-Create object to open/create file for appending
StreamWriter objFileWriter = new StreamWriter(path, false);
Step 2-create variable to store comma-delimited line
string strLine;
Step 3-Begin to search a
ay Getting every object's properties
for (int i = 0; i < SIZE; i++)
{
if cell is empty skip it
if (m_a
CustomerList[i] != null)
{
Step 4-Create comma-delimited string
strLine = m_a
CustomerList[i].IDNumber + ",";
strLine = strLine + m_a
CustomerList[i].Name + ",";
strLine = strLine + m_a
CustomerList[i].SSNumber + ",";
strLine = strLine + m_a
CustomerList[i].BirthDate + ",";
strLine = strLine + m_a
CustomerList[i].Address + ",";
strLine = strLine + m_a
CustomerList[i].Phone + ",";
strLine = strLine + m_a
CustomerList[i].Email;
Step 5-Write line to file
objFileWriter.WriteLine(strLine);
}
}
Step 6-End of writing, close file
objFileWriter.Close();
}
End of Function
#endregion "Instance A
ay Processing Methods Declarations"
#region "Static Methods"
/***********************************************************************
No Static Methods created
#endregion
}
}
58705/SmallBusinessApp/SmallBusinessApp/frmCustomerMgt.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SmallBusinessApp
{
public partial class frmCustomerMgt : Form
{
#region "Modular-level Declarations"
Create object of the Customer List class
private CustomerList objCustomerList = new CustomerList();
Create Customer object POINTER only
private Customer objCustomer;
#endregion "Modular-level Declarations"
public frmCustomerMgt()
{
InitializeComponent();
}
private void btnExit_Click(object sender, EventArgs e)
{
Close this form
program flow automatically goes back to Main program Form
which opened this form aa a dialog form.
this.Close();
}
private void frmCustomerMgt_Load(object sender, EventArgs e)
{
Step 1-Load objects from file to collection
objCustomerList.Load();
Step 2 - SET Age Textbox for ReadOnly
txtAge.ReadOnly = true;
}
private void frmCustomerMgt_FormClosed(object sender, FormClosedEventArgs e)
{
Step 1-Destroy Form-Level Objects
objCustomer = null;
Step 2-Save objects from Collection to file
objCustomerList.Save();
Step 3-Clear the Collection
objCustomerList.Clear();
}
/***********************************************************************
Name: Search() Event-handle
Purpose: User enter’s ID in ID Number textbox
Calls objCustomerList.Search(ID) method to do the work
if customer found, data is displayed on form
if customer not found, user is prompted
private void btnSearch_Click(object sender, EventArgs e)
{
Step 1-Call Calls Collection.Item() Property to return pointer to object
in A
ay
objCustomer = objCustomerList.Search(txtIDNumber.Text.Trim());
Step 2-If validate customer is found
if (objCustomer != null)
{
Step 3-Then Data is extracted from customer object & placed on textboxes
txtIDNumber.Text = objCustomer.IDNumber;
txtName.Text = objCustomer.Name;
txtSSNumber.Text = objCustomer.SSNumber;
txtBirthDate.Text = objCustomer.BirthDate;
txtAge.Text = objCustomer.Age.ToString();
convert to a string
txtAddress.Text = objCustomer.Address;
txtPhone.Text = objCustomer.Phone;
txtEmail.Text = objCustomer.Email;
}
else
{
Step 4-prompt user customer not found
MessageBox.Show("Customer Not Found");
Step 5-Clear all controls
txtIDNumber.Text = "";
txtName.Text = "";
txtSSNumber.Text = "";
txtBirthDate.Text = "";
txtAge.Text = "";
txtAddress.Text = "";
txtPhone.Text = "";
txtEmail.Text = "";
}
End of Search
}
/***********************************************************************
Name: Form_Add_Click() Event-handle
Purpose: Adds new customer. Calls objCustomerList.Add() to do the work
Promps user of outcome.
private void btnAdd_Click(object sender, EventArgs e)
{
Step 1-Calls CustomerList.Add(Value1,Value2,.) pass text control arguments
bool success = objCustomerList.Add(txtIDNumber.Text.Trim(), txtName.Text.Trim(),
txtSSNumber.Text.Trim(), txtBirthDate.Text, txtAddress.Text.Trim(), txtPhone.Text.Trim(),
txtEmail.Text.Trim());
Process results
if (success)
{
Prompt user customer was added
MessageBox.Show("Customer Added");
}
else
{
prompt user no space avaiable
MessageBox.Show("No available space!");
}
}
End of Add
/***********************************************************************
Name: Form_Edit_Click() Event-handle
Purpose: Edits existing customer. Calls objCustomerList.Edit(x,y,z) to do the work
Promps user of outcome.
private void btnEdit_Click(object sender, EventArgs e)
{
Step 1-Calls CustomerList.Edit(Value1,Value2,.) pass text control arguments
bool success = objCustomerList.Edit(txtIDNumber.Text.Trim(), txtName.Text.Trim(),
txtSSNumber.Text.Trim(), txtBirthDate.Text, txtAddress.Text.Trim(), txtPhone.Text.Trim(),
txtEmail.Text.Trim());
Process results
if (success)
{
Prompt user customer was edited
MessageBox.Show("Customer Edited");
}
else
{
prompt user customer not found
MessageBox.Show("Customer Not Found!");
}
}
End of Edit
private void btnDelete_Click(object sender, EventArgs e)
{
Step 1-Call Calls Collection.Remove(ID) method to do the work
in A
ay
bool success = objCustomerList.Remove(txtIDNumber.Text.Trim());
Step 2-If validate customer is found
Process results
if (success)
{
Prompt user customer was edited
MessageBox.Show("Customer deleted");
}
else
{
prompt user customer not found
MessageBox.Show("Customer Not Found!");
}
}
/***********************************************************************
Name: Button Print_Click() Event-handle
Purpose: Prints existing customer to file.
Calls objCustomerList.Print(ID) to do the work
Promps user of outcome.
private void btnPrint_Click(object sender, EventArgs e)
{
Step 1-Call Calls objCustomerList.Print(ID) method to do the work
in A
ay
bool success = objCustomerList.Print(txtIDNumber.Text.Trim());
Step 2-If validate customer is found
Process results
if (success)
{
Prompt user customer was edited
MessageBox.Show(" ****Customer record sent to printer * ***");
}
else
{
prompt user customer not found
MessageBox.Show("Customer Not Found!");
}
}
/***********************************************************************
Name: Button PrintAll_Click() Event-handle
Purpose: Prints all existing customers to file.
Calls objCustomerList.PrintAll() to do the work
Promps user of outcome.
private void btnPrintAll_Click(object sender, EventArgs e)
{
Step 1-Call Calls objCustomerList.PrintAll() method to do the work
objCustomerList.PrintAll();
Prompt user all existing customers were printed
MessageBox.Show(" **** All Customer records sent to printer ***");
}
End of Print All
/***********************************************************************
Name: Button List_Click() Event-handle
Purpose: List all existing customers to the form's listbox.
Calls objCustomerList.GetA
ayCop() to return a copy of the
CustomerLIst A
ay so the UI can loop throught the COPY
getting data from each object in a
ay, creating a CSV line
and adding it to the Listbox.
private void btnList_Click(object sender, EventArgs e)
{
Step 1-Clear the listBox to avoid duplicates
lstListAll.Items.Clear();
Step 2- Create an ARRAY Pointer & Get a Pointer to COPY
of the a
CustomerList ARRAY inside objCustomerList object
via GetA
ayCopy() Method
Customer[] a
TempList = objCustomerList.GetA
ayCopy();
Step 3-create variable to store comma-delimited line
string strLine;
Step 4-Begin to search a
ay Getting every object's properties
for (int i = 0; i < a
TempList.GetUpperBound(0) + 1; i++)
{
Step 5-if cell is empty skip it
if (a
TempList[i] != null)
{
Step 6-Create comma-delimited string
strLine = a
TempList[i].IDNumber + ",";
strLine = strLine + a
TempList[i].Name + ",";
strLine = strLine + a
TempList[i].SSNumber + ",";
strLine = strLine + a
TempList[i].BirthDate + ",";
strLine = strLine + a
TempList[i].Address + ",";
strLine = strLine + a
TempList[i].Phone + ",";
strLine = strLine + a
TempList[i].Email;
Step 7-Add string to ListBox
lstListAll.Items.Add(strLine);
}
}
}
End of Event-handle
}
}
58705/SmallBusinessApp/SmallBusinessApp/frmCustomerMgt.Designer.cs
namespace SmallBusinessApp
{
partial class frmCustomerMgt
{
Required designer variable.
summary
private System.ComponentModel.IContainer components = null;
Clean up any resources being used.
summary
true if managed resources should be disposed; otherwise, false.
param
protected ove
ide void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
Required method for Designer support - do not modify
the contents of this method with the code editor.
summary
private void InitializeComponent()
{
this.grpCustomerData = new System.Windows.Forms.GroupBox();
this.btnPrintAll = new System.Windows.Forms.Button();
this.btnPrint = new System.Windows.Forms.Button();
this.btnDelete = new System.Windows.Forms.Button();
this.btnEdit = new System.Windows.Forms.Button();
this.btnAdd = new System.Windows.Forms.Button();
this.btnSearch = new System.Windows.Forms.Button();
this.txtEmail = new System.Windows.Forms.TextBox();
this.txtSSNumber = new System.Windows.Forms.TextBox();
this.txtBirthDate = new System.Windows.Forms.TextBox();
this.txtAge = new System.Windows.Forms.TextBox();
this.txtAddress = new System.Windows.Forms.TextBox();
this.txtPhone = new System.Windows.Forms.TextBox();
this.txtName = new System.Windows.Forms.TextBox();
this.txtIDNumber = new System.Windows.Forms.TextBox();
this.lblEmail = new System.Windows.Forms.Label();
this.lblPhone = new System.Windows.Forms.Label();
this.lblAddress = new System.Windows.Forms.Label();
this.lblAge = new System.Windows.Forms.Label();
this.lblBirthDate = new System.Windows.Forms.Label();
this.lblSSNumber = new System.Windows.Forms.Label();
this.lblName = new System.Windows.Forms.Label();
this.lblIDNumber = new System.Windows.Forms.Label();
this.lblTitle = new System.Windows.Forms.Label();
this.grpList = new System.Windows.Forms.GroupBox();
this.lstListAll = new System.Windows.Forms.ListBox();
this.btnList = new System.Windows.Forms.Button();
this.grpExit = new System.Windows.Forms.GroupBox();
this.btnExit = new System.Windows.Forms.Button();
this.grpCustomerData.SuspendLayout();
this.grpList.SuspendLayout();
this.grpExit.SuspendLayout();
this.SuspendLayout();
grpCustomerData
this.grpCustomerData.Controls.Add(this.btnPrintAll);
this.grpCustomerData.Controls.Add(this.btnPrint);
this.grpCustomerData.Controls.Add(this.btnDelete);
this.grpCustomerData.Controls.Add(this.btnEdit);
this.grpCustomerData.Controls.Add(this.btnAdd);
this.grpCustomerData.Controls.Add(this.btnSearch);
this.grpCustomerData.Controls.Add(this.txtEmail);
this.grpCustomerData.Controls.Add(this.txtSSNumber);
this.grpCustomerData.Controls.Add(this.txtBirthDate);
this.grpCustomerData.Controls.Add(this.txtAge);
this.grpCustomerData.Controls.Add(this.txtAddress);
this.grpCustomerData.Controls.Add(this.txtPhone);
this.grpCustomerData.Controls.Add(this.txtName);
this.grpCustomerData.Controls.Add(this.txtIDNumber);
this.grpCustomerData.Controls.Add(this.lblEmail);
this.grpCustomerData.Controls.Add(this.lblPhone);
this.grpCustomerData.Controls.Add(this.lblAddress);
this.grpCustomerData.Controls.Add(this.lblAge);
this.grpCustomerData.Controls.Add(this.lblBirthDate);
this.grpCustomerData.Controls.Add(this.lblSSNumber);
this.grpCustomerData.Controls.Add(this.lblName);
this.grpCustomerData.Controls.Add(this.lblIDNumber);
this.grpCustomerData.Location = new System.Drawing.Point(48, 62);
this.grpCustomerData.Name = "grpCustomerData";
this.grpCustomerData.Size = new System.Drawing.Size(442, 368);
this.grpCustomerData.TabIndex = 0;
this.grpCustomerData.TabStop = false;
btnPrintAll
this.btnPrintAll.Location = new System.Drawing.Point(361, 304);
this.btnPrintAll.Name = "btnPrintAll";
this.btnPrintAll.Size = new System.Drawing.Size(75, 23);
this.btnPrintAll.TabIndex = 38;
this.btnPrintAll.Text = "Print All";
this.btnPrintAll.UseVisualStyleBackColor = true;
this.btnPrintAll.Click += new System.EventHandler(this.btnPrintAll_Click);
btnPrint
this.btnPrint.Location = new System.Drawing.Point(361, 248);
this.btnPrint.Name = "btnPrint";
this.btnPrint.Size = new System.Drawing.Size(75, 23);
this.btnPrint.TabIndex = 37;
this.btnPrint.Text = "Print";
this.btnPrint.UseVisualStyleBackColor = true;
this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
btnDelete
...