Advertisement
Guest User

Untitled

a guest
Aug 14th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.62 KB | None | 0 0
  1. void crearTablaInsumos(){
  2.     GtkButton *btEliminar;
  3.     GtkGrid *gridInsumos;
  4.     GtkLabel *lbNombre,*lbId;
  5.     gridInsumos=GTK_GRID(gtk_grid_new());
  6.     gtk_grid_set_column_homogeneous(GTK_GRID(gridInsumos),TRUE);
  7.  
  8.     int             rec_count;
  9.     int             row;
  10.    
  11.     conn = PQconnectdb("dbname=SistemaProduccion host=localhost user=postgres password=andyjosue");
  12.      if (PQstatus(conn) == CONNECTION_BAD) {
  13.                  printf("\nNo hemos sido capaz de conectar a la BD");
  14.                  
  15.     }
  16.     //Select de la tabla
  17.     res = PQexec(conn,"select * from Insumos");
  18.  
  19.     if (PQresultStatus(res) != PGRES_TUPLES_OK) {
  20.                  printf("No tenemos ningún dato!");
  21.                
  22.     }
  23.     rec_count = PQntuples(res);
  24.     // En el for se va creando la tabla de insumos.
  25.     for (row=0; row<rec_count; row++){
  26.         lbId=GTK_LABEL(gtk_label_new(PQgetvalue(res, row, 0)));
  27.         gtk_grid_attach(GTK_GRID(gridInsumos),GTK_WIDGET(lbId),0,row,1,1);
  28.         lbNombre=GTK_LABEL(gtk_label_new(PQgetvalue(res, row, 1)));
  29.         gtk_grid_attach(GTK_GRID(gridInsumos),GTK_WIDGET(lbNombre),1,row,1,1);
  30.         btEliminar=GTK_BUTTON(gtk_button_new_with_label("Eliminar"));
  31.         // Se enlaza la funcion al boton y sus parametros.
  32.         g_signal_connect(G_OBJECT(btEliminar),"clicked",G_CALLBACK(borrarInsumo),GINT_TO_POINTER(row));
  33.         gtk_grid_attach(GTK_GRID(gridInsumos),GTK_WIDGET(btEliminar),2,row,1,1);
  34.     }
  35.     // Se agrega la tabla creada al contenedor.
  36.     gtk_box_pack_start(GTK_BOX(boxGridInsumos),GTK_WIDGET(gridInsumos),FALSE,TRUE,0);
  37.     PQclear(res);
  38.     PQfinish(conn);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement