//metodo para insertar, se manda a llamar en el button2_click private void guardar() { //variables int Tot, dias, colprecio; string id, columna1; DataGridViewRow fila = dataGridView1.CurrentRow; // obtengo la fila actualmente seleccionada en el dataGridView //tomar la fecha de hoy DateTime Hoy = DateTime.Today; string fecha_reserva = Hoy.ToString("dd/MM/yyyy"); //conversiones columna1 = Convert.ToString(fila.Cells[3].Value); //obtengo el valor de la columna precio id = Convert.ToString(fila.Cells[0].Value); //obtengo el valor de la columna id colprecio = Convert.ToInt32(columna1); Convert.ToInt32(id); //Calcular la cantidad de dias TimeSpan ts = dateTimePicker2.Value - dateTimePicker1.Value; dias = (int)ts.TotalDays; //operaciones Tot = dias * colprecio; //insert DatosRes DatosRes = new DatosRes(); DatosRes.Id_empleado = "1"; DatosRes.Id_habitacion = id; DatosRes.Fecha_reservacion = fecha_reserva; DatosRes.Fecha_entrada = dateTimePicker1.Value.ToString(); DatosRes.Fecha_salida = dateTimePicker2.Value.ToString(); DatosRes.Nombre_cliente = Cliente_nombre_txt.Text; DatosRes.Telefono_cliente = textBox3.Text; DatosRes.Tarjeta_pago = textBox5.Text; DatosRes.Total = Tot; update1(Tot); int resultado = Regreserva.Agregar(DatosRes); if (resultado > 0) { MessageBox.Show("Datos Guardados Correctamente", "Datos Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("No se pudieron Guardar lo datos", "Error al Guardar", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public static int Agregar(DatosRes pDatosRes) { int retorno = 0; using (SqlConnection Conn = Conexion.ObtnerCOnexion()) { SqlCommand Comando = new SqlCommand(string.Format("Insert Into Reservaciones (Id_empleado, Id_habitacion, Fecha_reservacion, Fecha_entrada, Fecha_salida, Nombre_cliente, Telefono_cliente, Tarjeta_pago, Total) values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}')", pDatosRes.Id_empleado, pDatosRes.Id_habitacion, pDatosRes.Fecha_reservacion, pDatosRes.Fecha_entrada, pDatosRes.Fecha_salida, pDatosRes.Nombre_cliente, pDatosRes.Telefono_cliente, pDatosRes.Tarjeta_pago, pDatosRes.Total), Conn); retorno = Comando.ExecuteNonQuery(); SqlCommand Comando2 = new SqlCommand(string.Format("Insert Into Disponibilidad_hab (Id_habitacion, Fecha_entrada, Fecha_salida, Estado) values ('{0}', '{1}', '{2}', '{3}')", pDatosRes.Id_habitacion, pDatosRes.Fecha_entrada, pDatosRes.Fecha_salida, "No disponible"), Conn); retorno = Comando2.ExecuteNonQuery(); Conn.Close(); } return(retorno); }
// public void buscar_ultimo_id_reservacion() { int res; using (SqlConnection Conn = Conexion.ObtnerCOnexion()) { SqlCommand cmd = Conn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select Id_reservacion from Reservaciones where Id_reservacion = some (select max (Id_reservacion) from Reservaciones)"; cmd.ExecuteNonQuery(); cmd.Parameters.AddWithValue("Id_reservacion", "Id_reservacion".ToString()); res = Convert.ToInt32(cmd.ExecuteScalar()); Conn.Close(); } //insert DatosRes DatosRes = new DatosRes(); DatosRes.Id_reservacion = res; int resultado = Insertchekinout.Agregar(DatosRes); }