private void addToolStripMenuItem_Click(object sender, EventArgs e) { if (user.Login == "Admin") { client = new User(); AddClient ad = new AddClient(); if (ad.ShowDialog(this) == DialogResult.OK) { user = ad.user; client.Login = user.Login; client.Password = user.Password; client.CountBadWord = 0; client.Birthday = user.Birthday; client.Tag = ""; client.IPClient = ""; usersB.Add(client); AddToListViewClients(); MessageBox.Show("Client Addet!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { Cont = new Contact(); Cont.Login = ""; Cont.LoginAdd = user.Login; Cont.Name = ""; Cont.Tag = ""; Cont.Color = RandColor(); EditContact edit = new EditContact(); if (edit.ShowDialog(this) == DialogResult.OK) { contacts.Add(edit.contact); AddToListViewContacts(); MessageBox.Show("Contact Addet!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void editToolStripMenuItem_Click(object sender, EventArgs e) { if (user.Login == "Admin") { bool res = true; int k = 0; AddClient edit = new AddClient();; while (res) { client = new User(); ListViewItem item = listViewClients.SelectedItems[0]; client.Login = item.SubItems[0].Text; string name = client.Login; client.CountBadWord = Convert.ToInt32(item.SubItems[1].Text); client.Birthday = item.SubItems[2].Text;; client.Password = usersB[usersB.FindIndex((x) => x.Login == client.Login)].Password; client.Tag = usersB[usersB.FindIndex((x) => x.Login == client.Login)].Tag; client.IPClient = usersB[usersB.FindIndex((x) => x.Login == client.Login)].IPClient; if (edit.ShowDialog(this) == DialogResult.OK) { client = edit.client; if (client.Login != name) { if (!usersB.Exists((x) => x.Login == client.Login)) { k = usersB.FindIndex((x) => x.Login == client.Login); res = false; } else { MessageBox.Show("There is already a user with this login, please try again!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); res = true; } } else { k = usersB.FindIndex((x) => x.Login == client.Login); res = false; } } else { res = false; } } usersB.RemoveAt(k); usersB.Add(client); AddToListViewClients(); MessageBox.Show("Client Edited!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { Cont = new Contact(); ListViewItem it = listViewContacts.SelectedItems[0]; Cont.Login = it.SubItems[0].Text; Cont.Name = it.SubItems[1].Text; Cont.Tag = it.SubItems[2].Text; Cont.Color = contacts[contacts.FindIndex((x) => x.Login == Cont.Login)].Color; Cont.LoginAdd = contacts[contacts.FindIndex((x) => x.Login == Cont.Login)].LoginAdd; EditContact ed = new EditContact(); if (ed.ShowDialog(this) == DialogResult.OK) { int k = contacts.FindIndex((x) => x.Login == Cont.Login); contacts.RemoveAt(k); contacts.Add(ed.contact); AddToListViewContacts(); MessageBox.Show("Contact Edited!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }