Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            VistaHabitaciones form = new VistaHabitaciones();

            form.Show();
            this.Hide();
        }
Example #2
0
        private void reservacionTermina(object sender, EventArgs e)
        {
            string i = (sender as Button).Text;

            if (query("UPDATE habitacion SET estado = " + 1 + ", descripcion = 'Ocupado' WHERE id LIKE " + i + ";"))
            {
                var    src   = DateTime.Now;
                int    dias  = 0;
                double costo = 0;

                string          connStr = "server=localhost;user=root;database=dbHotel;port=3306;password="******"Connecting to MySQL...");
                    conn.Open();

                    string          sql = "select datediff((SELECT fechaEntrada FROM reservacion WHERE fkIdHabitacion LIKE " + i + " AND fechaSalida IS NULL), NOW()) as resultado1, (SELECT costo FROM habitacion WHERE Id LIKE " + i + ")as resultado2;";
                    MySqlCommand    cmd = new MySqlCommand(sql, conn);
                    MySqlDataReader rdr = cmd.ExecuteReader();

                    while (rdr.Read())
                    {
                        dias  = rdr.GetInt32(rdr.GetOrdinal("resultado1"));
                        costo = rdr.GetDouble(rdr.GetOrdinal("resultado2"));
                    }

                    if (src.Hour >= 12 && src.Hour <= 24 || dias == 0)
                    {
                        dias++;
                    }

                    rdr.Close();
                    conn.Close();
                    Console.WriteLine("Done.");

                    if (query("UPDATE reservacion SET fechaSalida = NOW(), importe = " + (costo * dias) + " WHERE fkIdHabitacion LIKE " + i + " AND fechaSalida IS NULL;"))
                    {
                        VistaHabitaciones form = new VistaHabitaciones();
                        form.Show();
                        this.Hide();
                        MessageBox.Show("Sevicio a la habitacion " + this.Text + " terminado, importe: " + (costo * dias).ToString("G", CultureInfo.CreateSpecificCulture("eu-ES")));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    conn.Close();
                    MessageBox.Show("Error 2 al terminar reservacion");
                }
            }
            else
            {
                MessageBox.Show("Error 1 al terminar reservacion");
            }
        }
Example #3
0
        private void reservacionInicio(object sender, EventArgs e)
        {
            string i = (sender as Button).Text;

            if (query("UPDATE habitacion SET estado = " + 0 + ", descripcion = 'Ocupado' WHERE id LIKE " + i + ";"))
            {
                if (query("INSERT INTO reservacion (fkIdHabitacion) VALUES (" + i + ");"))
                {
                    VistaHabitaciones form = new VistaHabitaciones();
                    form.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Error 2 al crear reservacion");
                }
            }
            else
            {
                MessageBox.Show("Error 1 al crear reservacion");
            }
        }