protected void BotonBuscar_Click(object sender, EventArgs e) { string consulta = "select b.idreserva as 'N° Reserva' , fechareserva as 'Fecha Reserva', subtotalreserva as SubTotal, b.IMPUESTOSRESERVA as Impuesto, totalreserva as Total, fechainicio as 'Fecha de Inicio', fechafin as 'Fecha de Fin', numerohuespedes as 'N° Huespedes', nombrecliente as 'Nombre Cliente', pasaportecliente as Pasaporte, telefonocliente as Telefono, mailcliente as mail from cliente a, reserva b where a.dicliente = b.dicliente and b.idreserva = (select max(idreserva) from reserva)"; ConsultasBaseDatos consu = new ConsultasBaseDatos(); DataTable consultaregreso; consultaregreso = consu.consultar(consulta); this.GridView1.DataSource = consultaregreso; GridView1.Visible = true; this.GridView1.DataBind(); consultaregreso = consu.consultar(consulta); if (consultaregreso.Rows.Count > 0) { DataRow row = consultaregreso.Rows[0]; TextBox1.Text = row["Nombre Cliente"].ToString(); } string consulta3 = "select nombretipohabitacion as 'Tipo Habitación', numerohabitacion as 'N° Habitación', descripcionhabitacion as Descripción, preciohabitacion as Precio, numeropiso as 'N° Piso' from tipohabitacion a, habitacion b, DETALLERESERVA c, reserva d, cliente e where e.DICLIENTE = d.DICLIENTE and d.IDRESERVA = c.IDRESERVA and b.IDHABITACION = c.IDHABITACION and a.IDTIPOHABITACION = b.IDTIPOHABITACION and NOMBRECLIENTE like '" + TextBox1.Text + "'"; DataTable consultaregreso3; consultaregreso3 = consu.consultar(consulta3); this.GridView2.DataSource = consultaregreso3; GridView2.Visible = true; this.GridView2.DataBind(); string consulta4 = "select nombreasociado as 'Nombre de Huésped', pasaporteasociado as 'Número de Pasaporte' from cliente a, CLIENTEASOCIADO b where a.DICLIENTE = b.DICLIENTE and NOMBRECLIENTE like '" + TextBox1.Text + "'"; DataTable consultaregreso4; consultaregreso4 = consu.consultar(consulta4); this.GridView3.DataSource = consultaregreso4; GridView3.Visible = true; this.GridView3.DataBind(); }
//Botón Buscar protected void Buscar_Click(object sender, EventArgs e) { BotonReservar.Enabled = true; string fechainicio = Calendar1.SelectedDate.ToString(); string fachafin = Calendar2.SelectedDate.ToString(); ConsultasBaseDatos consu = new ConsultasBaseDatos(); string consulta = "select top " + DropDownList1.SelectedValue + " numerohabitacion as 'Numero de la habitacion', numeropiso as Piso,descripcionhabitacion as 'Descripción',preciohabitacion as precio, idhabitacion as cod from habitacion where estadohabitacion = 'Disponible' and idtipohabitacion='1' and idhabitacion not in (select idhabitacion from reserva a, detallereserva b where a.idreserva = b.idreserva and fechainicio between '" + Calendar1.SelectedDate.ToString("MM/dd/yyyy HH:MM:ss") + "' and '" + Calendar2.SelectedDate.ToString("MM/dd/yyyy HH:MM:ss") + "')"; string consulta1 = "select top " + DropDownList5.SelectedValue + " numerohabitacion as 'Numero de la habitacion',numeropiso as Piso,descripcionhabitacion as 'Descripción',preciohabitacion as precio, idhabitacion as cod from habitacion where estadohabitacion = 'Disponible' and idtipohabitacion='2' and idhabitacion not in (select idhabitacion from reserva a, detallereserva b where a.idreserva = b.idreserva and fechainicio between '" + Calendar1.SelectedDate.ToString("MM/dd/yyyy HH:MM:ss") + "' and '" + Calendar2.SelectedDate.ToString("MM/dd/yyyy HH:MM:ss") + "')"; string consulta2 = "select top " + DropDownList6.SelectedValue + " numerohabitacion as 'Numero de la habitacion',numeropiso as Piso,descripcionhabitacion as 'Descripción',preciohabitacion as precio, idhabitacion as cod from habitacion where estadohabitacion = 'Disponible' and idtipohabitacion='3' and idhabitacion not in (select idhabitacion from reserva a, detallereserva b where a.idreserva = b.idreserva and fechainicio between '" + Calendar1.SelectedDate.ToString("MM/dd/yyyy HH:MM:ss") + "' and '" + Calendar2.SelectedDate.ToString("MM/dd/yyyy HH:MM:ss") + "')"; string consulta3 = "select top " + DropDownList7.SelectedValue + " numerohabitacion as 'Numero de la habitacion',numeropiso as Piso,descripcionhabitacion as 'Descripción',preciohabitacion as precio, idhabitacion as cod from habitacion where estadohabitacion = 'Disponible' and idtipohabitacion='4' and idhabitacion not in (select idhabitacion from reserva a, detallereserva b where a.idreserva = b.idreserva and fechainicio between '" + Calendar1.SelectedDate.ToString("MM/dd/yyyy HH:MM:ss") + "' and '" + Calendar2.SelectedDate.ToString("MM/dd/yyyy HH:MM:ss") + "')"; DataTable consultaregreso, consultaregreso1, consultaregreso2, consultaregreso3; //Simples consultaregreso = consu.consultar(consulta); this.GridView2.DataSource = consultaregreso; GridView2.Visible = true; this.GridView2.DataBind(); //Dobles consultaregreso1 = consu.consultar(consulta1); this.GridView3.DataSource = consultaregreso1; GridView3.Visible = true; this.GridView3.DataBind(); //Dobles consultaregreso2 = consu.consultar(consulta2); this.GridView6.DataSource = consultaregreso2; GridView6.Visible = true; this.GridView6.DataBind(); //Dobles consultaregreso3 = consu.consultar(consulta3); this.GridView7.DataSource = consultaregreso3; GridView7.Visible = true; this.GridView7.DataBind(); //Total Simples double suma = GridView2.Rows.Cast <GridViewRow>().Sum(x => Convert.ToDouble(x.Cells[3].Text)); //Total Dobles double suma1 = GridView3.Rows.Cast <GridViewRow>().Sum(x => Convert.ToDouble(x.Cells[3].Text)); //Total Twin double suma2 = GridView6.Rows.Cast <GridViewRow>().Sum(x => Convert.ToDouble(x.Cells[3].Text)); //Total Triples double suma3 = GridView7.Rows.Cast <GridViewRow>().Sum(x => Convert.ToDouble(x.Cells[3].Text)); double total = suma + suma1 + suma2 + suma3; double Impuesto = 14; double calculoImpuesto = ((Impuesto * total) / 100); double subtotal = total - calculoImpuesto; TextBox5.Text = Convert.ToString(subtotal).Replace(",", "."); TextBox6.Text = Convert.ToString(calculoImpuesto).Replace(",", "."); TextBox7.Text = Convert.ToString(total).Replace(",", "."); }
//Botón Buscar protected void Buscar_Click(object sender, EventArgs e) { ConsultasBaseDatos consu = new ConsultasBaseDatos(); int tipohabitacion = DropDownList4.SelectedIndex + 1; int precio = int.Parse(TextBox5.Text); string consulta = "select NUMEROHABITACION as 'Numero Habitación',DESCRIPCIONHABITACION as Descripción,PRECIOHABITACION as Precio from HABITACION where ESTADOHABITACION = 'Disponible'and IDTIPOHABITACION=1"; DataTable consultaregreso; consultaregreso = consu.consultar(consulta); this.GridView1.DataSource = consultaregreso; GridView1.Visible = true; if (consultaregreso.Rows.Count == 0) { TextBox10.Text = "no hay habitaciones"; } this.GridView1.DataBind(); }
//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"; } } }
//Botón Buscar protected void BotonBuscar_Click(object sender, EventArgs e) { string consulta = "select NOMBRETIPOHABITACION,NUMEROHABITACION, PRECIOHABITACION, DESCRIPCIONHABITACION, NUMEROPISO, ESTADOHABITACION from TIPOHABITACION a, HABITACION b where a.IDTIPOHABITACION = b.IDHABITACION and NUMEROHABITACION = '" + TextBox1.Text + "'"; ConsultasBaseDatos consu = new ConsultasBaseDatos(); DataTable consultaregreso; Label1.Visible = false; Label2.Visible = false; Label3.Visible = false; Label4.Visible = false; Label5.Visible = false; if (IsNumeric(TextBox1.Text) == false) { TextBox5.Visible = true; TextBox5.Text = "Solo números"; Label2.Visible = true; } else { if (TextBox1.Text == "" || TextBox1.Text == "0") { Label2.Visible = true; TextBox5.Visible = true; TextBox5.Text = "Ingrese un número para la búsqueda"; } else { Label2.Visible = false; consultaregreso = consu.consultar(consulta); if (consultaregreso.Rows.Count > 0) { DataRow row = consultaregreso.Rows[0]; TextBox2.Text = row["PRECIOHABITACION"].ToString(); TextBox3.Text = row["DESCRIPCIONHABITACION"].ToString(); TextBox4.Text = row["NUMEROPISO"].ToString(); TextBox5.Text = row["NOMBRETIPOHABITACION"].ToString(); TextBox6.Text = row["ESTADOHABITACION"].ToString(); TextBox7.Text = row["NUMEROHABITACION"].ToString(); TextBox4.Enabled = false; TextBox6.Visible = true; TextBox5.Visible = true; BotonNuevo.Visible = true; } else { TextBox1.Text = "0"; Label2.Visible = false; TextBox5.Visible = true; TextBox5.Text = "No hay Resultados"; } } } }
//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); } } }