Quantcast
Channel: code
Viewing all articles
Browse latest Browse all 9

code

$
0
0

thanks for the assist you have give me i have short some problem but the edit and delete code does not work properly. here is the new code help me to success full making of this code

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

namespace Project
{
    class Assistant
    {

        public string Name;
        public string Address;
        public string Phone;
        public string EmailID;//For adding details in Contact

        public string Meeting_Subject;
        public string Meeting_Address;
        public string Meeting_DATE;//For adding details in Meeting

        string Str, CheckStr1, CheckStr2;
        string N; int Pos;//For retriving data from Contact and Meeting

        static FileStream F;
        StreamWriter W;
        StreamReader R;      

        public void ShowIntro()
        {
            Console.WriteLine("\n\t\t\t****Welcome****");
            Console.WriteLine("\n\t\t\t****Personal Assistant****");
            Console.WriteLine("\n(1.) Contact");

            Console.WriteLine("\n(2.) Meetings\\Appointment");

            Console.WriteLine("\nPress 1 OR 2 to Select any of the above Operations");

            Main_Menu_Condition_For_Contact();
        }

        public void Main_Menu_Condition_For_Contact()
        {
            int InputNum = Convert.ToInt32(Console.ReadLine());
            while ((InputNum < 1) || (InputNum > 2))
            {
                Console.WriteLine("\nINVALID NUMBER ENTERED.Before You can continue Enter 1 OR 2");
                InputNum = Convert.ToInt32(Console.ReadLine());
            }
            if (InputNum == 1)
            {
                Console.Write("\n\t\t*****SUBMENUS FOR CONTACT*****");
                Console.WriteLine("\n(1.) Add new Contact");
                Console.WriteLine("\n(2.) Delete Contact");
                Console.WriteLine("\n(3.) Edit Contact");
                Console.WriteLine("\n(4.) Search Contact");

                Console.WriteLine("\nPress 1,2,3 OR 4 to Select any of the above Operations");
                SubMenuCondition_ForContact();
            }
            else if (InputNum == 2)
            {
                Console.Write("\n\t\t***** SUBMENUS FOR MEETING//APPOINTMENT *****");
                Console.WriteLine("\n(1.) Add an Appointment ");
                Console.WriteLine("\n(2.) Delete an Appointment");
                Console.WriteLine("\n(3.) Edit an Appointment");
                Console.WriteLine("\n(4.) Search for an Appointment");
                Console.WriteLine("\nPress 1,2,3 OR 4 to Select any of the above Operations");
                Sub_Menu_Condition_for_Meeting();
            }

        }
        public void SubMenuCondition_ForContact()
        {
            int InputMenu2 = Convert.ToInt32(Console.ReadLine());
            while ((InputMenu2 < 1) || (InputMenu2 > 4))
            {
                Console.WriteLine("\nINVALID NUMBER ENTERED.Before You can continue Enter 1,2,3 OR 4");
                InputMenu2 = Convert.ToInt32(Console.ReadLine());
            }
            switch (InputMenu2)
            {
                case 1:
                    {
                        AddContact();
                    }
                    break;
                case 2:
                    {
                        DELETE();
                    }
                    break;
                case 3:
                    {
                        Edit_Contact();
                    }
                    break;
                case 4:
                    {
                        Search_Contact();
                    }
                    break;
                default:
                    Console.WriteLine("\nNo operation for that value");
                    break;
            }
        }

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

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

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

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

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

