Exemplo n.º 1
0
        private void deleteDraudTiek_Click(object sender, EventArgs e)
        {
            try
            {
                DraudimoTiekejai gl = new DraudimoTiekejai();
                gl.tiekejo_Id = int.Parse(deleteDraudTiekTiekId.Text);
                draudTiekRep.DeleteDraudTiek(gl);

                deleteDraudTiekTiekId.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            MessageBox.Show("Deleted succesfully");
            getDraudimasTiekDisplay();
            getDraudimasDisplay();
        }
        public void UpdateDraudimoTiekejai(DraudimoTiekejai draudimoTiekejai)
        {
            try
            {
                //setting new SqlConnection, providing connectionString
                cnn = new MySqlConnection(connectionString);

                //check if user exist
                MySqlCommand cmd = new MySqlCommand("Update draudimoTiekejai SET pavadinimas=@pavadinimas WHERE tiekId=@tiekId", cnn);//to check if username exist we have to select all items with username
                cmd.Parameters.AddWithValue("@pavadinimas", draudimoTiekejai.pavadinimas);
                cmd.Parameters.AddWithValue("@tiekId", draudimoTiekejai.tiekejo_Id);
                cnn.Open();
                cmd.ExecuteNonQuery();
                cnn.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemplo n.º 3
0
        private void updateDraudTIek_Click(object sender, EventArgs e)
        {
            try
            {
                DraudimoTiekejai dt = new DraudimoTiekejai();
                dt.pavadinimas = updateDraudTiekPav.Text;
                dt.tiekejo_Id  = int.Parse(updateTiekDraudTiekId.Text);

                draudTiekRep.UpdateDraudimoTiekejai(dt);

                updateDraudTiekPav.Clear();
                updateTiekDraudTiekId.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            getDraudimasTiekDisplay();
            MessageBox.Show("Succesfully updated");
        }
        public void DeleteDraudTiek(DraudimoTiekejai draudimoTiekejai)
        {
            try
            {
                cnn = new MySqlConnection(connectionString);

                string newSql = ("Delete from draudimas where draudimas.tiekId=@id; ");
                newSql += ("Delete from draudimoTiekejai where draudimoTiekejai.tiekId=@id");

                cnn.Open();                                       //open connection. we use the Open method of the cnn variable to open a connection to the database.
                MySqlCommand cmd = new MySqlCommand(newSql, cnn); //select all from newTestTable
                cmd.Parameters.AddWithValue("@id", draudimoTiekejai.tiekejo_Id);
                cmd.ExecuteNonQuery();                            //execute function

                cnn.Close();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
            }
        }
Exemplo n.º 5
0
        private void addDraudTIek_Click(object sender, EventArgs e)
        {
            try
            {
                DraudimoTiekejai dt = new DraudimoTiekejai();
                dt.pavadinimas = addDraudTiekPav.Text;
                DraudimoTiekejai insertedDt = draudTiekRep.InsertDraudimoTiekejai(dt);

                if (insertedDt.pavadinimas != null && insertedDt.pavadinimas != "")
                {
                    MessageBox.Show("Succesfully inserted");
                }

                addDraudTiekPav.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            getDraudimasTiekDisplay();
        }
        //REGISTER STUDENT
        public DraudimoTiekejai InsertDraudimoTiekejai(DraudimoTiekejai draudimoTiekejai)//provide transportas object when calling this function
        {
            try
            {
                //setting new SqlConnection, providing connectionString
                cnn = new MySqlConnection(connectionString);
                cnn.Open();//open database

                //check if transportas exist
                MySqlCommand cmd = new MySqlCommand("Select * from draudimoTiekejai where pavadinimas=@pavadinimas", cnn);
                cmd.Parameters.AddWithValue("@pavadinimas", draudimoTiekejai.pavadinimas);

                MySqlDataReader dataReader = cmd.ExecuteReader();//sends SQLCommand.CommandText to the SQLCommand.Connection and builds SqlDataReader
                if ((dataReader.Read() == true))
                {
                    Console.WriteLine("Tiekejo toks yra");
                    return(null);
                }
                else
                {
                    Console.WriteLine("Tiekejo nera. Galima pridet");
                }
                dataReader.Close();//close data reader when it finishes work

                MySqlCommand cmd2 = new MySqlCommand("Insert into draudimoTiekejai (pavadinimas) VALUES(@pavadinimas)", cnn);
                cmd2.Parameters.AddWithValue("@pavadinimas", draudimoTiekejai.pavadinimas);
                cmd2.ExecuteNonQuery();

                cnn.Close();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
            }
            return(draudimoTiekejai);//return
        }