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 Baze_LV7_predlozak
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void btnSve_Click(object sender, EventArgs e)
- {
- // OVDJE SLIJEDI ZADATAK IZ LV7 a):
- /*Pritiskom na tipku Prikaži sve potrebno je spojiti se na bazu podataka student
- (server: 161.53.201.59; username: student; password: student) i u
- DataGridView dgvPodaci ispisati sve osobe iz tablice osobe poredane
- abecedno po prezimenu.*/
- SqlConnection conn = new SqlConnection("Data Source=192.168.26.14;Initial Catalog=student;User ID=student;Password=student");
- conn.Open();
- string statement = "SELECT * FROM osobe_R3758 ORDER BY prezime;";
- SqlDataAdapter dataAdapter = new SqlDataAdapter(statement, conn);
- DataTable dt = new DataTable();
- dataAdapter.Fill(dt);
- dgvPodaci.DataSource = dt;
- conn.Close();
- }
- private void btnSpremi_Click(object sender, EventArgs e)
- {
- // OVDJE SLIJEDI ZADATAK IZ LV7 b) (i BONUS zadatak):
- /*Pritiskom na tipku Spremi potrebno je spremiti novu osobu s podacima (OIB,
- ime, prezime, spol, datum rođenja) koje je korisnik upisao u sučelju aplikacije
- (txtOIB, txtIme, txtPrezime, rbM, rbZ, txtDatum).*/
- char spol;
- if (rbM.Checked)
- spol = 'M';
- else
- spol = 'F';
- txtDatum.Format = DateTimePickerFormat.Custom;
- txtDatum.CustomFormat = "yyyy-MM-dd";
- SqlConnection conn = new SqlConnection("Data Source=192.168.26.14;Initial Catalog=student;User ID=student;Password=student");
- conn.Open();
- string statement = "INSERT INTO osobe_R3758 (oib, ime, prezime, datum, spol) VALUES ('" + txtOIB.Text + "', '" + txtIme.Text + "', '" + txtPrezime.Text + "', '" + txtDatum.Text + "', '" + spol + "');";
- SqlCommand cmd = new SqlCommand(statement, conn);
- cmd.ExecuteNonQuery();
- conn.Close();
- }
- public void obrisiSve()
- {
- txtOIB.Text = "";
- txtIme.Text = "";
- txtPrezime.Text = "";
- txtDatum.Text = "";
- dgvPodaci.ClearSelection();
- txtOIB.ReadOnly = false;
- }
- private void btnObrisi_Click(object sender, EventArgs e)
- {
- obrisiSve();
- }
- private void dgvPodaci_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- //OVDJE JE DODATAK POTREBAN ZA BONUS ZADATAK
- txtOIB.Text = dgvPodaci.SelectedRows[0].Cells[0].Value.ToString();
- txtIme.Text = dgvPodaci.SelectedRows[0].Cells[1].Value.ToString();
- txtPrezime.Text = dgvPodaci.SelectedRows[0].Cells[2].Value.ToString();
- if (dgvPodaci.SelectedRows[0].Cells[3].Value.ToString() == "M") rbM.Checked = true;
- else rbZ.Checked = true;
- txtOIB.ReadOnly = true;
- txtDatum.Text = dgvPodaci.SelectedRows[0].Cells[4].Value.ToString();
- }
- }
- }
Add Comment
Please, Sign In to add comment