Advertisement
Guest User

Untitled

a guest
Jun 13th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11.  
  12. namespace OsiguranjeVozila
  13. {
  14. public partial class Polise : Form
  15. {
  16. public Polise()
  17. {
  18. InitializeComponent();
  19. citanjeSifre();
  20. }
  21. SqlConnection konekcija = new SqlConnection(Konekcija.kon);
  22. SqlCommand komanda;
  23. private void btnUpisi_Click(object sender, EventArgs e)
  24. {
  25. if (Convert.ToInt32(textBox1.Text)>1)
  26. {
  27. komanda = new SqlCommand("INSERT INTO Polisa (PolisaID,DatumPocetka,DatumZavrsetka,Vrednost) VALUES (@sifra,@datumPocetka,@datumZavrsetka,@vrednost)", konekcija);
  28. komanda.Parameters.AddWithValue("@sifra", Convert.ToInt32(cmbSifra.Text));
  29.  
  30.  
  31.  
  32. komanda.Parameters.AddWithValue("@datumPocetka", monthCalendar1.SelectionRange.Start.ToString("dd MMM yyyy"));
  33. komanda.Parameters.AddWithValue("@datumZavrsetka", monthCalendar2.SelectionRange.Start.ToString("dd MMM yyyy"));
  34. komanda.Parameters.AddWithValue("@vrednost", textBox1.Text);
  35.  
  36. try
  37. {
  38. konekcija.Open();
  39. komanda.ExecuteNonQuery();
  40. konekcija.Close();
  41. MessageBox.Show("Uspesno ste upisali!");
  42. resetuj();
  43.  
  44. }
  45. catch (Exception)
  46. {
  47.  
  48. MessageBox.Show("Greska!");
  49. }
  50. }
  51. else
  52. {
  53. MessageBox.Show("Vrednost mora biti veca od 1!!!");
  54. textBox1.Clear();
  55. textBox1.Focus();
  56. }
  57.  
  58. }
  59.  
  60. private void popuni()
  61. {
  62.  
  63. int a = Convert.ToInt32(cmbSifra.Text);
  64. string s = "select Vrednost from Polisa where PolisaID=" + a;
  65.  
  66.  
  67. komanda = new SqlCommand(s, konekcija);
  68.  
  69. SqlDataReader citac = null;
  70.  
  71. try
  72. {
  73. konekcija.Open();
  74. citac = komanda.ExecuteReader();
  75. while (citac.Read())
  76. {
  77.  
  78. textBox1.Text = citac["Vrednost"].ToString();
  79.  
  80. }
  81. konekcija.Close();
  82. }
  83. catch (Exception)
  84. {
  85.  
  86. MessageBox.Show("Greska!");
  87. }
  88. }
  89. private void resetuj()
  90. {
  91.  
  92.  
  93. cmbSifra.Text = "";
  94. textBox1.Clear();
  95.  
  96. }
  97.  
  98. private void citanjeSifre()
  99. {
  100.  
  101.  
  102. SqlDataAdapter da = new SqlDataAdapter("select * from Polisa", konekcija);
  103. DataTable dt = new DataTable();
  104. da.Fill(dt);
  105. for (int i = 0; i < dt.Rows.Count; i++)
  106. {
  107. cmbSifra.Items.Add(dt.Rows[i]["PolisaID"]);
  108. }
  109.  
  110.  
  111. }
  112.  
  113.  
  114. private void Polise_Load(object sender, EventArgs e)
  115. {
  116. monthCalendar1.MinDate = DateTime.Now;
  117. monthCalendar2.MinDate = DateTime.Now;
  118. }
  119.  
  120. private void btnIzadji_Click(object sender, EventArgs e)
  121. {
  122. Form1 f = new Form1();
  123. f.ShowDialog();
  124. }
  125.  
  126. private void btnObrisi_Click(object sender, EventArgs e)
  127. {
  128. int a = Convert.ToInt32(cmbSifra.Text);
  129. string s = "delete from Polisa where PolisaID=" + a;
  130. komanda = new SqlCommand(s, konekcija);
  131. try
  132. {
  133. konekcija.Open();
  134. komanda.ExecuteNonQuery();
  135. MessageBox.Show("Uspesno ste obrisali!");
  136. konekcija.Close();
  137. }
  138. catch (Exception)
  139. {
  140.  
  141. MessageBox.Show("Greska!");
  142. }
  143. }
  144.  
  145. private void btnIzmeni_Click(object sender, EventArgs e)
  146. {
  147.  
  148. int a = Convert.ToInt32(cmbSifra.Text);
  149. string vrednost = textBox1.Text;
  150.  
  151. string s = "update Polisa set Vrednost = '"+vrednost+"' where PolisaID = " + a;
  152. komanda = new SqlCommand(s, konekcija);
  153. try
  154. {
  155. konekcija.Open();
  156. komanda.ExecuteNonQuery();
  157. MessageBox.Show("Uspesno ste Izmenili!");
  158. konekcija.Close();
  159. }
  160. catch (Exception)
  161. {
  162.  
  163. MessageBox.Show("Greska!");
  164. }
  165. }
  166.  
  167. private void cmbSifra_SelectedIndexChanged(object sender, EventArgs e)
  168. {
  169. popuni();
  170. }
  171. }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement