private void buttonAddAccount_Click(object sender, EventArgs e) { if ((textBoxAccountName.Text == string.Empty) || (textBoxAccountName.Text == "Entrez le nom de compte...")) MessageBox.Show("Merci d'entrer un nom de compte.", "BS Error"); else if ((textBoxPassword.Text == string.Empty) || (textBoxPassword.Text == "Entrez le mot de passe...")) MessageBox.Show("Merci d'entrer un mot de passe.", "BS Error"); else { foreach (ListViewItem bot in listViewAccounts.Items) { if (bot.Text == textBoxAccountName.Text) { MessageBox.Show("Ce compte a déjà été ajouté.", "BS Error"); textBoxAccountName.Text = string.Empty; textBoxPassword.Text = string.Empty; return; } } string[] row1 = { textBoxAccountName.Text, textBoxPassword.Text }; ListViewItem li = new ListViewItem(row1); listViewAccounts.Items.Add(li); AccountsFileInteractions accountsFileInteractions = new AccountsFileInteractions(); List<Bot> listaccount = new List<Bot>(); foreach (ListViewItem item in listViewAccounts.Items) { listaccount.Add(new Bot(new Account(item.SubItems[0].Text, item.SubItems[1].Text))); } accountsFileInteractions.SaveAccountsInfos(listaccount); textBoxAccountName.Text = string.Empty; textBoxPassword.Text = string.Empty; listViewAccounts.Items[0].Focused = true; listViewAccounts.Items[0].Selected = true; } }
private void DelBt_Click(object sender, EventArgs e) { for (int i = 0; i < listViewAccounts.SelectedItems.Count; i++) //parcours des comptes sélectionnés { ListViewItem listViewItem2 = listViewAccounts.SelectedItems[i]; // Sauvegarde des comptes AccountsFileInteractions accountsFileInteractions = new AccountsFileInteractions(); List <Bot> listaccount = new List <Bot>(); foreach (ListViewItem item in listViewAccounts.Items) { listaccount.Add(new Bot(new Account(item.SubItems[0].Text, item.SubItems[1].Text))); } accountsFileInteractions.SaveAccountsInfos(listaccount); // suppression de l'interface listViewAccounts.Items.Remove(listViewItem2); } }