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 OsiguranjeVozila
- {
- public partial class Polise : Form
- {
- public Polise()
- {
- InitializeComponent();
- citanjeSifre();
- }
- SqlConnection konekcija = new SqlConnection(Konekcija.kon);
- SqlCommand komanda;
- private void btnUpisi_Click(object sender, EventArgs e)
- {
- if (Convert.ToInt32(textBox1.Text)>1)
- {
- komanda = new SqlCommand("INSERT INTO Polisa (PolisaID,DatumPocetka,DatumZavrsetka,Vrednost) VALUES (@sifra,@datumPocetka,@datumZavrsetka,@vrednost)", konekcija);
- komanda.Parameters.AddWithValue("@sifra", Convert.ToInt32(cmbSifra.Text));
- komanda.Parameters.AddWithValue("@datumPocetka", monthCalendar1.SelectionRange.Start.ToString("dd MMM yyyy"));
- komanda.Parameters.AddWithValue("@datumZavrsetka", monthCalendar2.SelectionRange.Start.ToString("dd MMM yyyy"));
- komanda.Parameters.AddWithValue("@vrednost", textBox1.Text);
- try
- {
- konekcija.Open();
- komanda.ExecuteNonQuery();
- konekcija.Close();
- MessageBox.Show("Uspesno ste upisali!");
- resetuj();
- }
- catch (Exception)
- {
- MessageBox.Show("Greska!");
- }
- }
- else
- {
- MessageBox.Show("Vrednost mora biti veca od 1!!!");
- textBox1.Clear();
- textBox1.Focus();
- }
- }
- private void popuni()
- {
- int a = Convert.ToInt32(cmbSifra.Text);
- string s = "select Vrednost from Polisa where PolisaID=" + a;
- komanda = new SqlCommand(s, konekcija);
- SqlDataReader citac = null;
- try
- {
- konekcija.Open();
- citac = komanda.ExecuteReader();
- while (citac.Read())
- {
- textBox1.Text = citac["Vrednost"].ToString();
- }
- konekcija.Close();
- }
- catch (Exception)
- {
- MessageBox.Show("Greska!");
- }
- }
- private void resetuj()
- {
- cmbSifra.Text = "";
- textBox1.Clear();
- }
- private void citanjeSifre()
- {
- SqlDataAdapter da = new SqlDataAdapter("select * from Polisa", konekcija);
- DataTable dt = new DataTable();
- da.Fill(dt);
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- cmbSifra.Items.Add(dt.Rows[i]["PolisaID"]);
- }
- }
- private void Polise_Load(object sender, EventArgs e)
- {
- monthCalendar1.MinDate = DateTime.Now;
- monthCalendar2.MinDate = DateTime.Now;
- }
- private void btnIzadji_Click(object sender, EventArgs e)
- {
- Form1 f = new Form1();
- f.ShowDialog();
- }
- private void btnObrisi_Click(object sender, EventArgs e)
- {
- int a = Convert.ToInt32(cmbSifra.Text);
- string s = "delete from Polisa where PolisaID=" + a;
- komanda = new SqlCommand(s, konekcija);
- try
- {
- konekcija.Open();
- komanda.ExecuteNonQuery();
- MessageBox.Show("Uspesno ste obrisali!");
- konekcija.Close();
- }
- catch (Exception)
- {
- MessageBox.Show("Greska!");
- }
- }
- private void btnIzmeni_Click(object sender, EventArgs e)
- {
- int a = Convert.ToInt32(cmbSifra.Text);
- string vrednost = textBox1.Text;
- string s = "update Polisa set Vrednost = '"+vrednost+"' where PolisaID = " + a;
- komanda = new SqlCommand(s, konekcija);
- try
- {
- konekcija.Open();
- komanda.ExecuteNonQuery();
- MessageBox.Show("Uspesno ste Izmenili!");
- konekcija.Close();
- }
- catch (Exception)
- {
- MessageBox.Show("Greska!");
- }
- }
- private void cmbSifra_SelectedIndexChanged(object sender, EventArgs e)
- {
- popuni();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement