//Boton Actualizar
        protected void BotonActualizar_Click(object sender, EventArgs e)
        {
            ConsultasBaseDatos update = new ConsultasBaseDatos();

            if (IsNumeric(TextBox2.Text) == false)
            {
                TextBox5.Visible = true;
                TextBox5.Text    = "Solo números";
                Label3.Visible   = true;
            }

            else
            {
                if (TextBox2.Text == "" || TextBox3.Text == "" || TextBox6.Text == "")
                {
                    TextBox5.Visible = true;
                    TextBox5.Text    = "Los campos * no pueden estar vacíos";
                    Label3.Visible   = true;
                    Label4.Visible   = true;
                    Label6.Visible   = true;
                }

                else
                {
                    string ingreso = "update HABITACION set PRECIOHABITACION = " + TextBox2.Text + ", DESCRIPCIONHABITACION = '" + TextBox3.Text + "', ESTADOHABITACION = '" + TextBox6.Text + "' where NUMEROHABITACION = '" + TextBox7.Text + "'";
                    update.counsultaTodoTipo(ingreso);
                    Label3.Visible   = false;
                    Label4.Visible   = false;
                    Label6.Visible   = false;
                    TextBox5.Text    = "Datos Actualizados";
                    TextBox6.Text    = "";
                    TextBox6.Visible = false;
                    TextBox1.Text    = "0";
                    TextBox2.Text    = "0";
                    TextBox3.Text    = "0";
                    TextBox4.Text    = "0";
                    TextBox4.Enabled = true;
                }
            }
        }
        //Boton Guardar
        protected void BotonGuardar_Click(object sender, EventArgs e)
        {
            int numpiso = int.Parse(TextBox4.Text);

            Label1.Visible   = false;
            Label2.Visible   = false;
            Label3.Visible   = false;
            Label4.Visible   = false;
            Label5.Visible   = false;
            TextBox5.Text    = "";
            TextBox5.Visible = false;

            //Comando SQL Insert para la base de datos

            string ingresar  = "insert INTO HABITACION (IDTIPOHABITACION,NUMEROHABITACION,PRECIOHABITACION,DESCRIPCIONHABITACION,NUMEROPISO,ESTADOHABITACION) VALUES (" + DropDownList1.SelectedValue + ",'" + TextBox1.Text + "'," + TextBox2.Text + ",'" + TextBox3.Text + "','" + TextBox4.Text + "','Disponible')";
            string consulta  = "select NUMEROHABITACION from HABITACION where NUMEROHABITACION = " + TextBox1.Text + "";
            string consulta4 = "select NUMEROHABITACION from HABITACION where NUMEROPISO = " + TextBox4.Text + "";

            if (IsNumeric(TextBox1.Text) == false || IsNumeric(TextBox2.Text) == false || IsNumeric(TextBox4.Text) == false)
            {
                TextBox5.Visible = true;
                TextBox5.Text    = "Solo valores numericos";
                Label2.Visible   = true;
                Label3.Visible   = true;
                Label5.Visible   = true;
            }

            else
            {
                ConsultasBaseDatos consu = new ConsultasBaseDatos();

                DataTable consultaregreso;
                consultaregreso = consu.consultar(consulta);

                DataTable consultaregreso1;
                consultaregreso1 = consu.consultar(consulta4);

                //Comprobación de campos vacíos
                if (TextBox1.Text == "" || TextBox2.Text == "" || TextBox3.Text == "" || TextBox4.Text == "")

                {
                    Label1.Visible   = true;
                    Label2.Visible   = true;
                    Label3.Visible   = true;
                    Label4.Visible   = true;
                    Label5.Visible   = true;
                    TextBox5.Visible = true;
                    TextBox5.Text    = "Los campos no deben ser 0 o vacíos";
                }

                else if (TextBox1.Text == "0" || TextBox2.Text == "0" || TextBox3.Text == "0" || TextBox4.Text == "0")

                {
                    Label1.Visible   = true;
                    Label2.Visible   = true;
                    Label3.Visible   = true;
                    Label4.Visible   = true;
                    Label5.Visible   = true;
                    TextBox5.Visible = true;
                    TextBox5.Text    = "Todos los campos con * son obligatorios";
                }

                else if (consultaregreso.Rows.Count > 0)
                {
                    TextBox5.Visible = true;
                    TextBox5.Text    = "El número de habitación ya está regitrado";
                    Label2.Visible   = true;
                }

                else if (TextBox4.Text == "13" || numpiso > 20)
                {
                    TextBox5.Visible = true;
                    TextBox5.Text    = "El piso no existe";
                    Label5.Visible   = true;
                }

                else if (consultaregreso1.Rows.Count > 5)
                {
                    TextBox5.Visible = true;
                    TextBox5.Text    = "En ese piso ya existen 5 habitaciones";
                    Label5.Visible   = true;
                }

                else
                {
                    Label1.Visible = false;
                    Label2.Visible = false;
                    Label3.Visible = false;
                    Label4.Visible = false;
                    Label5.Visible = false;
                    consu.counsultaTodoTipo(ingresar);
                    TextBox1.Text = "0";
                    TextBox2.Text = "0";
                    TextBox3.Text = "0";
                    TextBox4.Text = "0";
                }
            }
        }
Пример #3
0
        //Boton Aceptar
        protected void BotonAceptar_Click(object sender, EventArgs e)
        {
            string             ingresar1 = "insert into cliente values ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "')";
            string             consulta  = "select max(idreserva) as max from reserva";
            string             consulta1 = "select max(dicliente) as max from cliente";
            ConsultasBaseDatos consu     = new ConsultasBaseDatos();

            if (TextBox1.Text == "" || TextBox2.Text == "" || TextBox3.Text == "" || TextBox4.Text == "" || TextBox8.Text == "" || TextBox9.Text == "")

            {
                TextBox20.Visible = true;
                TextBox20.Text    = "Todos los campos son obligatorios";
            }

            else if (IsNumeric(TextBox2.Text) == false || IsNumeric(TextBox3.Text) == false || IsNumeric(TextBox8.Text) == false || IsNumeric(TextBox9.Text) == false)
            {
                TextBox20.Visible = true;
                TextBox20.Text    = "Solo valores numericos";
            }

            else
            {
                BotonReservar.Enabled = false;
                Nueva.Visible         = true;
                BotonAceptar.Enabled  = false;
                consu.counsultaTodoTipo(ingresar1);
                DataTable consultaregreso1;
                consultaregreso1 = consu.consultar(consulta1);
                if (consultaregreso1.Rows.Count > 0)
                {
                    DataRow row = consultaregreso1.Rows[0];
                    TextBox12.Text = row["max"].ToString();
                }
                string ingresar = "insert into reserva values (" + TextBox12.Text + ",'" + DateTime.Now.ToString("MM/dd/yyyy HH:MM:ss") + "'," + TextBox5.Text + ", " + TextBox6.Text + ", " + TextBox7.Text + ", '" + Calendar1.SelectedDate.ToString("MM/dd/yyyy HH:MM:ss") + "', '" + Calendar2.SelectedDate.ToString("MM/dd/yyyy HH:MM:ss") + "', " + DropDownList8.SelectedValue + ")";
                consu.counsultaTodoTipo(ingresar);

                DataTable consultaregreso;
                consultaregreso = consu.consultar(consulta);
                if (consultaregreso.Rows.Count > 0)
                {
                    DataRow row = consultaregreso.Rows[0];
                    TextBox11.Text = row["max"].ToString();
                }

                TextBox20.Visible = true;
                TextBox20.Text    = "Reserva Registrada";
                TextBox1.Enabled  = false;
                TextBox2.Enabled  = false;
                TextBox3.Enabled  = false;
                TextBox4.Enabled  = false;
                TextBox8.Enabled  = false;
                TextBox9.Enabled  = false;



                if (GridView2.Rows.Count == 1)
                {
                    SqlConnection conexion = new SqlConnection("Server=tcp:servidorbaseweb.database.windows.net,1433;Initial Catalog=baseWeb;Persist Security Info=False;User ID=sw;Password=Proyecto1;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");
                    conexion.Open();
                    SqlCommand agregar = new SqlCommand("insert into detallereserva  values (@idreserva,@idhabitacion);", conexion);



                    foreach (GridViewRow row in GridView2.Rows)
                    {
                        agregar.Parameters.Clear();
                        agregar.Parameters.AddWithValue("@idreserva", Convert.ToInt32(TextBox11.Text));
                        agregar.Parameters.AddWithValue("@idhabitacion", Convert.ToInt32(row.Cells[4].Text));

                        agregar.ExecuteNonQuery();
                    }
                    conexion.Close();
                }

                if (GridView3.Rows.Count == 1)
                {
                    SqlConnection conexion = new SqlConnection("Server=tcp:servidorbaseweb.database.windows.net,1433;Initial Catalog=baseWeb;Persist Security Info=False;User ID=sw;Password=Proyecto1;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");
                    conexion.Open();
                    SqlCommand agregar = new SqlCommand("insert into detallereserva  values (@idreserva,@idhabitacion);", conexion);
                    foreach (GridViewRow row in GridView3.Rows)
                    {
                        agregar.Parameters.Clear();
                        agregar.Parameters.AddWithValue("@idreserva", Convert.ToInt32(TextBox11.Text));
                        agregar.Parameters.AddWithValue("@idhabitacion", Convert.ToInt32(row.Cells[4].Text));

                        agregar.ExecuteNonQuery();
                    }
                    conexion.Close();
                }


                if (GridView6.Rows.Count == 1)
                {
                    SqlConnection conexion = new SqlConnection("Server=tcp:servidorbaseweb.database.windows.net,1433;Initial Catalog=baseWeb;Persist Security Info=False;User ID=sw;Password=Proyecto1;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");
                    conexion.Open();
                    SqlCommand agregar = new SqlCommand("insert into detallereserva  values (@idreserva,@idhabitacion);", conexion);
                    foreach (GridViewRow row in GridView6.Rows)
                    {
                        agregar.Parameters.Clear();
                        agregar.Parameters.AddWithValue("@idreserva", Convert.ToInt32(TextBox11.Text));
                        agregar.Parameters.AddWithValue("@idhabitacion", Convert.ToInt32(row.Cells[4].Text));

                        agregar.ExecuteNonQuery();
                    }
                    conexion.Close();
                }

                if (GridView7.Rows.Count == 1)
                {
                    SqlConnection conexion = new SqlConnection("Server=tcp:servidorbaseweb.database.windows.net,1433;Initial Catalog=baseWeb;Persist Security Info=False;User ID=sw;Password=Proyecto1;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");
                    conexion.Open();
                    SqlCommand agregar = new SqlCommand("insert into detallereserva  values (@idreserva,@idhabitacion);", conexion);
                    foreach (GridViewRow row in GridView7.Rows)
                    {
                        agregar.Parameters.Clear();
                        agregar.Parameters.AddWithValue("@idreserva", Convert.ToInt32(TextBox11.Text));
                        agregar.Parameters.AddWithValue("@idhabitacion", Convert.ToInt32(row.Cells[4].Text));

                        agregar.ExecuteNonQuery();
                    }
                    conexion.Close();
                }

                if (TextBox10.Visible.Equals(true) && TextBox13.Visible.Equals(true) && TextBox14.Visible.Equals(true) && TextBox15.Visible.Equals(true))
                {
                    string cliente2 = "insert into clienteasociado values (" + TextBox12.Text + ", '" + TextBox10.Text + "', '" + TextBox16.Text + "')";
                    string cliente3 = "insert into clienteasociado values (" + TextBox12.Text + ", '" + TextBox13.Text + "', '" + TextBox17.Text + "')";
                    string cliente4 = "insert into clienteasociado values (" + TextBox12.Text + ", '" + TextBox14.Text + "', '" + TextBox18.Text + "')";
                    string cliente5 = "insert into clienteasociado values (" + TextBox12.Text + ", '" + TextBox15.Text + "', '" + TextBox19.Text + "')";

                    consu.counsultaTodoTipo(cliente2);
                    consu.counsultaTodoTipo(cliente3);
                    consu.counsultaTodoTipo(cliente4);
                    consu.counsultaTodoTipo(cliente5);
                }

                else if (TextBox10.Visible.Equals(true) && TextBox13.Visible.Equals(true) && TextBox14.Visible.Equals(true))
                {
                    string cliente2 = "insert into clienteasociado values (" + TextBox12.Text + ", '" + TextBox10.Text + "', '" + TextBox16.Text + "')";
                    string cliente3 = "insert into clienteasociado values (" + TextBox12.Text + ", '" + TextBox13.Text + "', '" + TextBox17.Text + "')";
                    string cliente4 = "insert into clienteasociado values (" + TextBox12.Text + ", '" + TextBox14.Text + "', '" + TextBox18.Text + "')";

                    consu.counsultaTodoTipo(cliente2);
                    consu.counsultaTodoTipo(cliente3);
                    consu.counsultaTodoTipo(cliente4);
                }

                else if (TextBox10.Visible.Equals(true) && TextBox13.Visible.Equals(true))
                {
                    string cliente2 = "insert into clienteasociado values (" + TextBox12.Text + ", '" + TextBox10.Text + "', '" + TextBox16.Text + "')";
                    string cliente3 = "insert into clienteasociado values (" + TextBox12.Text + ", '" + TextBox13.Text + "', '" + TextBox17.Text + "')";

                    consu.counsultaTodoTipo(cliente2);
                    consu.counsultaTodoTipo(cliente3);
                }

                else
                {
                    string cliente2 = "insert into clienteasociado values (" + TextBox12.Text + ", '" + TextBox10.Text + "', '" + TextBox16.Text + "')";
                    consu.counsultaTodoTipo(cliente2);
                }
            }
        }