// Copyright (c) 2003,2004,2005 Juraj Kolesár #include "api.h" #include "t_s_item.h" /* qs {{{ *********************************************************************/ int t_s_item_qs(WINDOW *win, T_DB *tdb, T_QS *qs, T_ITEM *item) { bool End = false; bool Chosen = false; bool own_win = (win != NULL); int Status; T_COLS * cols = NULL; if (!own_win) win = newwin(8,70,10,2); lt_s_item_qs_init(item, &cols, qs); while (!End) { lt_s_item_data_init(item); Status = tt_table_qs(win, tdb, qs, cols); switch (Status) { case __TT_ENTER: if (strlen(item->pk.value) > 0) { item->status[__PK] = true; lt_s_item_data_get(tdb, item); } break; case __TT_INS: lt_s_item_data_clear(item); break; case __TT_ESC: lt_s_item_data_clear(item); End = true; break; } if (!End) Chosen = End = t_s_item_form(win, tdb, item); } werase(win);wrefresh(win); if (!own_win) delwin(win); return(Chosen); } /* }}} */ /* form {{{ *******************************************************************/ int t_s_item_form(WINDOW *win, T_DB *tdb, T_ITEM *item) { register int i; bool End = false; int menu_cursor = 0; POS pos[__LT_S_ITEM_PARAM_COUNT]; T_CELLIST *menu = NULL; T_CELL menu_item[] = { {"[POUŽI ]", "", 0}, {"[ SPÄŤ ]", "", 0}, {"[ INFO ]", "", 0} }; FILL_CELLIST(menu, menu_item, 4, i); SET_POS(pos[__PK], win, 1, 50); SET_POS(pos[__NUMBER], win, 1, 13); SET_POS(pos[__NAME], win, 2, 13); SET_POS(pos[__CODE], win, 3, 13); SET_POS(pos[__MESSURE], win, 4, 13); SET_POS(pos[__PRICE], win, 5, 13); if (!(item->status[__LT_S_ITEM_PK])) { lt_s_item_next_number(tdb, item); if (t_s_item_form_new(tdb, item, pos)) lt_s_item_data_set(tdb, item); else End = true; } t_s_item_form_draw(item, pos); // wrefresh(win); while (!End) { menu = g_list_first(menu); menu = g_list_nth(menu, menu_cursor); switch(tt_menu_vertical(pos[0], menu, 9)) { case __TT_ESC: End = true; break; case (0): werase(win); return(true); break; //OK case (1): End = true; break; //BACK case (2): break; //INFO } } werase(win); return(false); } /* }}} */ /* form draw {{{ **************************************************************/ int t_s_item_form_draw(T_ITEM *item, POS *pos) { register int i; T_CELL cell[] = { //for additional datas stored in T_TABLE to showrow {"", "", 0}, //PK {"", "", 13}, //VALUE {"", "", 20} //NOTE }; T_COLS *cols = NULL; for (i=0;i<3;i++) cols = g_slist_append(cols, &(cell[i])); werase(pos[__NAME].win); box(pos[__NAME].win,0,0); tt_label_left(pos[__NUMBER], "Karta:"); tt_label_left(pos[__NAME], "Názov:"); tt_label_left(pos[__CODE], "Kód:"); tt_label_left(pos[__MESSURE], "Jednotka:"); tt_label_left(pos[__PRICE], "L.Cena:"); mvwprintw(GET_POS(pos[__NUMBER]), item->number.value); mvwprintw(GET_POS(pos[__NAME]), item->name.value); mvwprintw(GET_POS(pos[__CODE]), "[.]%s",item->code.name); mvwprintw(GET_POS(pos[__MESSURE]), "[.]%s",item->messure.name); mvwprintw(GET_POS(pos[__PRICE]), item->price.value); return(__LT_OK); } /* }}} */ /* form new {{{ ***************************************************************/ int t_s_item_form_new(T_DB *tdb, T_ITEM *item, POS *pos) { bool End = false; int Object = __NAME; int Status; strcpy(item->code.name, ""); strcpy(item->messure.name, ""); t_s_item_form_draw(item, pos); while (!End) { switch (Object) { case __NAME: Status = tt_str_get(pos[__NAME], item->name.width, item->name.value); if (strlen(item->name.value) > 0) item->status[__NAME] = false; else item->status[__NAME] = true; break; case __CODE: Status = t_s_item_set_code(pos[__CODE], tdb, item); break; case __MESSURE: Status = t_s_item_set_messure(pos[__MESSURE], tdb, item); break; } switch (Status) { case __TT_ENTER: if ( !(item->status[__NAME]) && !(item->status[__CODE]) && !(item->status[__MESSURE]) ) End = true; else tt_message(pos->win, "Nevyplnili ste vsetky udaje"); break; case __TT_TAB: Object++; break; case __TT_ESC: return(End); break; } if (Object > __MESSURE) Object = __NAME; } return(End); //change to bool created true else false } /* }}} */ /* {{{ ************************************************************************* int t_s_item_set_cp(POS point, T_ITEM *item) { WINDOW *win; int BegX, BegY; int Status = __TT_ERR; if (*table == NULL) return(__TT_OK); bool Status; register int i; T_MATRIX matrix; T_CELL code_cells[] = { {"", "", 0}, {"", "", __LT_S_ITEM_WIDTH_CODE} }; T_COLS *cols = NULL; getbegyx(point.win, BegY, BegX); win = newwin(3, t_cols_width_sum(*cols) + g_slist_length(*cols), BegY + point.y - 1, BegX + point.x ); COLS_FILL(cols, code_cells, 2, i); lt_s_item_get_code(tdb, &matrix); Status = tt_table_combo(point, &(matrix.table), &cols); if (Status == __TT_ENTER) { strcpy(item->code.value, code_cells[0].value); strcpy(item->code.name, code_cells[1].value); } Status = tt_table(win, table, cols); werase(win);wrefresh(win);delwin(win);touchwin(point.win); return(Status); } /* }}} */ /* set code {{{ ***************************************************************/ int t_s_item_set_code(POS point, T_DB *tdb, T_ITEM *item) { int Status; T_MATRIX matrix; lt_s_item_get_codes(tdb, &matrix); Status = tt_table_input(point, &(item->code), matrix.table); switch (Status) { case(__TT_ENTER): item->status[__CODE] = false; Status = __TT_TAB; break; case(__TT_INS): if (strlen(item->code.name) > 0) if (tt_message(point.win, "Vložiť nový kód?") == __TT_ENTER) lt_s_item_new_code(tdb, item); else item->code.name[0] = '\0'; break; } return(Status); } /* }}} */ /* set messure {{{ ************************************************************/ int t_s_item_set_messure(POS point, T_DB *tdb, T_ITEM *item) { int Status; T_MATRIX matrix; lt_s_item_get_messures(tdb, &matrix); Status = tt_table_input(point, &(item->messure), matrix.table); switch (Status) { case(__TT_ENTER): item->status[__MESSURE] = false; Status = __TT_TAB; break; case(__TT_INS): if (strlen(item->messure.name) > 0) if (tt_message(point.win, "Vložíť nový typ mernej jednotky?") == __TT_ENTER) lt_s_item_new_messure(tdb, item); else item->messure.name[0] = '\0'; break; } return(Status); } /* }}} */