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.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Vezba_10_2017
- {
- public partial class Form1 : Form
- {
- private BindingList<Kontakt> kontakti;
- public Form1()
- {
- InitializeComponent();
- kontakti = new BindingList<Kontakt>();
- Kontakt k = new Kontakt();
- k.Prezime = "Stevanovic";
- k.Ime = "Milan";
- k.Adresa = "Mistake Island, USA";
- k.BrojTelefona = "021345678";
- kontakti.Add(k);
- dataGridView1.DataSource = kontakti;
- }
- private void toolStripButton1_Click(object sender, EventArgs e)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "Vezba 10 datoteke (*.v10)|*.v10";
- if(ofd.ShowDialog() == DialogResult.OK)
- {
- kontakti.Clear();
- using (FileStream stream = new FileStream(ofd.FileName, FileMode.Open))
- {
- using (BinaryReader reader = new BinaryReader(stream))
- {
- while (reader.BaseStream.Position < reader.BaseStream.Length)
- {
- Kontakt c = new Kontakt();
- c.Prezime = reader.ReadString();
- c.Ime = reader.ReadString();
- c.Adresa = reader.ReadString();
- c.BrojTelefona = reader.ReadString();
- kontakti.Add(c);
- }
- }
- }
- }
- }
- private void toolStripButton2_Click(object sender, EventArgs e)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Filter = "Vezba 10 datoteke (*.v10)|*.v10";
- if(sfd.ShowDialog() == DialogResult.OK)
- {
- using (FileStream stream = new FileStream(sfd.FileName, FileMode.Create))
- {
- using (BinaryWriter writer = new BinaryWriter(stream))
- {
- foreach(Kontakt c in kontakti)
- {
- writer.Write(c.Prezime);
- writer.Write(c.Ime);
- writer.Write(c.Adresa);
- writer.Write(c.BrojTelefona);
- }
- }
- }
- }
- }
- private void izlazIzProgramaToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Close();
- }
- private void dodajKontaktToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Form2 addForm = new Form2();
- if(addForm.ShowDialog() == DialogResult.OK)
- {
- Kontakt k = addForm.Kontakt;
- kontakti.Add(k);
- }
- }
- private void izmeniKontaktToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (dataGridView1.CurrentRow.DataBoundItem == null) return;
- Kontakt k = (Kontakt)dataGridView1.CurrentRow.DataBoundItem;
- Form2 addForm = new Form2();
- addForm.Kontakt = k;
- addForm.ShowDialog();
- if(addForm.DialogResult == DialogResult.OK)
- {
- k.Ime = addForm.Kontakt.Ime;
- k.Prezime = addForm.Kontakt.Prezime;
- k.Adresa = addForm.Kontakt.Adresa;
- k.BrojTelefona = addForm.Kontakt.BrojTelefona;
- dataGridView1.Refresh();
- }
- }
- private void obrisiKontaktToolStripMenuItem_Click(object sender, EventArgs e)
- {
- foreach (DataGridViewRow item in this.dataGridView1.SelectedRows)
- {
- dataGridView1.Rows.RemoveAt(item.Index);
- }
- dataGridView1.Refresh();
- }
- private void obrisiSveKontaktToolStripMenuItem_Click(object sender, EventArgs e)
- {
- kontakti.Clear();
- dataGridView1.Refresh();
- }
- private void oAplikacijiToolStripMenuItem_Click(object sender, EventArgs e)
- {
- MessageBox.Show("Jednostavan telefonski imenik");
- }
- }
- }
- 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;
- namespace Vezba_10_2017
- {
- public partial class Form2 : Form
- {
- public Kontakt Kontakt { get; set; }
- public Form2()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Kontakt = new Kontakt();
- Kontakt.Ime = textBox1.Text;
- Kontakt.Prezime = textBox2.Text;
- Kontakt.Adresa = textBox3.Text;
- Kontakt.BrojTelefona = textBox4.Text;
- DialogResult = DialogResult.OK;
- Close();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- DialogResult = DialogResult.Cancel;
- Close();
- }
- private void Form2_Load(object sender, EventArgs e)
- {
- textBox1.Text = Kontakt.Ime;
- textBox2.Text = Kontakt.Prezime;
- textBox3.Text = Kontakt.Adresa;
- textBox4.Text = Kontakt.BrojTelefona;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Vezba_10_2017
- {
- public class Kontakt
- {
- public string Prezime { get; set; }
- public string Ime { get; set; }
- public string Adresa { get; set; }
- public string BrojTelefona { get; set; }
- public Kontakt()
- {
- Prezime = string.Empty;
- Ime = string.Empty;
- Adresa = string.Empty;
- BrojTelefona = string.Empty;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement