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.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace LV6___Zadatak_2
- {
- public partial class form_imenik : Form
- {
- public form_imenik()
- {
- InitializeComponent();
- }
- class Kontakt
- {
- #region data_members
- private string ime;
- public string prezime;
- private string broj_telefona;
- #endregion
- #region public_methods
- public Kontakt()
- {
- ime = ""; prezime = ""; broj_telefona = "";
- }
- public Kontakt(string i, string p, string b)
- {
- ime = i; prezime = p; broj_telefona = b;
- }
- public override string ToString()
- {
- return ime + "\t" + prezime + "\t" + broj_telefona;
- }
- #endregion
- }
- List<Kontakt> listKontakt = new List<Kontakt>();
- string path = "C:\\Users\\Student\\Documents\\Visual Studio 2015\\Projects\\LV6 - Zadatak 2\\LV6 - Zadatak 2\\imenik.txt";
- private void form_imenik_Load(object sender, EventArgs e)
- {
- using (System.IO.StreamReader reader = new System.IO.StreamReader(@path))
- {
- string line;
- while ((line = reader.ReadLine()) != null)
- {
- string[] parts = line.Split('\t');
- Kontakt K = new Kontakt(parts[0], parts[1], parts[2]);
- listKontakt.Add(K);
- }
- listBox_popis.DataSource = null;
- listBox_popis.DataSource = listKontakt;
- }
- }
- private void button_dodaj_Click(object sender, EventArgs e)
- {
- bool error = false;
- if (textBox_ime.Text == "" || textBox_prezime.Text == "" || textBox_broj.Text == "")
- {
- error = true;
- MessageBox.Show("Neko od polja ostalo je prazno.", "Pogreška!");
- }
- else if (!Regex.IsMatch(textBox_broj.Text, @"^[0-9]+$"))
- {
- error = true;
- MessageBox.Show("Broj telefona je neispravan!", "Pogreška!");
- }
- else
- {
- error = false;
- }
- if (!error)
- {
- Kontakt K = new Kontakt(textBox_ime.Text, textBox_prezime.Text, textBox_broj.Text);
- listKontakt.Add(K);
- listBox_popis.DataSource = null;
- listBox_popis.DataSource = listKontakt;
- textBox_ime.Text = String.Empty;
- textBox_prezime.Text = String.Empty;
- textBox_broj.Text = String.Empty;
- }
- }
- private void button_izlaz_Click(object sender, EventArgs e)
- {
- using (System.IO.StreamWriter write = new System.IO.StreamWriter(@path))
- {
- foreach (Kontakt K in listKontakt)
- {
- {
- write.WriteLine(K.ToString());
- }
- }
- }
- Application.Exit();
- }
- private void button_pretraga_Click(object sender, EventArgs e)
- {
- bool state = false;
- if (textBox_pretraga.Text == "")
- {
- MessageBox.Show("Niste unjeli prezime!", "Pogreška!");
- }
- else
- {
- foreach (Kontakt K in listKontakt)
- {
- if (K.prezime.Contains(textBox_pretraga.Text))
- {
- state = true;
- break;
- }
- else
- {
- state = false;
- }
- }
- if (state)
- {
- MessageBox.Show("Kontakt postoji!", "Pretraga!");
- }
- else
- {
- MessageBox.Show("Kontakt ne postoji!", "Pretraga!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement