Пређи на главни садржај

Antiques in c# 2



  OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=B9B10.accdb");
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text != "")
                {
                    int br = 0;
                    string izbroj = "Select Max(PeriodID) From Period";
                    OleDbCommand prebroj = new OleDbCommand(izbroj, con);
                    con.Open();
                    OleDbDataReader dr = prebroj.ExecuteReader();
                    while (dr.Read())
                    { br = (int)dr.GetValue(0); }
                    if (Convert.ToInt32(textBox1.Text) > br) textBox2.Clear();

                    string select = "Select Period From Period Where PeriodID=@PeriodID";
                    OleDbCommand cmd = new OleDbCommand(select, con);
                    cmd.Parameters.AddWithValue("PeriodID", Convert.ToInt32(textBox1.Text));


                    OleDbDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                        textBox2.Text = reader.GetString(0);
                }
                else if (textBox1.Text == "") textBox2.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(textBox1.Text!="" && textBox2.Text != "")
            {
                string delete = "Delete From Period Where PeriodID=@PeriodID";
                OleDbCommand cmd = new OleDbCommand(delete, con);
                cmd.Parameters.AddWithValue("PeriodID", Convert.ToInt32(textBox1.Text));
                try
                {
                    con.Open();
                    if (Convert.ToInt32(cmd.ExecuteNonQuery()) == 1)
                    {
                        MessageBox.Show("Uspešno ste izbrisali period!");
                        textBox1.Clear();
                        textBox2.Clear();
                    }
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    con.Close();
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(textBox1.Text!="" && textBox2.Text != "")
            {
                string unesi = "Insert Into Period Values(@PeriodID, @Period)";
                OleDbCommand cmd = new OleDbCommand(unesi, con);
                cmd.Parameters.AddWithValue("PeriodId", Convert.ToInt32(textBox1.Text));
                cmd.Parameters.AddWithValue("Period", textBox2.Text);
                try
                {
                    con.Open();
                    if (Convert.ToInt32(cmd.ExecuteNonQuery()) == 1)
                    {
                        MessageBox.Show("Uspešno unet novi period!");
                        textBox1.Clear();
                        textBox2.Clear();
                    }
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    con.Close();
                }

            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if(textBox1.Text!="" && textBox2.Text != "")
            {
                string update = "Update Period Set Period=@Period Where PeriodID=@PeriodID";
                OleDbCommand cmd = new OleDbCommand(update, con);
                cmd.Parameters.AddWithValue("Period", textBox2.Text);
                cmd.Parameters.AddWithValue("PeriodID", Convert.ToInt32(textBox1.Text));
                try
                {
                    con.Open();
                    if (Convert.ToInt32(cmd.ExecuteNonQuery()) == 1)
                    {
                        MessageBox.Show("Uspešno je izvršena izmena!");
                        textBox1.Clear();
                        textBox2.Clear();
                    }
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally {
                    con.Close();
                }
            }
      }

Query:

   private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
   
        private void button1_Click(object sender, EventArgs e)
        {
            OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=B9B10.accdb");
            if (comboBox1.Text != "")
            {
                string select = "Select Naziv As [Naziv lokaliteta], KoordinateDuzine As [Koordinate duzine], KoordinateSirine As [Koordinate sirine] From Lokalitet, Tip_Antikviteta, Antikvitet Where Tip_Antikviteta.Tip=@Tip_Antikviteta.Tip And Tip_Antikviteta.TipAntikvitetaID=Antikvitet.TipAntikvitetaID And Lokalitet.LokalitetID=Antikvitet.LokalitetID";
                OleDbCommand cmd = new OleDbCommand(select, con);
                cmd.Parameters.AddWithValue("Tip_Antikviteta.Tip", comboBox1.Text);
                OleDbDataAdapter adapter = new OleDbDataAdapter();
                adapter.SelectCommand = cmd;
                DataSet ds = new DataSet();
                adapter.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Graphics g = pictureBox1.CreateGraphics();
            Pen p = new Pen(Color.Blue, 4);
            g.DrawRectangle(p, 0, 0, pictureBox1.Width, pictureBox1.Height);
            Point p1 = new Point(pictureBox1.Width / 2, pictureBox1.Height);
            Point p2 = new Point(pictureBox1.Width / 2, -pictureBox1.Height);
            g.DrawLine(p, p1, p2);

            Point p3 = new Point(-pictureBox1.Width, pictureBox1.Height / 2);
            Point p4 = new Point(pictureBox1.Width, pictureBox1.Height / 2);
            g.DrawLine(p, p3, p4);

            label2.Visible = true;
            label3.Visible = true;
            label4.Visible = true;
            label5.Visible = true;
            label6.Visible = true;
            label7.Visible = true;
            label8.Visible = true;
            label9.Visible = true;
            label10.Visible = true;
            label11.Visible = true;
            label12.Visible = true;
            label13.Visible = true;
           

            string sirina, duzina;
            if (dataGridView1.SelectedCells.Count > 0)
            {
                DataGridViewRow red = dataGridView1.SelectedRows[0];
                duzina = red.Cells[1].Value.ToString();
                sirina = red.Cells[2].Value.ToString();

                int m1 = duzina.IndexOf(' ');
                int m2 = sirina.IndexOf(' ');
                int brDuzine = Convert.ToInt32(duzina.Substring(0, m1));
                int brSirine = Convert.ToInt32(sirina.Substring(0, m2));

                Pen pen = new Pen(Color.Red, 2);


                if (duzina.Contains("istocno") && sirina.Contains("severno"))
                {
                    g.DrawEllipse(pen, pictureBox1.Width / 2 + brDuzine, pictureBox1.Height / 2 - brSirine, 4, 4);
                }
                else if (duzina.Contains("istocno") && sirina.Contains("juzno"))
                {
                    g.DrawEllipse(pen, pictureBox1.Width / 2 + brDuzine, pictureBox1.Height / 2 + brSirine, 4, 4);
                }
                else if (duzina.Contains("zapadno") && sirina.Contains("severno"))
                {
                    g.DrawEllipse(pen, pictureBox1.Width / 2 - brDuzine, pictureBox1.Height / 2 - brSirine, 4, 4);
                }
                else if (duzina.Contains("zapadno") && sirina.Contains("juzno"))
                {
                    g.DrawEllipse(pen, pictureBox1.Width / 2 - brDuzine, pictureBox1.Height / 2 + brSirine, 4, 4);
                }
            }
            g.Dispose();



        }

        private void Form5_Load(object sender, EventArgs e)
        {
            label2.Visible = false;
            label3.Visible = false;
            label4.Visible = false;
            label5.Visible = false;
            label6.Visible = false;
            label7.Visible = false;
            label8.Visible = false;
            label9.Visible = false;
            label10.Visible = false;
            label11.Visible = false;
            label12.Visible = false;
            label13.Visible = false;
            OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=B9B10.accdb");
            string select = "Select Tip From Tip_Antikviteta Order BY Tip";
            OleDbCommand cmd = new OleDbCommand(select, con);
            con.Open();
            OleDbDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
                comboBox1.Items.Add(reader.GetString(0));
           

Коментари

Популарни постови са овог блога

Charts with more than one source c# pt1

 private void radioButton1_CheckedChanged(object sender, EventArgs e)         {             button1.Enabled = true;             button2.Enabled=false;             textBox1.Enabled=true;             textBox2.Enabled = true;             textBox3.Enabled = true;             textBox5.Enabled = true;             comboBox1.Enabled = true;             List<string> kategorije = new List<string>();             string drl = "Select Naziv From Kategorija ORDER BY Naziv";             OleDbCommand komanda = new OleDbCommand(drl, con);             con.Open();             OleDbDataReader read...

Insert stadions in database c#

 private void Form4_Load(object sender, EventArgs e)         {             OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=B5B6.accdb");             List<string> gradovi = new List<string>();             string select = "Select Grad From Grad Order By Grad";             OleDbCommand cmd = new OleDbCommand(select, con);             con.Open();             OleDbDataReader reader = cmd.ExecuteReader();             while (reader.Read())                 gradovi.Add(reader.GetString(0));             comboBox1.DataSource = gradovi;             con.Close();         }   ...