Advertisement
Guest User

GULE OTVORI

a guest
Sep 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 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 MySql.Data.MySqlClient;
  11.  
  12. namespace WindowsFormsApplication1
  13. {
  14. public partial class Glumci : Form
  15. {
  16. MySqlConnection konekcija = new MySqlConnection();
  17. MySqlCommand komanda = new MySqlCommand();
  18. MySqlDataAdapter da = new MySqlDataAdapter();
  19. DataTable glumac = new DataTable();
  20. DataTable pom = new DataTable();
  21.  
  22. public Glumci()
  23. {
  24. InitializeComponent();
  25. }
  26.  
  27. private void Form2_Load(object sender, EventArgs e)
  28. {
  29.  
  30.  
  31. konekcija.ConnectionString = "Server=192.168.10.21; DATABASE=32zvekic_b3;" + "UID=32zvekic; PASSWORD=123";
  32.  
  33. komanda.Connection = konekcija;
  34. da.SelectCommand = komanda;
  35.  
  36. if (!konekcija.Ping())
  37. konekcija.Open();
  38.  
  39. komanda.CommandText = "SELECT * FROM glumac ORDER BY GlumacID ASC";
  40.  
  41. da.Fill(glumac);
  42.  
  43. dataGridView1.DataSource = glumac;
  44. }
  45.  
  46. private void button4_Click(object sender, EventArgs e)
  47. {
  48. this.Close();
  49. }
  50.  
  51. private void button2_Click(object sender, EventArgs e)
  52. {
  53. if (!konekcija.Ping())
  54. konekcija.Open();
  55.  
  56. if (textBox1.Text != "")
  57. {
  58. komanda.CommandText = "DELETE FROM glumac where GlumacID=" + textBox1.Text;
  59. }
  60.  
  61. komanda.CommandText = "SELECT * FROM glumac ORDER BY GlumacID ASC";
  62.  
  63. }
  64.  
  65. private void textBox1_TextChanged(object sender, EventArgs e)
  66. {
  67. if (textBox1.Text != "")
  68. {
  69. try
  70. {
  71. int x = Convert.ToInt32(textBox1.Text);
  72. }
  73. catch (FormatException)
  74. {
  75. MessageBox.Show("Ukucaj broj");
  76. textBox1.Clear();
  77.  
  78. }
  79.  
  80. catch { }
  81. }
  82.  
  83.  
  84. }
  85.  
  86. private void button1_Click(object sender, EventArgs e)
  87. {
  88. try
  89. {
  90. if (!konekcija.Ping())
  91. konekcija.Open();
  92.  
  93. if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "")
  94. {
  95.  
  96. DateTime d = Convert.ToDateTime(textBox4.Text);
  97.  
  98. komanda.CommandText = "INSERT INTO glumac values(" + textBox1.Text + ",'" + textBox2.Text + "','" + textBox3.Text + "','" + d.ToString("yyyy-MM-dd") + "','" + textBox5.Text + "')";
  99. komanda.ExecuteNonQuery();
  100. }
  101. }
  102. catch (FormatException)
  103. {
  104. MessageBox.Show("Molimo upisite u pravilnom formatu");
  105. textBox4.Clear();
  106. }
  107. catch { }
  108.  
  109.  
  110. }
  111.  
  112. private void button3_Click(object sender, EventArgs e)
  113. {
  114. try
  115. {
  116. if (!konekcija.Ping())
  117. konekcija.Open();
  118.  
  119. if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "")
  120. {
  121.  
  122. DateTime d = Convert.ToDateTime(textBox4.Text);
  123.  
  124. komanda.CommandText = "UPDATE glumac SET ime = '" + textBox2.Text + "', prezime = '" + textBox3.Text + "', DatumRodjenja='" + d.ToString("yyyy-MM-dd") + "', MestoRodjenja='" + textBox5.Text + "' where GlumacID=" + textBox1.Text + " ";
  125. komanda.ExecuteNonQuery();
  126. }
  127. }
  128. catch (FormatException)
  129. {
  130. MessageBox.Show("Molimo upisite u pravilnom formatu");
  131. textBox4.Clear();
  132. }
  133. catch { }
  134.  
  135. }
  136.  
  137. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  138. {
  139.  
  140. }
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement