Need Little help

Discussion in 'C#' started by DeadSoul, Sep 6, 2010.

  1. DeadSoul

    DeadSoul New Member

    Joined:
    Sep 6, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I have made a program in c# where the user will input some data and that program should prompt the user to specify the date to view all the appointments of that day.i have made the code but still the problem lies is i can only find that the date which is entered by the user is there in the file but i dont dont know how to display the data related to it please help me..the code is as follow
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    
    
    namespace FileData
    {
        class Program
        {
            DateTime date = new DateTime();
            DateTime time = new DateTime();
    
            string name;
            public void Inputdata()
            {
                FileStream fs = new FileStream("C:\\Data.txt",FileMode.Append,FileAccess.Write,FileShare.Write);
                StreamWriter sw = new StreamWriter(fs);
    
                Console.WriteLine("Enter the date in format {dd/mm/yyyy} :: ");
                date = DateTime.Parse(Console.ReadLine());
                sw.WriteLine("-------------------------------------------");
                sw.WriteLine("Date :: "+date);
               
    
                Console.WriteLine("Enter the name of the person you want to meet :: ");
                name = Console.ReadLine();
                sw.WriteLine("Name of the person :: "+name);
               
    
                Console.WriteLine("Enter the your visit time in format {HH:MM:SS} :: ");
                time = DateTime.Parse(Console.ReadLine());
                sw.WriteLine("Visit time :: "+time);
                sw.WriteLine("-------------------------------------------\n");
                sw.Close();
               // sw.Flush();
                fs.Close();
            }
            public void Displaydata()
            {
                FileStream fs1 = new FileStream("C:\\Data.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
                StreamReader sr = new StreamReader(fs1);
                sr.BaseStream.Seek(0, SeekOrigin.Begin);
    
                string r1 = sr.ReadLine();
                Console.WriteLine("File Data :: \n");
                //Console.WriteLine("\n");
                while (r1 != null)
                {
                    Console.WriteLine("{0}", r1);
                    
                    r1 = sr.ReadLine();
                
                }
               // Console.WriteLine(r1);
    
                sr.Close();
                fs1.Close();
            }
    
            public void search()
            {
                string fName = @"C:\Data.txt ";
                StreamReader testTxt = new StreamReader(fName);
                string allRead = testTxt.ReadToEnd();
                 
                Console.WriteLine("Enter the date in format {dd/mm/yyyy} :: ");
                DateTime search1 = new DateTime(); 
                string s =  search1.ToString(Console.ReadLine());
                
           
                if (allRead.Contains(s))
                {
                   Console.WriteLine("Found");
                 
                }
                else
                {
                    Console.WriteLine("not found");
                }
    
                testTxt.Close();
            }
            static void Main(string[] args)
            {
                Program p = new Program();
              
    
                Console.WriteLine("1. Enter a data into file  ");
                Console.WriteLine("2. View the data from file  ");
                Console.WriteLine("3. Search according to date  ");
                Console.WriteLine("4. Exit \n");
                Console.WriteLine("Enter your choice :: ");
                int a = Convert.ToInt32(Console.ReadLine());
    
                switch (a)
                {
    
                    case 1: p.Inputdata();
                        break;
                    case 2: p.Displaydata();
                        break;
                    case 3: p.search();
                        break;
                    case 4: System.Environment.Exit(0);
                        break;
    
                    default: Console.WriteLine("Please enter the correct choice");
                        break;
                }
    
                Console.ReadLine();
            }
        }
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice