Пример #1
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection conn            = Yhteys.openConnection();
            string        insertStatement = "Insert into AutoTable (merkki, malli, rekisterinumero, vuosimalli, katsastuspvm, koko, teho) values('" + MerkkiBox.Text + "' , '" + MalliBox.Text + "' , '" + RekisteriBox.Text + "' , '" + VuosimalliBox.Text + "' , '" + KatsastusBox.Text + "' , '" + KokoBox.Text + "' , '" + TehoBox.Text + "' )";

            SqlCommand insertCommand = new SqlCommand(insertStatement, conn);

            conn.Open();
            insertCommand.ExecuteNonQuery();
        }
Пример #2
0
        private void ButtonPoista_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection conn            = Yhteys.openConnection();
            string        PoistaStatement = "Delete FROM AutoTable WHERE id=('" + textBoxPoista.Text + "')";

            SqlCommand insertCommand = new SqlCommand(PoistaStatement, conn);

            conn.Open();
            insertCommand.ExecuteNonQuery();
            MessageBox.Show("Kohde poistettu");
        }
Пример #3
0
        private void ButtonJarjesta_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection conn = Yhteys.openConnection();

            if (radioButtonMerkki.IsChecked == true)
            {
                string     JarjestaStatement = "Select * from AutoTable Order by merkki";
                SqlCommand jarjestaCommand   = new SqlCommand(JarjestaStatement, conn);
                conn.Open();
                jarjestaCommand.ExecuteNonQuery();
            }
        }
Пример #4
0
        private void MuokkaaButton_Click(object sender, RoutedEventArgs e)
        {
            if (checkBoxMuokkaus.IsChecked == true)
            {
                SqlConnection conn            = Yhteys.openConnection();
                string        UpdateStatement = "UPDATE AutoTable SET Merkki=('" + MerkkiBox.Text + "'), Malli=('" + MalliBox.Text + "'), rekisterinumero=('" + RekisteriBox.Text + "'), vuosimalli=('" + VuosimalliBox.Text + "'), katsastuspvm=('" + KatsastusBox.Text + "'), koko=('" + KokoBox.Text + "'), teho=('" + TehoBox.Text + "') WHERE Id=('" + textBoxId.Text + "')";

                SqlCommand selectCommand = new SqlCommand(UpdateStatement, conn);
                conn.Open();
                selectCommand.ExecuteNonQuery();
            }
            else
            {
                MessageBox.Show("Muokkaustila ei ole päällä");
            }
        }
Пример #5
0
        private void HaeButton_Click(object sender, RoutedEventArgs e)
        {
            listViewInfo.Items.Clear();
            SqlDataReader dataReader;
            String        Output = "";
            SqlConnection conn   = Yhteys.openConnection();

            if (radioButtonKaikki.IsChecked == true && radioButtonMerkki.IsChecked == true)
            {
                string     JarjestaStatement = "Select * from AutoTable Order by merkki";
                SqlCommand jarjestaCommand   = new SqlCommand(JarjestaStatement, conn);
                conn.Open();
                jarjestaCommand.ExecuteNonQuery();
                dataReader = jarjestaCommand.ExecuteReader();
            }

            else if (radioButtonKaikki.IsChecked == true && radioButtonMalli.IsChecked == true)
            {
                string     JarjestaStatement = "Select * from AutoTable Order by malli";
                SqlCommand jarjestaCommand   = new SqlCommand(JarjestaStatement, conn);
                conn.Open();
                jarjestaCommand.ExecuteNonQuery();
                dataReader = jarjestaCommand.ExecuteReader();
            }
            else if (radioButtonKaikki.IsChecked == true && radioButtonVanhin.IsChecked == true)
            {
                string     JarjestaStatement = "Select * from AutoTable Order by vuosimalli ASC";
                SqlCommand jarjestaCommand   = new SqlCommand(JarjestaStatement, conn);
                conn.Open();
                jarjestaCommand.ExecuteNonQuery();
                dataReader = jarjestaCommand.ExecuteReader();
            }
            else if (radioButtonKaikki.IsChecked == true && radioButtonUusin.IsChecked == true)
            {
                string     JarjestaStatement = "Select * from AutoTable Order by vuosimalli DESC";
                SqlCommand jarjestaCommand   = new SqlCommand(JarjestaStatement, conn);
                conn.Open();
                jarjestaCommand.ExecuteNonQuery();
                dataReader = jarjestaCommand.ExecuteReader();
            }
            else if (radioButtonKaikki.IsChecked == true)
            {
                string     selectStatement = "Select * from AutoTable";
                SqlCommand selectCommand   = new SqlCommand(selectStatement, conn);
                conn.Open();
                selectCommand.ExecuteNonQuery();
                dataReader = selectCommand.ExecuteReader();
            }
            else
            {
                string     selectStatement = "Select * from AutoTable WHERE rekisterinumero =('" + RekisteriBox.Text + "')";
                SqlCommand selectCommand   = new SqlCommand(selectStatement, conn);
                conn.Open();
                selectCommand.ExecuteNonQuery();
                dataReader = selectCommand.ExecuteReader();
            }

            while (dataReader.Read())
            {
                Output = Output + dataReader.GetValue(0) + " - Merkki:" + dataReader.GetValue(1) + " - Malli:" + dataReader.GetValue(2) + " - Rekisterinumero:" + dataReader.GetValue(3) + " - Vuosimalli:" + dataReader.GetValue(4) + " - Katsastuspvm:" + dataReader.GetValue(5) + " - Koko:" + dataReader.GetValue(6) + " - Teho:" + dataReader.GetValue(7) + "\n";
            }
            MessageBox.Show(Output);

            OutputList = Output.Split('\n').ToList();

            foreach (string str in OutputList)
            {
                listViewInfo.Items.Add(str);
            }
        }