Advertisement
Guest User

GULEEEE

a guest
Nov 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 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=32golubs_b3;" + "UID=32golubs; 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.  
  54. if (!konekcija.Ping())
  55. konekcija.Open();
  56.  
  57. if (textBox1.Text != "")
  58. {
  59. komanda.CommandText = "DELETE FROM uloga where GlumacID=" + textBox1.Text + ";";
  60. komanda.CommandText += "DELETE FROM glumac where GlumacID=" + textBox1.Text;
  61. if (komanda.ExecuteNonQuery() == 1)
  62. {
  63. MessageBox.Show("Uspesno obrisano");
  64. }
  65. }
  66.  
  67. komanda.CommandText = "SELECT * FROM glumac ORDER BY GLumacID ASC";
  68. glumac.Clear();
  69. da.Fill(glumac);
  70.  
  71. }
  72.  
  73. private void textBox1_TextChanged(object sender, EventArgs e)
  74. {
  75.  
  76. try
  77. {
  78. if (!konekcija.Ping())
  79. konekcija.Open();
  80.  
  81.  
  82. //komanda.CommandText = "INSERT INTO glumac(GlumacID, Ime,Prezime,DatumRodjenja,MestoRodjenja) values(" + textBox1.Text + ",'" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text+ "')";
  83. //komanda.ExecuteNonQuery();
  84.  
  85. komanda.CommandText = "SELECT * FROM glumac where GlumacID='"+textBox1.Text+"'";
  86. glumac.Clear();
  87. da.Fill(glumac);
  88.  
  89. textBox2.Text = glumac.Rows[0][1].ToString();
  90. textBox3.Text = glumac.Rows[0][2].ToString();
  91. textBox4.Text = glumac.Rows[0][3].ToString();
  92. textBox5.Text = glumac.Rows[0][4].ToString();
  93.  
  94.  
  95.  
  96. }
  97. catch
  98. {
  99. }
  100.  
  101.  
  102.  
  103. }
  104.  
  105. private void button1_Click(object sender, EventArgs e)
  106. {
  107. try
  108. {
  109. if (!konekcija.Ping())
  110. konekcija.Open();
  111.  
  112. if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "")
  113. {
  114.  
  115. DateTime d = Convert.ToDateTime(textBox4.Text);
  116.  
  117. komanda.CommandText = "INSERT INTO glumac values(" + textBox1.Text + ",'" + textBox2.Text + "','" + textBox3.Text + "','" + d.ToString("yyyy-MM-dd") + "','" + textBox5.Text + "')";
  118. komanda.ExecuteNonQuery();
  119.  
  120.  
  121. }
  122. }
  123. catch (FormatException)
  124. {
  125. MessageBox.Show("Molimo upisite u pravilnom formatu");
  126. textBox4.Clear();
  127. }
  128. catch { }
  129.  
  130.  
  131. }
  132.  
  133. private void button3_Click(object sender, EventArgs e)
  134. {
  135. try
  136. {
  137. if (!konekcija.Ping())
  138. konekcija.Open();
  139.  
  140. if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "")
  141. {
  142.  
  143. DateTime d = Convert.ToDateTime(textBox4.Text);
  144.  
  145. komanda.CommandText = "UPDATE glumac SET ime = '" + textBox2.Text + "', prezime = '" + textBox3.Text + "', DatumRodjenja='" + d.ToString("yyyy-MM-dd") + "', MestoRodjenja='" + textBox5.Text + "' where GlumacID=" + textBox1.Text + " ";
  146. komanda.ExecuteNonQuery();
  147.  
  148. }
  149. komanda.CommandText = "SELECT * FROM glumac ORDER BY GlumacID ASC";
  150. glumac.Clear();
  151. da.Fill(glumac);
  152.  
  153. }
  154. catch (FormatException)
  155. {
  156. MessageBox.Show("Molimo upisite u pravilnom formatu");
  157. textBox4.Clear();
  158. }
  159. catch { }
  160.  
  161.  
  162.  
  163. }
  164.  
  165. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  166. {
  167.  
  168. }
  169. }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement