Ejemplo n.º 1
0
        private void deleteContact_Click(object sender, EventArgs e)
        {
            if (ContactsTable.SelectedCells.Count > 0)
            {
                if (!string.IsNullOrWhiteSpace(ContactsTable.CurrentCell.Value.ToString()))
                {
                    try
                    {
                        #region Pobieranie zaznaczonych komórek (jako cała wartość tabeli) + tworzenie zmiennych zaznaczonych

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

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

                        #endregion

                        #region Pobieranie całej aktualnej tabeli (komórki widocznej w czasie edycji)

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

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

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

                        ContactsTable.Rows.Clear();

                        for (int i = 0; i < oldValues.Count; i++)
                        {
                            string[] RowValue = oldValues[i].Split('|');

                            ContactsTable.Rows.Add($"{RowValue[0]}", $"{RowValue[1]}", $"{RowValue[2]}", $"{RowValue[3]}", $"{RowValue[4]}", $"{RowValue[5]}", $"{RowValue[6]}", $"{RowValue[7]}");
                        }

                        try
                        {
                            ContactsTable.Rows.Add("", "", "", "", "", "", "", "");

                            int tableRow = ContactsTable.Rows.Count - 1;

                            ContactsTable.Rows[tableRow].DefaultCellStyle.BackColor = Color.FromArgb(224, 224, 224);

                            ContactsTable.ClearSelection();
                        }

                        catch
                        {
                            //błąd rysowania komórki
                        }

                        #endregion

                        #region Usuwanie wartości głównej kopi danych [copyOfContacts]

                        for (int i = 0; i < wholeValues.Count; i++)
                        {
                            for (int j = 0; j < copyOfContacts.Count; j++)
                            {
                                if (copyOfContacts[j].Trim() == wholeValues[i].Trim())
                                {
                                    copyOfContacts.RemoveAt(j);
                                }
                            }
                        }
                        #endregion
                    }

                    catch
                    {
                        //Błąd usuwania danych
                    }
                }

                else
                {
                    Navigate.ToolTipTitle = "Informacja";

                    Navigate.ToolTipIcon = ToolTipIcon.Warning;

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

            else
            {
                Navigate.ToolTipTitle = "Informacja";

                Navigate.ToolTipIcon = ToolTipIcon.Warning;

                Navigate.Show("Zaznacz komórki w tabeli!", backgroundTip, 5, backgroundTip.Height - 5, 2500);
            }
        }
Ejemplo n.º 2
0
        private void addContact_Click(object sender, EventArgs e)
        {
            try
            {
                checkPosible = false;

                AddContact Window = new AddContact();

                DialogResult Check = Window.ShowDialog();

                if (checkPosible == false)
                {
                    List <string> readyValues = AddContact.newContact;

                    InputSearcher.Clear();

                    #region Pobieranie starwej wersji tabeli

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

                    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

                    ContactsTable.Rows.Clear();

                    #region Dodawanie nowych komórek do tabeli

                    for (int i = 0; i < oldValues.Count; i++)
                    {
                        string[] DivideValue = oldValues[i].Split('|');

                        ContactsTable.Rows.Add($"{DivideValue[0]}", $"{DivideValue[1]}", $"{DivideValue[2]}", $"{DivideValue[3]}", $"{DivideValue[4]}", $"{DivideValue[5]}", $"{DivideValue[6]}", $"{DivideValue[7]}");
                    }

                    ContactsTable.Rows.Add($"{readyValues[0]}", $"{readyValues[1]}", $"{readyValues[2]}", $"{readyValues[3]}", $"{readyValues[4]}", $"{readyValues[5]}", $"{readyValues[6]}", $"{readyValues[7]}");

                    ContactsTable.Rows.Add("", "", "", "", "", "", "", "");

                    int tableRow = ContactsTable.Rows.Count - 1;

                    ContactsTable.Rows[tableRow].DefaultCellStyle.BackColor = Color.FromArgb(224, 224, 224);

                    ContactsTable.ClearSelection();

                    #endregion

                    #region Nadpisywanie kopii komórek

                    try
                    {
                        copyOfContacts.Clear();

                        int contactCountCopy = ContactsTable.Rows.Count;

                        string ReadyContactCopy = null;

                        for (int i = 0; i < contactCountCopy - 1; i++)
                        {
                            ReadyContactCopy = null;

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

                            copyOfContacts.Add(ReadyContactCopy);
                        }
                    }

                    catch
                    {
                        //błąd tworzenia kopii kontaktów
                    }

                    #endregion
                }
            }

            catch
            {
                //błąd
            }
        }
Ejemplo n.º 3
0
        private void InputSearcher_TextChanged(object sender, EventArgs e)
        {
            try
            {
                string Word = InputSearcher.Text.Trim();

                ContactsTable.Rows.Clear();

                if (!string.IsNullOrWhiteSpace(Word))
                {
                    foreach (string Value in copyOfContacts)
                    {
                        if (Value.ToLower().Contains(Word.ToLower()))
                        {
                            string[] RowValue = Value.Split('|');

                            ContactsTable.Rows.Add($"{RowValue[0]}", $"{RowValue[1]}", $"{RowValue[2]}", $"{RowValue[3]}", $"{RowValue[4]}", $"{RowValue[5]}", $"{RowValue[6]}", $"{RowValue[7]}");
                        }
                    }

                    try
                    {
                        ContactsTable.Rows.Add("", "", "", "", "", "", "", "");

                        int tableRow = ContactsTable.Rows.Count - 1;

                        ContactsTable.Rows[tableRow].DefaultCellStyle.BackColor = Color.FromArgb(224, 224, 224);

                        ContactsTable.ClearSelection();
                    }

                    catch
                    {
                        //błąd rysowania komórki
                    }
                }

                else
                {
                    foreach (string Value in copyOfContacts)
                    {
                        string[] RowValue = Value.Split('|');

                        ContactsTable.Rows.Add($"{RowValue[0]}", $"{RowValue[1]}", $"{RowValue[2]}", $"{RowValue[3]}", $"{RowValue[4]}", $"{RowValue[5]}", $"{RowValue[6]}", $"{RowValue[7]}");
                    }

                    try
                    {
                        ContactsTable.Rows.Add("", "", "", "", "", "", "", "");

                        int tableRow = ContactsTable.Rows.Count - 1;

                        ContactsTable.Rows[tableRow].DefaultCellStyle.BackColor = Color.FromArgb(224, 224, 224);

                        ContactsTable.ClearSelection();
                    }

                    catch
                    {
                        //błąd rysowania komórki
                    }
                }
            }

            catch
            {
                //błąd wyszukiwania podanej frazy
            }
        }
Ejemplo n.º 4
0
        private void readDataFromFile()
        {
            try
            {
                using (StreamReader loadedValue = new StreamReader($@"{DirectoryApp}\contact.txt"))
                {
                    List <string> AllValues = new List <string>();

                    while (true)
                    {
                        if (loadedValue.EndOfStream)
                        {
                            break;
                        }

                        string Line = loadedValue.ReadLine();

                        AllValues.Add(Line.Trim());
                    }

                    AllValues = AllValues.Where(x => !string.IsNullOrWhiteSpace(x)).ToList();

                    this.Invoke((MethodInvoker) delegate
                    {
                        for (int i = 0; i < AllValues.Count; i++)
                        {
                            string[] DivideValue = AllValues[i].Split('|');

                            ContactsTable.Rows.Add($"{DivideValue[0]}", $"{DivideValue[1]}", $"{DivideValue[2]}", $"{DivideValue[3]}", $"{DivideValue[4]}", $"{DivideValue[5]}", $"{DivideValue[6]}", $"{DivideValue[7]}");
                        }

                        ContactsTable.Rows.Add("", "", "", "", "", "", "", "");

                        int tableRow = ContactsTable.Rows.Count - 1;

                        ContactsTable.Rows[tableRow].DefaultCellStyle.BackColor = Color.FromArgb(224, 224, 224);

                        ContactsTable.ClearSelection();
                    });

                    try
                    {
                        copyOfContacts.Clear();

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

                            copyOfContacts.Add(ReadyContact);
                        }
                    }

                    catch
                    {
                        //błąd tworzenia kopii kontaktów
                    }
                }
            }

            catch
            {
                //błąd odczytu pliku
            }
        }