            W.Flush();
            W.Close();
            F.Close();
        }
        public void DELETE()
        {  
            F = new FileStream("Contacts.txt", FileMode.Open, FileAccess.ReadWrite, FileShare.Delete);
            R = new StreamReader(F);
            
            R.BaseStream.Seek(0, SeekOrigin.Begin);            
            Boolean found = false;
            Console.WriteLine("\nEnter the Name which to delete"); 
            
            if ((Str = R.ReadLine()) != null && (found == false))
            {
                string Receive = R.ReadLine();
                CheckStr1 = Name = Console.ReadLine() + N;
                Pos = Str.IndexOf("?");
                CheckStr2 = Str.Substring(0, Pos);
                if ((CheckStr1.CompareTo(CheckStr2)) == 0)                
                {
                    found = true;                  
                    File.Delete(Name=Receive);
                    Str = Str.Substring(Pos + 1);                    
                } Pos = 0;                  
            }                
                R.Close();
                F.Close();
        }
        public void Edit_Contact()
        {            
            F = new FileStream("Contacts.txt", FileMode.Open, FileAccess.ReadWrite, FileShare.Inheritable);
            R = new StreamReader(F);
            Console.Write("Enter name: ");
            N = Console.ReadLine();

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

                //R.Close();
                Console.Write("Enter Name: ", Str.Substring(0, Pos));
                Name = Console.ReadLine();
                Console.Write("Enter Address :");
                Address = Console.ReadLine();
                Console.Write("Enter Phone :");
                Phone = Console.ReadLine();
                Console.Write("Enter Email :");
                EmailID = Console.ReadLine();                
                
                W = new StreamWriter(F);
                W.Write("Name: " + Name);
                W.Write("?");
                W.Write("Address: " + Address);
                W.Write("?");
                W.Write("Phone #: " + Phone);
                W.Write("?");
                W.Write("EmailID : " + EmailID);
                W.WriteLine("?");                
                Console.WriteLine("\nYou have Successfully Modified Your Record");
            }
            W.Flush();
            W.Close();
            F.Close();
        }
        public void Search_Contact()
        {            
            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();
        }
        public void Sub_Menu_Condition_for_Meeting()
        {
            //Variable to Accept A Valid Value
            int InputMenu2 = Convert.ToInt32(Console.ReadLine());

            //Input Validation Condition

            while ((InputMenu2 < 1) || (InputMenu2 > 4))
            {
                Console.WriteLine("\nINVALID NUMBER ENTERED.Before You can continue Enter 1,2,3 OR 4");
                //Variable to accept a Value
                InputMenu2 = Convert.ToInt32(Console.ReadLine());
            }
            //Statement to Carry out operation from any of the SubMenu Options

            //int InputSelectionForContact;
            switch (InputMenu2)
            {

                case 1:
                    {
                        Add_Meeting();
                    }
                    break;
                case 2:
                    {
                        DELETE_Meeting();
                    }
                    break;
                case 3:
                    {
                        Edit_Meeting();
                    }
                    break;
                case 4:
                    {
                        Search_Meeting();
                    }
                    break;
                default:
                    Console.WriteLine("\nNo operation for that value");
                    break;

            }


        }

        public void Add_Meeting()
        {
            Console.Write("Enter Meeting_Subject: ");
            Meeting_Subject = Console.ReadLine();

            Console.Write("Enter Meeting_Address: ");
            Meeting_Address = Console.ReadLine();

            Console.Write("Enter Meeting_DATE: ");
            Meeting_DATE = (Console.ReadLine());

            F = new FileStream("Meeting.txt", FileMode.Append, FileAccess.Write);
            W = new StreamWriter(F);
            //Writing data into the file
            W.Write("Meeting_Subject: " + Meeting_Subject);
            W.Write("?");
            W.Write("Meeting_Address: " + Meeting_Address);
            W.Write("?");
            W.Write("Meeting_DATE: " + Meeting_DATE);
            W.Write("?");

            W.Flush();
            W.Close();
        }
        public void DELETE_Meeting()
        {
            F = new FileStream("Meeting.txt", FileMode.Open, FileAccess.ReadWrite, FileShare.Delete);
            R = new StreamReader(F);
            
            R.BaseStream.Seek(0, SeekOrigin.Begin);

            string Receive = R.ReadLine();


            Boolean found = false;

            Console.WriteLine("\nEnter the Subject of the meeting that which to delete");

            Meeting_Subject = Console.ReadLine();

            Meeting_Subject = Receive;

            while ((Receive != null) && (found == false))
            {
                if (Receive == Meeting_Subject)
                {
                    found = true;
                    Meeting_Subject = Receive;
                    File.Delete(Meeting_Subject);
                }
                R.Close();
                F.Close();
            }

            Console.WriteLine("\nThe Meeting has been Deleted");
        }

        public void Edit_Meeting()
        {

            F = new FileStream("Meeting.txt", FileMode.Open, FileAccess.ReadWrite, FileShare.Inheritable);
            R = new StreamReader(F);
            Console.Write("Enter Meeting_Subject: ");
            N = Console.ReadLine();

            if ((Str = R.ReadLine()) != null)
            {
                CheckStr1 = "Meeting_Subject: " + 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);
                    }
                }

                //R.Close();
                Console.Write("Enter Meeting_Subject: ", Pos += 0);
                Meeting_Subject = Console.ReadLine();
                Console.Write("Enter Meeting_Address :");
                Meeting_Address = Console.ReadLine();
                Console.Write("Enter Meeting_DATE :");
                Meeting_DATE = Console.ReadLine();

                W = new StreamWriter(F);
                W.Write("Meeting_Subject: " + Meeting_Subject);
                W.Write("?");
                W.Write("Meeting_Address: " + Meeting_Address);
                W.Write("?");
                W.Write("Meeting_Date: " + Meeting_DATE);
                W.Write("?");               
                Console.WriteLine("\nYou have Successfully Modified Your Record");
            }
            W.Flush();
            W.Close();
            F.Close();
        }
        public void Search_Meeting()
        {
            string Str, CheckStr1, CheckStr2;
            string N; int Pos;
            F = new FileStream("Meeting.txt", FileMode.Open, FileAccess.Read);
            R = new StreamReader(F);
            Console.Write("Enter Meeting_Subject: ");
            N = Console.ReadLine();

            //Code to fetch data and display in proper format

            while ((Str = R.ReadLine()) != null)
            {
                CheckStr1 = "Meeting_Subject: " + 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();

        }
        public static void Main(string[] args)
        {

            Assistant ps = new Assistant();

            string keepgoing = "yes";
            do
            {
                Console.BackgroundColor = ConsoleColor.DarkMagenta;
                Console.ForegroundColor = ConsoleColor.White;
                Console.Clear();
                 ps.ShowIntro();
                Console.WriteLine("\nWill You Like To Perform Another Operation.");
                Console.WriteLine("\nEnter yes to go back to the Main Menu or any other key to cancel");
                keepgoing = Console.ReadLine();
                Console.Clear();
            } while (keepgoing.Equals("yes"));

        }

    }
}


surajit halder


Viewing all articles
Browse latest Browse all 9

Trending Articles


Vimeo 10.7.1 by Vimeo.com, Inc.


UPDATE SC IDOL: TWO BECOME ONE


KASAMBAHAY BILL IN THE HOUSE


Girasoles para colorear


Presence Quotes – Positive Quotes


EASY COME, EASY GO


Love with Heart Breaking Quotes


Re:Mutton Pies (lleechef)


Ka longiing longsem kaba skhem bad kaba khlain ka pynlong kein ia ka...


Vimeo 10.7.0 by Vimeo.com, Inc.


FORECLOSURE OF REAL ESTATE MORTGAGE


FORTUITOUS EVENT


Pokemon para colorear


Sapos para colorear


Smile Quotes


Letting Go Quotes


Love Song lyrics that marks your Heart


RE: Mutton Pies (frankie241)


Hato lada ym dei namar ka jingpyrshah jong U JJM Nichols Roy (Bah Joy) ngin...


Long Distance Relationship Tagalog Love Quotes



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>