Ejemplo n.º 1
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            using (MySqlConnection cn = new MySqlConnection(_myconnectionstring))
            {
                string idClear = textBox1.Text;
                int    intId;
                string sql = null;
                int    idHashKonvertert;

                if (textBox1.Text == string.Empty)
                {
                    MessageBox.Show(@"Du må taste inn noe!");
                    return;
                }


                if (int.TryParse(idClear, out intId))
                {
                    sql = "DELETE FROM booking WHERE bookingId=" + intId;
                }

                else
                {
                    var   hashids = new Hashids("Tralalalalala, dette er min SALT");
                    int[] idHash  = hashids.Decode(idClear);
                    try
                    {
                        idHashKonvertert = idHash[0];
                    }
                    catch (Exception exception)
                    {
                        idHashKonvertert = 9999999;
                    }
                    sql = "DELETE FROM booking WHERE bookingId=" + idHashKonvertert;
                }


                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = cn;
                cmd.CommandText = sql;
                cn.Open();
                int numRowsUpdated = cmd.ExecuteNonQuery();
                cmd.Dispose();

                if (numRowsUpdated == 1)
                {
                    MessageBox.Show("Booking med id/ref: " + idClear +
                                    " ble slettet. Applikasjonen vil nå laste på nytt");
                    Hide();
                    HotelBookForm hotelBookForm = new HotelBookForm();
                    hotelBookForm.Closed += (s, args) => Close();
                    hotelBookForm.Show();
                }
                else
                {
                    MessageBox.Show("Fant ingen booking med inntastet id eller ref nummer");
                }
            }
        }
Ejemplo n.º 2
0
        private void slettBookingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (MySqlConnection cn = new MySqlConnection(_myconnectionstring))
            {
                var          sql = "DELETE FROM booking WHERE bookingId=" + _idx;
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = cn;
                cmd.CommandText = sql;
                cn.Open();
                int numRowsUpdated = cmd.ExecuteNonQuery();
                cmd.Dispose();

                if (numRowsUpdated == 1)
                {
                    dataGridView1.Rows.RemoveAt(rowIndex);
                    Hide();
                    HotelBookForm hotelBookForm = new HotelBookForm();
                    hotelBookForm.Closed += (s, args) => Close();
                    hotelBookForm.Show();
                }
            }
        }