Personal Assistant Console Application using C#

  • Thread starter Thread starter Rudra Paul
  • Start date Start date
R

Rudra Paul

Guest
Hello!
This application would assist the users to store and retrieve personal information. According to the requirement specifications, the software should provide the functionality to store contact details of various people.
Design specifications
When the application is executed, a menu with the following options should be displayed
  • Add new record
  • Delete record
  • Edit record
  • Search record
The contact details option would enable the user to add, edit, delete, and search the contact details of various people. the contact include information such as name, address, phone number, and email address.
Note: the address book and the meetings/appointment details should be stored in separate files(text files not in Database)

And the details should be stored in text files but not in database. Please help me.
I have written the code for Adding and Searching records but dont know how to edit and delete records.

This is the code i have written so far:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Personal_Assistant
{
class Contact
{
struct details
{
public string Name;
public string Address;
public string Phone;
public string EmailID;
};
private details Testdetails;
static FileStream F;
StreamWriter W;
StreamReader R;

public void GetContactData()
{
Console.Write("Enter Name: ");
Testdetails.Name = Console.ReadLine();

Console.Write("Enter Address: ");
Testdetails.Address = Console.ReadLine();

Console.Write("Enter Phone #: ");
Testdetails.Phone = (Console.ReadLine());

Console.Write("Enter Email Address: ");
Testdetails.EmailID = Console.ReadLine();

F = new FileStream("Contacts.txt", FileMode.Append, FileAccess.Write);
W = new StreamWriter(F);

//Writing data into the file
W.Write("Name: " + Testdetails.Name);
W.Write("?");
W.Write("Address: " + Testdetails.Address);
W.Write("?");
W.Write("Phone #: " + Testdetails.Phone);
W.Write("?");
W.Write("EmailID : " + Testdetails.EmailID);
W.WriteLine("?");

W.Flush();
W.Close();
}

public void Search_Contact()
{
string Str, CheckStr1, CheckStr2;
string N; int Pos;
F = new FileStream("Contacts.txt", FileMode.Open, FileAccess.Read);
R= new StreamReader(F);
Console.Write("Enter name: ");
N=Console.ReadLine();

//Code to fetch data and display in proper format

while((Str=R.ReadLine())!=null)
{
CheckStr1="Name: "+N;
Pos=Str.IndexOf("?");
CheckStr2=Str.Substring(0,Pos);

if ((CheckStr1.CompareTo(CheckStr2))==0)
{
while(true)
{
Pos = Str.IndexOf("?");
if (Pos==-1)
break;
Console.WriteLine(Str.Substring(0,Pos));

Str=Str.Substring(Pos+1);
}
Pos=0;
}
}
R.Close();
}

static void Main(string[] args)
{
Contact C = new Contact();
int M = 0;
Console.Clear();
while (M != 2)
{
Console.WriteLine("1. Add new record");
Console.WriteLine("2. Search new record");
Console.Write("Enter Choice: ");
M = Convert.ToInt32(Console.ReadLine());
switch (M)
{
case 1: Console.Clear();
C.GetContactData();
Console.Clear();
break;
case 2: Console.Clear();
C.Search_Contact();
Console.ReadLine();
Console.Clear();
break;
default: Console.WriteLine("Invalid input");
break;
}
}
Console.ReadLine();
}
}
}



Continue reading...
 
Back
Top