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/bin/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/bin/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/bin/Debug/SmallBusinessApp.exe
58705/SmallBusinessApp/SmallBusinessApp/bin/Debug/SmallBusinessApp.exe.config
58705/SmallBusinessApp/SmallBusinessApp/bin/Debug/SmallBusinessApp.pdb
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 Provider
namespace SmallBusinessApp
{
public class Customer
{
#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 IDNumber
{
get { return m_IDNumber; }
set { m_IDNumber = value; }
}
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}
public string SSNumber
{
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
//being 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
//birth date passed as parameter
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
//current 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 number
//If TRUE, subtract 1 day from the age, otherwise do nothing since
//you already have the correct 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 Error 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 error 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 Error 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 error 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 Error 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 error 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 Error 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 error 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 Array here
private const int SIZE = 10;
private Customer[] m_arrCustomerList;
#endregion
#region "Properties Declarations"
/***********************************************************************/
//Create Properties here. NO PROPERTIES AT THE MOMENT
#endregion
#region "Constructor Methods Declarations"
/***********************************************************************/
//Default Constructor method
public CustomerList()
{
m_arrCustomerList = new Customer[SIZE]; //Creating Array of objects
}
/***********************************************************************/
//Parameterized Constructor. NO PARAMETERIZED CONSTRUCTOR
/***********************************************************************/
//Destructor
~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
//Error-code: Trap for array & 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_arrCustomerList[i] != null)
{
//Ask if this is object you are looking for?
if (m_arrCustomerList[i].IDNumber == ID)
//return array pointer
return m_arrCustomerList[i];
}
}
//searched all array and did not find object. Return a null
return null;
}
/***********************************************************************/
//Name: Add Method
//Purpose: Search for empty cell in array and add Customer object
//Parameter: Customer Object to be added
//Return Value: True if empty cell found, false otherwise
//Error-code: Trap for array & general exceptions
public bool Add(Customer objCustomer)
{
//Begin search for empty cell
for (int i = 0; i < SIZE; i++)
{
//find empty cell
if (m_arrCustomerList[i] == null)
{
//Add object to array
m_arrCustomerList[i] = objCustomer;
//Success, return true
return true;
}
}
return false; //Searched array, 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 array,
// Add Customer Object to Array
//Parameter: Variables for customer name, ID, birthdate, address and age
//Return Value: True if empty cell found, false otherwise
//Error-code: Trap & rethrow array & 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_arrCustomerList[i] == null)
{
//Add object to array
m_arrCustomerList[i] = objCustomer;
//Success, return true
return true;
}
}
return false; //Searched array, no empty cell found. Return false
}
/***********************************************************************/
//Name: Edit Method
//Purpose: Search for Customer Object by ID
// When found replace existing object with object in parameter
//Parameter: Customer Object to be added
//Return Value: True if object found, false otherwise
//Error-code: Trap for array & 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_arrCustomerList[i] != null)
{
//Ask if this is object you are looking for?
if (m_arrCustomerList[i].IDNumber == objCustomer.IDNumber)
{
//Replace exiting object, by adding new one
//Set each property & return true.
//IMPORTANT. IDNUMBER NOT SET
m_arrCustomerList[i].Name = objCustomer.Name;
m_arrCustomerList[i].SSNumber = objCustomer.SSNumber;
m_arrCustomerList[i].BirthDate = objCustomer.BirthDate;
m_arrCustomerList[i].Address = objCustomer.Address;
m_arrCustomerList[i].Phone = objCustomer.Phone;
m_arrCustomerList[i].Email = objCustomer.Email;
//Success, return true
return true;
}
}
}
//searched all array 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 parameter
// 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
//Error-code: Trap & rethrow array & 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_arrCustomerList[i] != null)
{
//Ask if this is object you are looking for?
if (m_arrCustomerList[i].IDNumber == idNum)
{
//Set each property & return true.
//IMPORTANT. IDNUMBER NOT SET
m_arrCustomerList[i].Name = name;
m_arrCustomerList[i].SSNumber = SSNum;
m_arrCustomerList[i].BirthDate = bDate;
m_arrCustomerList[i].Address = address;
m_arrCustomerList[i].Phone = phone;
m_arrCustomerList[i].Email = email;
//Success, return true
return true;
}
}
}
//searched all array and did not find object. Return a null
return false;
}
/***********************************************************************/
//Name: Remove Method
//Purpose: Search for Customer object by ID
// Remove object from array by setting array pointer to null
//Parameter: Customer ID
//Return Value: True if found, false otherwise
//Error-code: Trap for array & 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_arrCustomerList[i] != null)
{
//Ask if this is object you are looking for?
if (m_arrCustomerList[i].IDNumber == ID)
{
//Set Array pointer to NULL
m_arrCustomerList[i] = null;
//Success, return true
return true;
}
}
}
//searched all array 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
//Error-code: Trap for array & 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_arrCustomerList[i] != null)
{
//Ask if this is object you are looking for?
if (m_arrCustomerList[i].IDNumber == ID)
{
//Call object.Print() method
m_arrCustomerList[i].Print();
return true; //Success, return true
}
}
}
//searched all array 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
//Error-code: Trap for array & general exceptions
public void PrintAll()
{
//Begin search
for (int i = 0; i < SIZE; i++)
{
//if cell is empty skip it
if (m_arrCustomerList[i] != null)
{
//Call object.Print() method
m_arrCustomerList[i].Print();
}
}
}
/***********************************************************************/
//Name: Clear Method
//Purpose: Clears all elements of array using Array Class method
//Parameter: None
//Return Value: None
//Error-code: Trap for general exceptions
public void Clear()
{
//Call Clear Static Method - Array.Clear(array, startIndex, count);
Array.Clear(m_arrCustomerList, m_arrCustomerList.GetLowerBound(0),
m_arrCustomerList.GetUpperBound(0) + 1);
}
/***********************************************************************/
//Name: GetArrayCopy Method
//Purpose: to get a copy of arrCustomerList & return the copy
//Parameter: None
//Return Value: Pointer of copy version of objCustomerList
//Error-code: Trap for general exceptions
public Customer[] GetArrayCopy()
{
//Create temp array
Customer[] arrTemp = new Customer[SIZE];
m_arrCustomerList.CopyTo(arrTemp, m_arrCustomerList.GetLowerBound(0));
return arrTemp;
}
/***********************************************************************/
//Name: Load Method
//Purpose: Populate Array with objects from File, Database etc
//Parameter: None
//Return Value: None
//Error-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 array POINTER to store the array returned from String.Split()method
string strLine;
string[] strArray;
//Step 4-Create delimiter
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 array pointer
strArray = strLine.Split(delimiter);
//Step 8-Create a new Object
Customer objCustomer = new Customer();
//Step 9-Extract parsed data from array and SET object
objCustomer.IDNumber = strArray[0];
objCustomer.Name = strArray[1];
objCustomer.SSNumber = strArray[2];
objCustomer.BirthDate = strArray[3];
objCustomer.Address = strArray[4];
objCustomer.Phone = strArray[5];
objCustomer.Email = strArray[6];
//Step 10-ADD object to array
this.Add(objCustomer);
//Step 11-Read NEXT line from the file
strLine = objFileReader.ReadLine();
}
//Step 11-EOF reached. Close the reader
objFileReader.Close();
}//End of Function
/***********************************************************************/
//Name: Save Method
//Purpose: Populate Array with objects from File, Database etc
//Parameter: None
//Return Value: None
//Error-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 array Getting every object's properties
for (int i = 0; i < SIZE; i++)
{
//if cell is empty skip it
if (m_arrCustomerList[i] != null)
{
//Step 4-Create comma-delimited string
strLine = m_arrCustomerList[i].IDNumber + ",";
strLine = strLine + m_arrCustomerList[i].Name + ",";
strLine = strLine + m_arrCustomerList[i].SSNumber + ",";
strLine = strLine + m_arrCustomerList[i].BirthDate + ",";
strLine = strLine + m_arrCustomerList[i].Address + ",";
strLine = strLine + m_arrCustomerList[i].Phone + ",";
strLine = strLine + m_arrCustomerList[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 Array 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-handler
//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 Array
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-handler
//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-handler
//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 Array
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-handler
//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 Array
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-handler
//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-handler
//Purpose: List all existing customers to the form's listbox.
// Calls objCustomerList.GetArrayCop() to return a copy of the
// CustomerLIst Array so the UI can loop throught the COPY
// getting data from each object in array, 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 arrCustomerList ARRAY inside objCustomerList object
//via GetArrayCopy() Method
Customer[] arrTempList = objCustomerList.GetArrayCopy();
//Step 3-create variable to store comma-delimited line
string strLine;
//Step 4-Begin to search array Getting every object's properties
for (int i = 0; i < arrTempList.GetUpperBound(0) + 1; i++)
{
//Step 5-if cell is empty skip it
if (arrTempList[i] != null)
{
//Step 6-Create comma-delimited string
strLine = arrTempList[i].IDNumber + ",";
strLine = strLine + arrTempList[i].Name + ",";
strLine = strLine + arrTempList[i].SSNumber + ",";
strLine = strLine + arrTempList[i].BirthDate + ",";
strLine = strLine + arrTempList[i].Address + ",";
strLine = strLine + arrTempList[i].Phone + ",";
strLine = strLine + arrTempList[i].Email;
//Step 7-Add string to ListBox
lstListAll.Items.Add(strLine);
}
}
}//End of Event-handler
}
}
58705/SmallBusinessApp/SmallBusinessApp/frmCustomerMgt.Designer.cs
namespace SmallBusinessApp
{
partial class frmCustomerMgt
{
///
/// Required designer variable.
/// private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
/// ///
true if managed resources should be disposed; otherwise, false.
protected override 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.
/// 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
//
...