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;
- namespace Vezba_15_2018
- {
- public partial class Form1 : Form
- {
- private BindingSource bs;
- public Form1()
- {
- InitializeComponent();
- bs = new BindingSource();
- }
- private void UcitajSveGradove()
- {
- bs.DataSource = Database.ExecuteQuery("SELECT * FROM Grad ORDER BY GradID");
- }
- private void PrikaziGrad()
- {
- DataRowView grad = (DataRowView)bs.Current;
- if (grad != null)
- {
- sifraTextBox.Text = grad["GradID"].ToString();
- gradTextBox.Text = grad["Grad"].ToString();
- pozBrojTextBox.Text = grad["PozivniBroj"].ToString();
- postBrojTextBox.Text = grad["PostanskiBroj"].ToString();
- stanovniciTextBox.Text = grad["BrojStanovnika"].ToString();
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- UcitajSveGradove();
- bs.MoveFirst();
- PrikaziGrad();
- }
- private void sledeciButton_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(sifraTextBox.Text))
- bs.MoveLast();
- else
- {
- if (bs.Position == bs.Count - 1)
- bs.MoveFirst();
- else
- bs.MoveNext();
- }
- PrikaziGrad();
- }
- private void prethodniButton_Click(object sender, EventArgs e)
- {
- if(string.IsNullOrEmpty(sifraTextBox.Text))
- {
- bs.MoveFirst();
- }
- else
- {
- if (bs.Position == 0)
- bs.MoveLast();
- else
- bs.MovePrevious();
- }
- PrikaziGrad();
- }
- private void noviButton_Click(object sender, EventArgs e)
- {
- sifraTextBox.Clear();
- gradTextBox.Clear();
- pozBrojTextBox.Clear();
- postBrojTextBox.Clear();
- stanovniciTextBox.Clear();
- sifraTextBox.Focus();
- }
- private void izadjiButton_Click(object sender, EventArgs e)
- {
- Close();
- }
- private void upisiButton_Click(object sender, EventArgs e)
- {
- int sifra = int.Parse(sifraTextBox.Text);
- string grad = gradTextBox.Text;
- int pozivniBroj = int.Parse(pozBrojTextBox.Text);
- int postanskiBroj = int.Parse(postBrojTextBox.Text);
- int brojStanovnika = int.Parse(stanovniciTextBox.Text);
- string query = string.Format("INSERT INTO Grad (GradID, Grad, PozivniBroj, PostanskiBroj, BrojStanovnika) VALUES({0}, '{1}', {2}, {3}, {4});", sifra, grad, pozivniBroj, postanskiBroj, brojStanovnika);
- if (Database.ExecuteNonQuery(query) > 0)
- {
- MessageBox.Show("Uspesno ste dodali grad u bazu!");
- }
- else
- {
- MessageBox.Show("Greska!");
- }
- UcitajSveGradove();
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Data.OleDb;
- using System.Data;
- namespace Vezba_15_2018
- {
- class Database
- {
- public static DataTable ExecuteQuery(string query)
- {
- DataTable dataTable = new DataTable();
- using (OleDbConnection connection =
- new OleDbConnection(Properties.Settings.Default.B5FudbKluboviConnectionString))
- {
- connection.Open();
- using (OleDbCommand command = new OleDbCommand(query, connection))
- {
- using (OleDbDataReader reader = command.ExecuteReader())
- {
- dataTable.Load(reader);
- }
- }
- }
- return dataTable;
- }
- public static int ExecuteNonQuery(string query)
- {
- int rowsAffected = 0;
- using (OleDbConnection connection =
- new OleDbConnection(Properties.Settings.Default.B5FudbKluboviConnectionString))
- {
- connection.Open();
- using (OleDbCommand command = new OleDbCommand(query, connection))
- {
- rowsAffected = command.ExecuteNonQuery();
- }
- }
- return rowsAffected;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement