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.Data.SqlClient;
- namespace Vezba_14_2018
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
- {
- using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.SportistiConnectionString))
- {
- connection.Open();
- string commandText = "SELECT * FROM Sportista";
- using (SqlCommand command = new SqlCommand(commandText, connection))
- {
- using (SqlDataReader reader = command.ExecuteReader())
- {
- DataTable dataTable = new DataTable();
- dataTable.Load(reader);
- dataGridView1.DataSource = dataTable;
- }
- }
- }
- }
- private void dodajSportistuToolStripMenuItem_Click(object sender, EventArgs e)
- {
- SportistaForm sForm = new SportistaForm();
- sForm.ShowDialog();
- }
- private void obrisiSportistuToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (dataGridView1.CurrentCell.RowIndex >= 0)
- {
- using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.SportistiConnectionString))
- {
- connection.Open();
- string commandText = "DELETE FROM Sportista where Id = {0}";
- using (SqlCommand command = new SqlCommand(commandText, connection))
- {
- using (SqlDataReader reader = command.ExecuteReader())
- {
- DataTable dataTable = new DataTable();
- dataTable.Load(reader);
- dataGridView1.DataSource = dataTable;
- }
- }
- }
- }
- }
- }
- }
- 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.Data.SqlClient;
- namespace Vezba_14_2018
- {
- public partial class SportistaForm : Form
- {
- public SportistaForm()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.SportistiConnectionString))
- {
- connection.Open();
- string commandText = string.Format("INSERT INTO Sportista(Ime, Visina, Tezina, KlubId, DatumRodjenja) VALUES (N'{0}', {1}, {2}, {3})", textBox1.Text, numericUpDown1.Value, numericUpDown2.Value, (int)comboBox1.SelectedValue);
- using (SqlCommand command = new SqlCommand(commandText, connection))
- {
- if (command.ExecuteNonQuery() > 0)
- {
- MessageBox.Show("Uspesno ste dodali sportistu!");
- }
- else
- {
- MessageBox.Show("Greska prilikom dodavanja sportiste", "Greska", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- Close();
- }
- private void SportistaForm_Load(object sender, EventArgs e)
- {
- using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.SportistiConnectionString))
- {
- connection.Open();
- string commandText = "SELECT Id, Naziv FROM Klub";
- using (SqlCommand command = new SqlCommand(commandText, connection))
- {
- using (SqlDataReader reader = command.ExecuteReader())
- {
- DataTable dataTable = new DataTable();
- dataTable.Load(reader);
- comboBox1.DataSource = dataTable;
- comboBox1.DisplayMember = "Naziv";
- comboBox1.ValueMember = "Id";
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement