Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace BooksList
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void label1_Click(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- ListViewItem lvi = new ListViewItem(textBox1.Text);
- lvi.SubItems.Add(textBox2.Text);
- lvi.SubItems.Add(textBox3.Text);
- listView1.Items.Add(lvi);
- FileStream file = File.Open("C:\\Users\\Stoyan\\Desktop\\data.txt", FileMode.Append);
- StreamWriter strWriter = new StreamWriter(file);
- strWriter.WriteLine(textBox1.Text + "," + textBox2.Text + "," + textBox3.Text);
- strWriter.Close();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- string title, author, isbn;
- string[] result;
- string[] stringSeparators = new string[] { "," };
- FileStream inFile = null;
- // enter C:\Users\Stoyan\Desktop\data.txt in the field
- if (textBox4.Text == "") {
- MessageBox.Show("The filename can not be empty");
- return;
- }
- try
- {
- inFile = new FileStream(textBox4.Text, FileMode.Open, FileAccess.Read); //"C:\\Users\\Stoyan\\Desktop\\" +
- }
- catch (FileNotFoundException) {
- MessageBox.Show("File Not Found!");
- return;
- }
- StreamReader reader = new StreamReader(inFile);
- string recordIn = reader.ReadLine();
- result = recordIn.Split(stringSeparators, StringSplitOptions.None);
- while (recordIn != null)
- {
- title = result[0];
- author = result[1];
- isbn = result[2];
- ListViewItem lvi = new ListViewItem(title);
- lvi.SubItems.Add(author);
- lvi.SubItems.Add(isbn);
- listView1.Items.Add(lvi);
- recordIn = reader.ReadLine();
- if (recordIn != null)
- {
- result = recordIn.Split(stringSeparators, StringSplitOptions.None);
- }
- }
- reader.Close();
- inFile.Close();
- }
- private void textBox1_Validating(object sender, CancelEventArgs e)
- {
- if (textBox1.Text == "")
- {
- errorProvider1.SetError(textBox1, "Please enter the Title");
- }
- else
- {
- errorProvider1.SetError(textBox1, "");
- }
- }
- private void textBox4_Validating(object sender, CancelEventArgs e)
- {
- if (textBox4.Text == "")
- {
- errorProvider1.SetError(textBox4, "Please enter the Name of the File");
- }
- else
- {
- errorProvider1.SetError(textBox4, "");
- }
- }
- private void textBox2_Validating(object sender, CancelEventArgs e)
- {
- if (textBox2.Text == "")
- {
- errorProvider1.SetError(textBox2, "Please enter the Author");
- }
- else
- {
- errorProvider1.SetError(textBox2, "");
- }
- }
- private void textBox3_Validating(object sender, CancelEventArgs e)
- {
- if (textBox3.Text == "")
- {
- errorProvider1.SetError(textBox3, "Please enter the ISBN");
- }
- else
- {
- errorProvider1.SetError(textBox3, "");
- }
- }
- private void listView1_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement