示例#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);
            }
        }
示例#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
            }
        }