CFanatic

Go Back   CFanatic > Programming > C# Programming

Join CFanatic Forum Now

Need Little help topic posted under C# Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 09-06-2010, 11:04 AM
Junior Member
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
DeadSoul is on a distinguished road
| More
Need Little help

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();
        }
    }
}

Last edited by shabbir; 09-06-2010 at 12:02 PM. Reason: C
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 04:01 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board