X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/blobdiff_plain/a339833551941a32ea6f156e136fd2f7ee95f8bf..7cd2e930f9665432a3bfa725b90bf3c0a3cb5617:/gui/articulos.c?ds=inline diff --git a/gui/articulos.c b/gui/articulos.c index af349dd..28c0cc1 100644 --- a/gui/articulos.c +++ b/gui/articulos.c @@ -1,6 +1,10 @@ #include "articulos.h" +t_LstArticulos *lst_articulos; + +t_Articulo *art_form_buscar(WINDOW *win); + t_LstArticulos *art_cargar(const char *filename) { xmlDocPtr document; @@ -9,7 +13,7 @@ t_LstArticulos *art_cargar(const char *filename) t_LstArticulos *tmp = (t_LstArticulos *)malloc(sizeof(t_LstArticulos)); if (tmp == NULL) return NULL; - document = xmlParseFile(filename); + document = xmlReadFile(filename, "ISO-8859-1",0); if (document == NULL) { free(tmp); return NULL; @@ -61,13 +65,13 @@ t_LstArticulos *art_cargar(const char *filename) for ( ; node ; node = node->next) { if (node->type == XML_ELEMENT_NODE) { if (strcmp(node->name, "ARTICULO") == 0) { - strncpy(tmp->array[cant].numero, xmlGetProp(node, "NroArticulo"), 8); - strncpy(tmp->array[cant].desc, xmlGetProp(node, "Descripcion"), 50); - strncpy(tmp->array[cant].presentacion, xmlGetProp(node, "Presentacion"), 30); + strncpy(tmp->array[cant].numero, xmlGetProp(node, "NroArtículo"), 8); + strncpy(tmp->array[cant].desc, xmlGetProp(node, "Descripción"), 50); + strncpy(tmp->array[cant].presentacion, xmlGetProp(node, "Presentación"), 30); strncpy(tmp->array[cant].existencia, xmlGetProp(node, "Existencia"), 8); -// strncpy(tmp->array[cant].ubicacion, xmlGetProp(node, "Ubicacion"), 30); +// / strncpy(tmp->array[cant].ubicacion, xmlGetProp(node, "Ubicacion"), 30); strncpy(tmp->array[cant].pvu, xmlGetProp(node, "PVU"), 8); - strncpy(tmp->array[cant].emin, xmlGetProp(node, "Emin"), 8); + strncpy(tmp->array[cant].emin, xmlGetProp(node, "Emín"), 8); ++cant; } } @@ -75,16 +79,19 @@ t_LstArticulos *art_cargar(const char *filename) xmlFreeDoc(document); xmlCleanupParser(); + lst_articulos = tmp; return tmp; } int art_liberar(t_LstArticulos *l) { + if (l == NULL) l = lst_articulos; if (l == NULL) return 1; free(l->array); free(l); + lst_articulos = NULL; return 0; } @@ -92,6 +99,9 @@ t_Articulo *art_obtener(t_LstArticulos *lst, const char *numero) { int i, j; int n = atoi(numero); + + if (lst == NULL) lst = lst_articulos; + for(i=0; icant; i++) { j = atoi(lst->array[i].numero); if (n == j) @@ -101,3 +111,102 @@ t_Articulo *art_obtener(t_LstArticulos *lst, const char *numero) return NULL; } +t_Articulo *art_form_buscar(WINDOW *win) +{ + t_Form *form; + t_Articulo *articulo; + + form = form_crear(win); + form_agregar_widget(form, INPUT, "Numero de Artículo", 8, ""); + form_ejecutar(form, 1,1); + articulo = art_obtener(NULL, form_obtener_valor(form, "Numero de Artículo")); + form_destruir(form); + + return articulo; +} + +void art_modificar(char *s) +{ + WINDOW *win; + t_Form *form; + t_Articulo *articulo; + + win = newwin(8, 68, 13, 1); + box(win, 0, 0); + wrefresh(win); + + articulo = art_form_buscar(win); + + if (articulo != NULL) { + form = form_crear(win); + form_agregar_widget(form, INPUT, "Numero de Artículo", 8, articulo->numero); + form_agregar_widget(form, INPUT, "Descripción", 50, articulo->desc); + form_agregar_widget(form, INPUT, "Presentación", 30, articulo->presentacion); + form_agregar_widget(form, INPUT, "Stock Actual", 8, articulo->existencia); + form_agregar_widget(form, INPUT, "PVU", 8, articulo->pvu); + form_agregar_widget(form, INPUT, "Stock Mínimo", 8, articulo->emin); + form_ejecutar(form, 1,1); + + /* TODO : Actualizar registro */ + + form_destruir(form); + } + + werase(win); + wrefresh(win); + delwin(win); +} + +void art_eliminar(char *s) +{ + WINDOW *win; + t_Articulo *articulo; + + win = newwin(8, 68, 13, 1); + box(win, 0, 0); + wrefresh(win); + + articulo = art_form_buscar(win); + + if (articulo == NULL) { + wattron(win, COLOR_PAIR(COLOR_YELLOW)); + mvwaddstr(win, 6, 4, "No existe artículo con ese código. Abortando!"); + wattroff(win, COLOR_PAIR(COLOR_YELLOW)); + wrefresh(win); + getch(); + } else { + /* TODO : Eliminar un registro */ + } + + werase(win); + wrefresh(win); + delwin(win); +} + +void art_agregar(char *s) +{ + WINDOW *win; + t_Form *form; + + win = newwin(8, 68, 13, 1); + box(win, 0, 0); + wrefresh(win); + + form = form_crear(win); + form_agregar_widget(form, INPUT, "Numero de Artículo", 8, ""); + form_agregar_widget(form, INPUT, "Descripción", 50, ""); + form_agregar_widget(form, INPUT, "Presentación", 30, ""); + form_agregar_widget(form, INPUT, "Stock Actual", 8, ""); + form_agregar_widget(form, INPUT, "PVU", 8, ""); + form_agregar_widget(form, INPUT, "Stock Mínimo", 8, ""); + form_ejecutar(form, 1,1); + + /* TODO : Agregar el nuevo elemento */ + + form_destruir(form); + + werase(win); + wrefresh(win); + delwin(win); +} +