I am doing an appointment program wherein I am adding few appointments based on date and stored in a text file. I have a problem in displaying the appointment details according to the date entered.The stored appointments in a text file looks like this..
Date & Time :08/08/2013 09:30 AM Person Name :Shiv
Date & Time :08/08/2013 10:30 AM Person Name :Sanjay
Date & Time :10/08/2013 09:30 PM Person Name :Kumar
Problem is when I enter any date to search appointments,suppose there are 2 appointments for that particular date, my output is showing only one appointment.
Example: If I enter date 08/08/2013,There are 2 appointments stored in text file for the entered date but my output is showing only one appointment like this
Appointment Details
08/08/2013 09:30 AM Person Name :Shiv
My code:
Console.WriteLine("Enter the date to search appointment in (dd/mm/yyyy) format");
string Date = Console.ReadLine();
string str = sr.ReadToEnd();
bool isDate = File.ReadAllText("E:\\Practice/C#/MySchedular.txt").Contains(Date) ? true : false;
if (isDate)
{
string searchWithinThis = str; ;
int CharacterPos = searchWithinThis.IndexOf(Date);
sr.BaseStream.Seek(CharacterPos ,SeekOrigin.Begin);
str = sr.ReadLine();
Console.WriteLine("\n*********Appointment Details*********");
Console.WriteLine("{0}", str);
Console.WriteLine("\n");
}
else
{
Console.WriteLine("No appointment details found for the entered date");
}