Example #1
0
        static Dictionary <String, AddressBookPrg> addressBookDictionary = new Dictionary <string, AddressBookPrg>(); //create Dictionary
        static void Main(string[] args)                                                                               //Main method
        {
            bool        loop1 = true;                                                                                 //Boolean Value TRue Or False
            EditContact edit  = new EditContact();                                                                    //Create object Edit class

            while (loop1)                                                                                             //While loop to adding number of Address book system
            {
                Console.WriteLine("**** Welcome To Address Book System ****");
                Console.WriteLine("\n1.Add Address Book System\n2.Show Address Books System Names\n3.Search Person in City or State\n4.Exit "); //Print menu

                Console.Write("Enter Your Choice:- ");                                                                                          //Take input
                int choice1 = Convert.ToInt32(Console.ReadLine());                                                                              //take input user and store choice1 veriable

                while (choice1 > 4)                                                                                                             //Check input is greater or not
                {
                    Console.WriteLine("Plz Enter Valid Option");                                                                                //print
                    Console.Write("Enter Your Choice:-");                                                                                       //take input
                    choice1 = Convert.ToInt32(Console.ReadLine());                                                                              //store choice1
                }


                AddressBookPrg addressBook     = new AddressBookPrg(); //Create Object AddressBookMain
                string         addressBookName = null;                 // addressBookName empty or null
                switch (choice1)                                       //switch Case
                {
                case 1:

                    Console.Write("Enter Address Book System Name:- ");                               //take input user side

                    addressBookName = Console.ReadLine();                                             //Store name addressBookName

                    bool isKeyAvailable = false;                                                      // true if a key press is available; otherwise, false.

                    foreach (KeyValuePair <string, AddressBookPrg> keyValue in addressBookDictionary) //Iterating dictionary  displayed
                    {
                        if (keyValue.Key.Equals(addressBookName))                                     //Check Addressbook name exixt or not
                        {
                            isKeyAvailable = true;                                                    //value is present
                        }
                    }
                    if (isKeyAvailable)     //value is present print message
                    {
                        Console.WriteLine($"Address Book System {addressBookName} is Already Exist\n Please Enter New Address Book Name:-");
                        addressBookName = Console.ReadLine();    //Take input user
                    }
                    bool loop2 = true;
                    Console.WriteLine("**** Welcome To Address Book System ****");
                    int i = 0;
                    // Edit edit = new Edit(); //Create object Edit class
                    while (loop2)
                    {
                        Console.WriteLine("\n1. Add New Person      ");
                        Console.WriteLine("2. Display Records     ");
                        Console.WriteLine("3. Edit Records        ");
                        Console.WriteLine("4. Delete Records      ");
                        Console.WriteLine("5. Exit		        \n");
                        Console.Write("Enter Your Choice:- ");
                        int choice = Convert.ToInt32(Console.ReadLine());
                        switch (choice)
                        {
                        case 1:
                            edit.AddRecord();         //call AddRecord Method
                            break;

                        case 2:
                            edit.DisplayRecord();          //call DisplayRecord Method
                            break;

                        case 3:
                            Console.Write("Enter First Name To Edit Records:- ");
                            String firstName = Console.ReadLine();
                            edit.EditRecord(firstName);         //call Edit record method
                            break;

                        case 4:
                            Console.Write("Enter First Name To Delete Records:- ");
                            String Name = Console.ReadLine();
                            edit.DeleteRecord(Name);         //call Delete record method
                            break;

                        case 5:
                            loop2 = false;
                            break;

                        default:
                            Console.WriteLine("Enter Valid Option");
                            break;
                        }
                    }
                    addressBookDictionary.Add(addressBookName, addressBook);    //Addrees book add Name
                    break;

                case 2:
                    Console.WriteLine(" Available Address Books System ");

                    foreach (KeyValuePair <String, AddressBookPrg> keyValue in addressBookDictionary) //Iterating
                    {
                        Console.WriteLine("Address Book System Name:-  " + keyValue.Key);             //print
                    }
                    break;

                case 3:
                    edit.SearchRecordCityOrState();     //call Delete record method
                    break;

                default:
                    loop1 = false;
                    break;
                }
            }
        }
Example #2
0
        private void editContact_Click(object sender, EventArgs e)
        {
            try
            {
                if (ContactsTable.GetCellCount(DataGridViewElementStates.Selected) > 1 == false &&
                    !string.IsNullOrWhiteSpace(ContactsTable.CurrentCell.Value.ToString()) &&
                    ContactsTable.SelectedCells.Count != 0)
                {
                    actualValue = ContactsTable.CurrentCell.Value.ToString();

                    checkStatus = false;

                    for (int i = 0; i < ContactsTable.GetCellCount(DataGridViewElementStates.Selected); i++)
                    {
                        EditRowIndex = ContactsTable.SelectedCells[i].RowIndex;

                        EditColumnIndex = ContactsTable.SelectedCells[i].ColumnIndex;
                    }

                    List <string> wholeValues = new List <string>();

                    List <string> oldValues = new List <string>();

                    wholeValues.Clear();

                    oldValues.Clear();

                    string readyRow = null;

                    for (int i = 0; i < ContactsTable.GetCellCount(DataGridViewElementStates.Selected); i++)
                    {
                        int rowIndex = ContactsTable.SelectedCells[i].RowIndex;

                        for (int j = 0; j < 8; j++)
                        {
                            readyRow += ContactsTable.Rows[rowIndex].Cells[j].Value.ToString() + "|";
                        }

                        wholeValues.Add(readyRow);

                        readyRow = null;
                    }

                    EditContact Window = new EditContact();

                    DialogResult Check = Window.ShowDialog();

                    try
                    {
                        if (checkStatus == false)
                        {
                            ContactsTable.CurrentCell.Value = EditContact.readyValue;

                            #region Pobieranie aktualnej wersji tabeli

                            int contactCount = ContactsTable.Rows.Count;

                            string ReadyContact = null;

                            for (int i = 0; i < contactCount - 1; i++)
                            {
                                ReadyContact = null;

                                for (int j = 0; j < 8; j++)
                                {
                                    ReadyContact += ContactsTable.Rows[i].Cells[j].Value.ToString() + "|";
                                }

                                oldValues.Add(ReadyContact);
                            }

                            #endregion

                            for (int i = 0; i < oldValues.Count; i++)
                            {
                                for (int j = 0; j < copyOfContacts.Count; j++)
                                {
                                    if (copyOfContacts[j].Trim() == wholeValues[0].Trim())
                                    {
                                        for (int k = 0; k < oldValues.Count; k++)
                                        {
                                            copyOfContacts[j] = oldValues[EditRowIndex];
                                        }
                                    }
                                }
                            }
                        }
                    }

                    catch
                    {
                    }
                }

                else
                {
                    Navigate.ToolTipTitle = "Informacja";

                    Navigate.ToolTipIcon = ToolTipIcon.Warning;

                    Navigate.Show("Zaznacz jedną komórkę w tabeli!", backgroundTip, 5, backgroundTip.Height - 5, 2500);
                }
            }

            catch
            {
                //błąd edytowania komórek
            }
        }