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.Data.SqlClient;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace B6_Fudbalski_klub_i_utakmice
- {
- public partial class Form2 : Form
- {
- SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-BEDE3AM\SQLEXPRESS;Initial Catalog=B6;Integrated Security=True");
- public Form2()
- {
- InitializeComponent();
- }
- private void Form2_Load(object sender, EventArgs e)
- {
- // TODO: This line of code loads data into the 'b6DataSet.Grad' table. You can move, or remove it, as needed.
- this.gradTableAdapter.Fill(this.b6DataSet.Grad);
- string k = "select top 1 * from Stadion";
- int stadion = 0;
- try
- {
- con.Open();
- SqlCommand cmd = new SqlCommand(k, con);
- SqlDataReader dr = cmd.ExecuteReader();
- while(dr.Read())
- {
- textBox1.Text = dr[0].ToString();
- textBox2.Text = dr[1].ToString();
- textBox3.Text = dr[2].ToString();
- textBox4.Text = dr[3].ToString();
- textBox5.Text = dr[4].ToString();
- stadion = Convert.ToInt32(dr[5].ToString());
- }
- dr.Close();
- // MessageBox.Show(stadion.ToString());
- string k2 = "select Grad from Grad where GradID="+stadion;
- SqlCommand cmd2 = new SqlCommand(k2, con);
- SqlDataReader dr2 = cmd2.ExecuteReader();
- if(dr2.Read())
- {
- comboBox1.SelectedIndex = stadion - 1;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- throw;
- }
- finally
- {
- if (con.State == ConnectionState.Open) con.Close();
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- try
- {
- textBox1.Text = "";
- textBox2.Text = "";
- textBox3.Text = "";
- textBox4.Text = "";
- textBox5.Text = "";
- comboBox1.Text = "";
- textBox1.Focus();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- throw;
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string k = "";
- if (textBox1.Text == "")
- k = "select top 1 * from Stadion";
- else
- k = "select top 1 * from Stadion where StadionID=" + (Convert.ToInt32(textBox1.Text)-1);
- try
- {
- con.Open();
- SqlCommand cmd = new SqlCommand(k, con);
- SqlDataReader dr = cmd.ExecuteReader();
- int grad = 0;
- while (dr.Read())
- {
- textBox1.Text = dr[0].ToString();
- textBox2.Text = dr[1].ToString();
- textBox3.Text = dr[2].ToString();
- textBox4.Text = dr[3].ToString();
- textBox5.Text = dr[4].ToString();
- grad = Convert.ToInt32(dr[5].ToString());
- }
- dr.Close();
- string k2 = "";
- k2 = "select Grad from Grad where GradID=" + grad;
- SqlCommand cmd2 = new SqlCommand(k2, con);
- SqlDataReader dr2 = cmd2.ExecuteReader();
- if (dr2.Read())
- {
- comboBox1.SelectedIndex = grad - 1;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- throw;
- }
- finally
- {
- if (con.State == ConnectionState.Open) con.Close();
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- string k = "";
- if (textBox1.Text == "")
- k = "select top 1 * from Stadion order by StadionID desc";
- else
- k = "select top 1 * from Stadion where StadionID=" + (Convert.ToInt32(textBox1.Text) + 1);
- try
- {
- con.Open();
- SqlCommand cmd = new SqlCommand(k, con);
- SqlDataReader dr = cmd.ExecuteReader();
- int grad = 0;
- while (dr.Read())
- {
- textBox1.Text = dr[0].ToString();
- textBox2.Text = dr[1].ToString();
- textBox3.Text = dr[2].ToString();
- textBox4.Text = dr[3].ToString();
- textBox5.Text = dr[4].ToString();
- grad = Convert.ToInt32(dr[5].ToString());
- }
- dr.Close();
- string k2 = "";
- k2 = "select Grad from Grad where GradID=" + grad;
- SqlCommand cmd2 = new SqlCommand(k2, con);
- SqlDataReader dr2 = cmd2.ExecuteReader();
- if (dr2.Read())
- {
- comboBox1.SelectedIndex = grad - 1;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- throw;
- }
- finally
- {
- if (con.State == ConnectionState.Open) con.Close();
- }
- }
- private void button4_Click(object sender, EventArgs e)
- {
- string k = "insert into Stadion values("+textBox1.Text+ ", N'" + textBox2.Text + "', N'" + textBox3.Text + "', " + textBox4.Text + ", " + textBox5.Text + ", "+comboBox1.SelectedValue+")";
- try
- {
- con.Open();
- SqlCommand cmd = new SqlCommand(k, con);
- cmd.ExecuteNonQuery();
- MessageBox.Show("Uspesno ste uneli stadion");
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- //throw;
- }
- finally
- {
- if (con.State == ConnectionState.Open) con.Close();
- }
- }
- private void button5_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement