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

code

$
0
0

I have worked on personal assistant code on visual c# code was built successfully but edit delete and search function doesn't work properly help me to get of it.

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

namespace Project
{
    class Assistant
    {
        bool found = false;
        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()
        {
            try
            {
                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();
                }

            }
            catch (FormatException E)
            {
                Console.WriteLine(E.Message);
            }
        }
        private 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.WriteLine("\nHow many Contacts do want to Add");
            int Add = Convert.ToInt32(Console.ReadLine());
            FileStream fs = new FileStream("@PersonalAssistant.txt", FileMode.Append, FileAccess.Write);
            StreamWriter W = new StreamWriter(fs);


            string NameContact;
            double ContactPhone;
            string Address;
            string Email;
           
            for (int Index = 0; Index < Add; Index++)
            {
                Console.Write("\nEnter Namecontact {0}", Index + 1);
                NameContact = Console.ReadLine();
                Console.WriteLine();
                Console.Write("\nEnter ContactPhone");
                ContactPhone = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine();
                Console.Write("\nEnter Address");
                Address = Console.ReadLine();
                Console.WriteLine();
                Console.Write("\nEnter Email");
                Email = Console.ReadLine();
                Console.WriteLine();
                Console.WriteLine();
                W.Write(NameContact);
                W.Write("?");
                W.Write(ContactPhone);
                W.Write("?");
                W.Write(Address);
                W.Write("?");
                W.Write(Email);
                W.Write("?");
                W.WriteLine();
                Console.WriteLine("\nYour Contact Has been Added");
            }
            W.Flush();
            W.Close();
            fs.Close();
        }
        public void DELETE()
        {
            FileStream fs = new FileStream("@PersonalAssistant.txt", FileMode.Open, FileAccess.Read, FileShare.Delete);
            StreamReader sr = new StreamReader(fs);

            sr.BaseStream.Seek(0, SeekOrigin.Begin);

            string Receive = sr.ReadLine();


            Boolean found = false;

            Console.WriteLine("\nEnter the Name of contact that which to delete from the file");

            string SearchValue = Console.ReadLine();

            SearchValue = Receive;

            while ((Receive != null) && (found == false))
            {
                if (Receive == SearchValue)
                {
                    found = true;
                    SearchValue = Receive;
                    File.Delete(SearchValue);
                }
                sr.Close();
                fs.Close();
            }
            Console.WriteLine("\nThe Data has been Deleted");
        }
        public void Edit_Contact()
        {
            FileStream fs = new FileStream("@PersonalAssistant.txt", FileMode.Append, FileAccess.Write, FileShare.Inheritable);
            StreamWriter sr = new StreamWriter(fs);


            Console.WriteLine("\nHow Many Contact do which to modify");
            int Number = Convert.ToInt32(Console.ReadLine());

            for (int Index = 0; Index < Number; Index++)
            {
                Console.WriteLine("\nEnter the New NameContact for contact {0}", Index + 1);
                string NameContact = Console.ReadLine();

                Console.WriteLine("\nEnter the New ContactPhone Number");
                double ContactPhone = Convert.ToDouble(Console.ReadLine());

                Console.WriteLine("\nEnter the New Address for Contact");
                string Address = Console.ReadLine();
                Console.WriteLine("\nEnter new Email");
                string Email = Console.ReadLine();
                //Display Blank Line
                Console.WriteLine();

                sr.WriteLine(NameContact);
                sr.WriteLine(ContactPhone);
                sr.WriteLine(Address);
                sr.WriteLine(Email);

            }
            sr.Flush();
            sr.Close();
            fs.Close();
            Console.WriteLine("\nYou have Successfully Modified Your Record");

        }
        public void Search_Contact()
        {
            FileStream fs = new FileStream("@PersonalAssistant.txt", FileMode.Open, FileAccess.Read);
            StreamReader sr = new StreamReader(fs);

            sr.BaseStream.Seek(0, SeekOrigin.Begin);


            string NameContact, Address, Email;
            double Contactphone;

            NameContact = Convert.ToString (sr.ReadLine());
            Contactphone = Convert.ToDouble(sr.ReadLine());
            Address = Convert.ToString(sr.ReadLine());
            Email = Convert.ToString(sr.ReadLine());

            

            Console.WriteLine("\nEnter The name of the Contact to Search for");
            string SearchName = Console.ReadLine();
            if ((NameContact == SearchName))
            {
                found = true;
                SearchName = NameContact;
                Console.Write("{0}", NameContact);
                NameContact = sr.ReadLine();
                Console.Write("{0}", Contactphone);
                Contactphone = sr.Read();
                Console.Write("{0}", Address);
                Console.Write("{0}", Email);
                Address = sr.ReadLine();
                Email = sr.ReadLine();
            }
            fs.Flush();
            sr.Close();
            fs.Close();

            Console.WriteLine("{0} ", SearchName + " Was not found");

        }
        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()
        {
            FileStream fs = new FileStream("@Meeting.txt", FileMode.Append, FileAccess.Write);
            StreamWriter writer = new StreamWriter(fs);




            Console.WriteLine("\nHow many meeting(s) do want to Add");
            int Add = Convert.ToInt32(Console.ReadLine());


            string Meeting_Subject;
            string Meeting_Address;
            double Meeting_DATE;
            for (int Index = 0; Index < Add; Index++)
            {
                Console.WriteLine("\nEnter the Subject of Meeting {0}", Index + 1);
                Meeting_Subject = Console.ReadLine();
                Console.WriteLine();
                Console.WriteLine("\nEnter the Meeting Address ");
                Meeting_Address = Console.ReadLine();
                Console.WriteLine();
                Console.WriteLine("\nEnter the Date of the Meeting");
                Meeting_DATE = Convert.ToDouble(Console.ReadLine());
                //Leave A BlankLine
                Console.WriteLine();

                //Writes MeetingSubject To File
                writer.Write(Meeting_Subject);

                //Write Meeting Address To file
                writer.Write(Meeting_Address);

                //Write Meeting Date to file
                writer.Write(Meeting_DATE);
                Console.WriteLine();

                Console.WriteLine("\nYour Meeting Has been Added");
            }
            writer.Flush();
            writer.Close();
            fs.Close();
        }
        public void DELETE_Meeting()
        {
            FileStream fs = new FileStream("@Meeting.txt", FileMode.Open, FileAccess.Read, FileShare.Delete);
            
            StreamReader sr = new StreamReader(fs);

            sr.BaseStream.Seek(0, SeekOrigin.Begin);

            string Receive = sr.ReadLine();


            Boolean found = false;

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

            string SearchValue = Console.ReadLine();

            SearchValue = Receive;

            while ((Receive != null) && (found == false))
            {
                if (Receive == SearchValue)
                {
                    found = true;
                    SearchValue = Receive;
                    File.Delete(SearchValue);
                }
                sr.Close();
                fs.Close();
            }

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

        public void Edit_Meeting()
        {
            FileStream fs = new FileStream("@Meeting.txt", FileMode.Append, FileAccess.Write);
            
            StreamWriter sr = new StreamWriter(fs);



            Console.WriteLine("\nHow Many Meeting do which to modify");
            int Number = Convert.ToInt32(Console.ReadLine());

            for (int Index = 0; Index < Number; Index++)
            {
                Console.WriteLine("\nEnter the New Subject for Meeting {0}", Index + 1);
                string New_Meeting_Subject = Console.ReadLine();

                Console.WriteLine("\nEnter The New Date For Meeting");
                double New_Meeting_DATE = Convert.ToDouble(Console.ReadLine());

                Console.WriteLine("\nEnter the New Address for Contact");
                double New_Meeting_Address = Convert.ToDouble(Console.ReadLine());
                
                Console.WriteLine();

                sr.WriteLine(New_Meeting_Subject);
                sr.WriteLine(New_Meeting_DATE);
                sr.WriteLine(New_Meeting_Address);

            }
            sr.Flush();
            sr.Close();
            fs.Close();
        }
        public void Search_Meeting()
        {
            FileStream fs = new FileStream("@Meeting.txt", FileMode.Open, FileAccess.Read);
            StreamReader sr = new StreamReader(fs);

            sr.BaseStream.Seek(0, SeekOrigin.Begin);

            string Meeting_Subject;
            string Meeting_Address;
            double Meeting_DATE;

            Meeting_Subject = sr.ReadLine();
            Meeting_DATE = sr.Read();
            Meeting_Address = sr.ReadLine();

            

            Console.WriteLine("\nEnter the Name of the Meeting to Search for");
            string SearchMeeting = Console.ReadLine();

            while (Meeting_Subject != null)
            {
                if (Meeting_Subject == SearchMeeting)
                {
                    
                    SearchMeeting = Meeting_Subject;
                    Console.WriteLine(Meeting_Subject);
                    Meeting_Subject = sr.ReadLine();
                    Console.WriteLine(Meeting_Address);
                    Meeting_Address = sr.ReadLine();
                    Console.WriteLine(Meeting_DATE);
                    Meeting_DATE = sr.Read();

                    fs.Flush();
                    sr.Close();
                    fs.Close();
                }
                else
                {
                    Console.WriteLine("{0} ", SearchMeeting + "Was not found");
                }

            }
        }
        public static void Main(string[] args)
        {
            Assistant ps = new Assistant();
            string keepgoing = "y";
            do
            {
                ps.ShowIntro();
                Console.WriteLine("\nWill You Like To Perform Another Operation.");
                Console.WriteLine("\nEnter y to go back to the Main Menu or any other key to cancel");
                keepgoing = Console.ReadLine();


            } while (keepgoing.Equals("y"));
 
        }

    }
}






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>