File: [Platon] / tucniak / api / t_s_input.c (download)
Revision 1.1.1.1 (vendor branch), Fri Nov 11 16:08:29 2005 UTC (18 years, 4 months ago) by koli
Changes since 1.1: +0 -0
lines
Initial import
|
// Copyright (c) 2003,2004,2005 Juraj Kolesár <koli@koli.sk>
#include "api.h"
#include "t_s_input.h"
/* form {{{ *******************************************************************/
int t_s_input_form(WINDOW *win, T_DB *tdb, T_INPUT *input) {
bool End = false;
POS pos[__LT_S_INPUT_PARAM_COUNT];
WINDOW *swin_items = derwin(win, 0,0,6,0);
register int i;
T_CELL cell[] = {
{"", "pk_s_add", 0},
{"", "názov", __LT_S_ITEM_WIDTH_NAME},
{"", "ks", 4},
{"", "mj", __LT_S_ITEM_WIDTH_MESSURE},
{"", "cena", 5},
{"", "spolu", 6}
};
T_COLS *cols = NULL;
FILL_COLS(cols, cell, 6, i);
SET_POS(pos[__PK], win, 10, 0);
SET_POS(pos[__CODE], win, 1, 13);
SET_POS(pos[__DATE], win, 2, 13);
SET_POS(pos[__LETTER], win, 3, 13);
SET_POS(pos[__WHERE], win, 1, 40);
SET_POS(pos[__FROM], win, 2, 40);
SET_POS(pos[__ITEMS], swin_items, 1, 0);
t_s_input_form_draw(input, pos, cols);
while (!End) {
switch (t_s_input_form_edit(tdb, input, pos, cols)) {
case __TT_ENTER:End = true; break;
case __TT_ESC:End = true; break;
}
}
werase(win);
return(__LT_OK);
}
/* }}} */
/* form draw {{{ **************************************************************/
int t_s_input_form_draw(T_INPUT *input, POS *pos, T_COLS *item_cols) {
werase(pos->win);
box(pos->win,0,0);
box(pos[__ITEMS].win,0,0);
wrefresh(pos[__ITEMS].win);
tt_label_left(pos[__CODE], "Príjemka:");
tt_label_left(pos[__DATE], "Dátum:");
tt_label_left(pos[__LETTER], "Doklad:");
tt_label_left(pos[__WHERE], "Prijal:");
tt_label_left(pos[__FROM], "Dodávatel:");
if (input->status[__CODE])
mvwprintw(GET_POS(pos[__CODE]), input->code.value);
else
mvwprintw(GET_POS(pos[__CODE]), "NOVÁ");
mvwprintw(GET_POS(pos[__LETTER]), input->letter.value);
mvwprintw(GET_POS(pos[__WHERE]), "[.]");
mvwprintw(GET_POS(pos[__FROM]), "[.]");
tt_datum_draw(pos[__DATE], input->date.value);
tt_table_draw(pos[__ITEMS].win, item_cols, input->items.table);
return(__LT_OK);
}
/* }}} */
/* form edit {{{ **************************************************************/
int t_s_input_form_edit(T_DB *tdb, T_INPUT *input, POS *pos, T_COLS *item_cols)
{
bool End = false;
int Object;
int Status;
TT_TABLE *items_table = NULL;
if (strlen(input->code.value) > 0) Object= __DATE;
else Object = __DATE;
while (!End) {
switch (Object) {
case __DATE:
Status = tt_datum_get(pos[__DATE], input->date.value);
input->status[__DATE] = false;
break;
case __LETTER:
Status = tt_str_get(pos[__LETTER], input->letter.width,
input->letter.value);
input->status[__LETTER] = false;
break;
case __WHERE:
Status = t_s_input_set_where(pos[__WHERE], tdb, input);
break;
case __FROM:
Status = t_s_input_set_from(pos[__FROM], tdb, input);
break;
case __ITEMS:
Status = tt_table(pos[__ITEMS],
&(input->items.table), item_cols);
tt_table_draw(pos[__ITEMS].win, item_cols, input->items.table);
switch (Status) {
case __TT_OK: //table empty, insert at least one item
Status = __TT_INS; break;
case __TT_TAB:
Status = t_s_input_edit_item(pos, input, item_cols);
break;
case __TT_DEL:
input->items.table = g_list_remove(input->items.table,
(input->items.table)->data);
werase(pos[__ITEMS].win);
break;
}
break;
}
switch (Status) {
case __TT_ENTER:
if (__TT_ENTER == tt_message(pos->win,"Uložiť?")) {
//BEGIN TRAN
lt_s_input_items_set(tdb, input);
lt_s_input_save(tdb, input);
//END TRAN
End = true;
}
break;
case __TT_TAB: Object++; break;
case __TT_ESC:
lt_s_input_remove_blind(tdb, input);
End = true; break;
case __TT_INS:
if (t_s_input_add_item(tdb, input)) {
tt_table_draw(pos[__ITEMS].win, item_cols,
input->items.table);
Status = t_s_input_edit_item(pos, input, item_cols);
}
break;
}
if (Object > __ITEMS) Object = __DATE;
}
return(Status);
}
/* }}} */
/* edit item {{{ **************************************************************/
int t_s_input_edit_item(POS *pos, T_INPUT *input, T_COLS *item_cols) {
int Status = tt_table_edit_cell(pos[__ITEMS].win,
input->items.table, item_cols, 2);
if (Status == __TT_TAB)
Status = tt_table_edit_cell(pos[__ITEMS].win,
input->items.table, item_cols, 4);
//TODO prepocitat hodnotu stlpca spolu
return(Status);
}
/* }}} */
/* add item {{{ ***************************************************************/
int t_s_input_add_item(T_DB *tdb, T_INPUT *input) {
T_ITEM item;
T_QS qs;
INIT_QS(qs);
lt_s_item_data_init(&item);
if (t_s_item_qs(NULL, tdb, &qs, &item)) {
lt_s_input_item_add(input, &item, 0);
input->status[__ITEMS] = false;
return(true);
}
return(false);
}
/* }}} */
/* set where {{{ **************************************************************/
int t_s_input_set_where(POS point, T_DB *tdb, T_INPUT *input) {
int Status;
WINDOW * win = newwin(13,70,10,2);
T_COMPANY company;
T_PERSON person;
T_QS qs;
wmove(GET_POS(point) + 1);
wrefresh(point.win);
Status = tt_input();
switch (Status) {
case __TT_ENTER:
INIT_QS(qs);
lt_c_company_data_init(&company);
lt_c_person_data_init(&person);
strcpy(company.pk.value, "1");
INIT_QS(qs);
lt_c_company_employees_qs_init(&qs, &company);
if (t_c_person_qs(win, tdb, &qs, &person)) {
strcpy(input->where.value, person.pk.value);
strcpy(input->where.name, person.surname.value);
}
Status = __TT_TAB;
mvwprintw(GET_POS(point) + 3, input->where.name);
werase(win);wrefresh(win);delwin(win);touchwin(point.win);
break;
}
wrefresh(point.win);
return(Status);
}
/* }}} */
/* set from {{{ ***************************************************************/
int t_s_input_set_from(POS point, T_DB *tdb, T_INPUT *input) {
int Status;
WINDOW * win = newwin(13,70,10,2);
T_COMPANY company;
T_QS qs;
wmove(GET_POS(point) + 1);
wrefresh(point.win);
Status = tt_input();
switch (Status) {
case __TT_ENTER:
INIT_QS(qs);
lt_c_company_data_init(&company);
if (t_c_company_qs(win, tdb, &qs, &company)) {
strcpy(input->from.value, company.pk.value);
strcpy(input->from.name, company.name.value);
}
mvwprintw(GET_POS(point) + 3, input->from.name);
werase(win);wrefresh(win);delwin(win);touchwin(point.win);
Status = __TT_TAB;
break;
}
wrefresh(point.win);
return(Status);
}
/* }}} */
/* qs {{{ NOT FUNCTIONAL ******************************************************/
int t_s_input_qs(WINDOW *win, T_DB *tdb, T_QS *qs, T_INPUT *input) {
bool End = false;
bool own_win = (win != NULL);
int Status;
T_COLS * cols = NULL;
if (!own_win) win = newwin(13,70,10,2);
lt_s_input_qs_init(input, &cols, qs);
while (!End) {
lt_s_input_data_init(input);
Status = tt_table_qs(win, tdb, qs, cols);
switch (Status) {
case __TT_ENTER:
if (strlen(input->pk.value) > 0) {
input->status[__PK] = true;
lt_s_input_items_get(tdb, input);
t_s_input_form(win, tdb, input);
// lt_s_input_data_get(tdb, input);
}
break;
case __TT_INS:
lt_s_input_data_init(input);
lt_s_input_new(tdb, input);
t_s_input_form(win, tdb, input);
// lt_s_input_data_clear(input);
break;
case __TT_ESC:
// lt_s_input_data_clear(input);
End = true;
break;
}
// if (!End) End = t_s_input_form(win, tdb, input);
}
werase(win);wrefresh(win);
if (!own_win) delwin(win);
return(End);
}
/* }}} */
Platon Group <platon@platon.org> http://platon.org/
|