private void imprumutare_Click(object sender, EventArgs e) { this.Hide(); Imprumutare f = new Imprumutare(); f.ShowDialog(); this.Close(); }
private void imprumutare_Click(object sender, EventArgs e) { if (listBox1.SelectedIndex == -1) { MessageBox.Show("Nu ati ales nici o carte!", "Info"); } else { string isbnL = listBox1.SelectedItem.ToString(); string isbnLista = ""; for (int i = 0; i < isbnL.Length; i++) { if (isbnL[i] == ' ' && isbnL[i + 1] == '|') { break; } else { isbnLista += isbnL[i]; } } StreamReader rd = new StreamReader("CartiImprumutate.txt"); string info = ""; string isbn = ""; int ok = 0; while ((info = rd.ReadLine()) != null) { for (int i = 0; i < info.Length; i++) { if (info[i] != '|') { isbn += info[i]; } else { break; } } if (isbn == isbnLista) { ok = 1; break; } else { isbn = ""; } } //isbnL contine toata schema rd.Close(); if (ok == 0) { DialogResult dg = MessageBox.Show("Cartea a fost adaugata la cartile ce vor fi imprumutate\nDoriti sa continuati la meniul Imprumutare Carte?", "Info", MessageBoxButtons.YesNo, MessageBoxIcon.Information); StreamWriter wr = new StreamWriter("CartiImprumutate.txt", true); string[] table = isbnL.Split(new[] { " | " }, StringSplitOptions.None); wr.WriteLine(table[0] + "|" + table[1] + "|" + table[2] + "|" + table[3] + "|"); wr.Close(); if (dg == DialogResult.Yes) { this.Hide(); Imprumutare f = new Imprumutare(); f.ShowDialog(); this.Close(); } } else { MessageBox.Show("Cartea este adaugata deja la meniul Imprumutare Carte", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }