#include #include #include #include #include #include #include #include #include "ci0.h" #include "cilib.h" #include "ci0600a.h" #include "../ve/velib.h" //////////////////////////////////////// //// CLASSE TDef_risoatt_msk //// //////////////////////////////////////// //Classe TDef_risoatt_msk class TDef_risoatt_msk : public TAutomask { int _qtaore; protected: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); void riempi_sheet(); void nuova_riga(); void azzera_riga(TSheet_field& sheet); void azzera_tutto(TSheet_field& sheet); void registra(); public: void esegui() const; TDef_risoatt_msk(); }; //RIEMPI_SHEET: metodo che riempie lo sheet in base ai campi chiave //compilati sulla maschera void TDef_risoatt_msk::riempi_sheet() { //leggo dalla maschera i campi chiave di ricerca const TString4 anno = get(F_ANNO); const TString4 risoatt = get(F_RISOATT) == "T" ? "" : get(F_RISOATT); const TString4 mese = get(F_MESE); const TString4 tpora = get(F_TPORA); const TString80 codcosto = get(F_CODCOSTO); const TString80 codcms = get(F_CODCMS); const TString16 codfase = get(F_CODFASE); TString16 codice; switch(get(F_RISOATT)[0]) { case 'T': codice = get(F_CODICE); break; case 'R': codice = get(F_CODRIS); break; case 'A': codice = get(F_CODATT); break; default: break; } TString query; query << "USE RILORE\n" << "SELECT (BETWEEN(TIPORA,\"" << risoatt << "\",\"" << risoatt << "\"))&&" << "(BETWEEN(CODICE,\"" << codice << "\",\"" << codice << "\"))&&" << "(BETWEEN(ANNO,\"" << anno << "\",\"" << anno << "\"))&&" << "(BETWEEN(MESE,\"" << mese << "\",\"" << mese << "\"))&&" << "(BETWEEN(TPORA,\"" << tpora << "\",\"" << tpora << "\"))&&" << "(BETWEEN(CODCOSTO,\"" << codcosto << "\",\"" << codcosto << "\"))&&" << "(BETWEEN(CODCMS,\"" << codcms << "\",\"" << codcms << "\"))&&" << "(BETWEEN(CODFASE,\"" << codcms << "\",\"" << codfase << "\"))\n"; TString fromto = "TIPO=\"D\""; if(risoatt != 'T') { fromto << " TIPORA=\"" << risoatt << "\""; if(codice.full()) { fromto << " CODICE=\"" << codice << "\""; if(anno.full()) { fromto << " ANNO=\"" << anno << "\""; if(mese.full()) { fromto << " MESE=\"" << mese << "\""; if(tpora.full()) fromto << " TPORA=\"" << tpora << "\""; } } } } query << "FROM " << fromto << "\n" << "TO " << fromto; TISAM_recordset def(query); TSheet_field& sheet = sfield(F_SHEET); sheet.destroy(); //riempio lo sheet con i dati che soddisfano il filtro preparato prima for(bool ok = def.move_first(); ok; ok = def.move_next()) { TRilevamento_ore rilore(def.cursor()->curr()); TToken_string& riga = sheet.row(-1); riga.add(rilore.tipora(), sheet.cid2index(S_RISOATT)); switch(rilore.tipora()) { case 'R': riga.add(rilore.codice(), sheet.cid2index(S_CODRIS)); break; case 'A': riga.add(rilore.codice(), sheet.cid2index(S_CODATT)); break; default : break; } riga.add(rilore.anno(), sheet.cid2index(S_ANNO)); riga.add(rilore.mese(), sheet.cid2index(S_MESE)); riga.add(rilore.tpora(), sheet.cid2index(S_TPORA)); riga.add(rilore.codcosto(), sheet.cid2index(S_CODCOSTO)); riga.add(rilore.codcms(), sheet.cid2index(S_CODCMS)); riga.add(rilore.codfase(), sheet.cid2index(S_CODFASE)); riga.add(rilore.qtaore(), sheet.cid2index(S_QTAORE)); riga.add(rilore.costo().string(), sheet.cid2index(S_COSTO)); } sheet.force_update(); } //NUOVA_RIGA: metodo che aggiunge una riga allo sheet //tenendo conto dei campi chiave compilati in testata void TDef_risoatt_msk::nuova_riga() { TSheet_field& sheet = sfield(F_SHEET); sheet.row(-1); sheet.select(sheet.items() - 1); TMask& msk = sheet.sheet_mask(); //guardo il tipo risorsa / attrezzatura che sto ricercando const char risoatt = get(F_RISOATT)[0] == 'T' ? 'R' : get(F_RISOATT)[0]; TString4 tmp; tmp << risoatt; msk.set(S_RISOATT, tmp); msk.enable(S_RISOATT, get(F_RISOATT)[0] == 'T'); //leggo il codice corretto a seconda del tipo selezionato switch(get(F_RISOATT)[0]) { case 'T': msk.reset(S_CODRIS); msk.enable(S_CODRIS); msk.reset(S_CODATT); msk.enable(S_CODATT); break; case 'R': msk.set(S_CODRIS, get(F_CODRIS)); msk.enable(S_CODRIS); break; case 'A': msk.set(S_CODATT, get(F_CODATT)); msk.enable(S_CODATT); break; default: break; } msk.enable(S_ANNO, get(F_ANNO).empty()); msk.set(S_ANNO, get(F_ANNO)); msk.enable(S_MESE, get(F_MESE).empty()); msk.set(S_MESE, get(F_MESE)); msk.enable(S_TPORA, get(F_TPORA).empty()); msk.set(S_TPORA, get(F_TPORA)); msk.set(S_QTAORE, 0L); //lancio la maschera di riga da compilare if(msk.run() == K_ENTER) { const int qtaore = msk.get_int(S_QTAORE); const real prezzo = msk.get_real(S_COSTO); if(qtaore > 0) { const char tipo = msk.get(S_RISOATT)[0]; const TString& codice = tipo == 'R' ? msk.get(S_CODRIS) : msk.get(S_CODATT); const TString& mese = msk.get(S_MESE); const TString& tpora = msk.get(S_TPORA); const TString& codcosto = msk.get(S_CODCOSTO); const TString& codcms = msk.get(S_CODCMS); const TString& codfase = msk.get(S_CODFASE); TToken_string& riga = sheet.row(sheet.items() - 1); riga.add(tipo, sheet.cid2index(S_RISOATT)); switch(tipo) { case 'R': riga.add(codice, sheet.cid2index(S_CODRIS)); break; case 'A': riga.add(codice, sheet.cid2index(S_CODATT)); break; default : break; } riga.add(get_int(F_ANNO), sheet.cid2index(S_ANNO)); riga.add(mese, sheet.cid2index(S_MESE)); riga.add(tpora, sheet.cid2index(S_TPORA)); riga.add(codcosto, sheet.cid2index(S_CODCOSTO)); riga.add(codcms, sheet.cid2index(S_CODCMS)); riga.add(codfase, sheet.cid2index(S_CODFASE)); riga.add(qtaore, sheet.cid2index(S_QTAORE)); riga.add(prezzo.string(), sheet.cid2index(S_COSTO)); } else { sheet.destroy(sheet.items() - 1); sheet.force_update(); } } msk.enable_default(); sheet.check_row(sheet.items() - 1); sheet.force_update(); } //AZZERA_RIGA: metodo che azzera il valore unitario della riga selezionata //(N.B.: le righe con valore unitario nullo verranno eliminate in fase di registrazione) void TDef_risoatt_msk::azzera_riga(TSheet_field& sheet) { const int nriga = sheet.selected(); TToken_string& row = sheet.row(nriga); row.add(0, sheet.cid2index(S_QTAORE)); TMask& msk = sheet.sheet_mask(); _qtaore = msk.get_int(S_QTAORE); msk.set(S_QTAORE, 0L); } //AZZERA_TUTTO: metodo che azzera il valore unitario di tutte le righe visualizzate sullo sheet //(N.B.: le righe con valore unitario nullo verranno eliminate in fase di registrazione) void TDef_risoatt_msk::azzera_tutto(TSheet_field& sheet) { FOR_EACH_SHEET_ROW(sheet, r, row) { TToken_string& row = sheet.row(r); row.add(0, sheet.cid2index(S_QTAORE)); } } //REGISTRA: metodo che salva nella tabella di modulo le //righe dello sheet che hanno valore > 0, ed elimina quelle che hanno //vaoler pari a zero, e poi ricarica lo sheet void TDef_risoatt_msk::registra() { TLocalisamfile file(LF_CIRILORE); TSheet_field& sheet = sfield(F_SHEET); FOR_EACH_SHEET_ROW(sheet, r, row) { TToken_string& riga = *(TToken_string*)row; const char tipora = riga.get_char(sheet.cid2index(S_RISOATT)); const TString16 codice = tipora == 'R' ? riga.get(sheet.cid2index(S_CODRIS)) : riga.get(sheet.cid2index(S_CODATT)); const int anno = riga.get_int(sheet.cid2index(S_ANNO)); const TString4 mese = riga.get(sheet.cid2index(S_MESE)); const TString4 tpora = riga.get(sheet.cid2index(S_TPORA)); const TString80 codcosto = riga.get(sheet.cid2index(S_CODCOSTO)); const TString80 codcms = riga.get(sheet.cid2index(S_CODCMS)); const TString80 codfase = riga.get(sheet.cid2index(S_CODFASE)); const int qtaore = riga.get_int(sheet.cid2index(S_QTAORE)); const TString& tmp = riga.get(sheet.cid2index(S_COSTO)); const real costo(tmp); TRilevamento_ore rilroa('D', tipora, codice, anno, mese, tpora); if(!rilroa.empty() && qtaore == 0) rilroa.remove(file); else { TRilevamento_ore rilroa; rilroa.set_tipo('D'); rilroa.set_tipora(tipora); rilroa.set_codice(codice); rilroa.set_anno(anno); rilroa.set_mese(mese); rilroa.set_tpora(tpora); rilroa.set_codcosto(codcosto); rilroa.set_codcms(codcms); rilroa.set_codfase(codfase); rilroa.set_qtaore(qtaore); rilroa.set_costo(costo); int err = rilroa.rewrite_write(file); } } riempi_sheet(); } //ON_FIELD_EVENT: metodo che gestisce gli eventi sui vari campi della maschera bool TDef_risoatt_msk::on_field_event(TOperable_field& f, TField_event e, long jolly) { switch (f.dlg()) { case DLG_CERCA: if (e == fe_button) { riempi_sheet(); return false; } case DLG_NEWREC: if (e == fe_button) { nuova_riga(); return false; } case DLG_SAVEREC: if (e == fe_button) { registra(); return false; } break; case DLG_RESET: if(e == fe_button) { TSheet_field& sheet = sfield(F_SHEET); switch(jolly) { case 0: azzera_tutto(sheet); break; case 1: azzera_riga(sheet); break; default: break; } sheet.force_update(); return false; } break; case DLG_CANCEL: if(e == fe_button && jolly == 1) { TSheet_field& sheet = sfield(F_SHEET); TMask& msk = sheet.sheet_mask(); const int qtaore = msk.get_int(S_QTAORE); if(sheet.selected() == sheet.items() - 1) { sheet.destroy(sheet.items() - 1); sheet.force_update(); } else if(_qtaore > 0) { TToken_string& row = sheet.row(sheet.selected()); row.add(_qtaore, sheet.cid2index(S_QTAORE)); _qtaore = 0; } } break; case F_SHEET: if (e == se_query_add) { send_key(K_SPACE, DLG_NEWREC); return false; } default: break; } return true; } void TDef_risoatt_msk::esegui() const { } TDef_risoatt_msk::TDef_risoatt_msk() : TAutomask("ci0600a") { _qtaore = 0; } //////////////////////////////////////// //// CLASSE TDef_risoatt_app //// //////////////////////////////////////// //classe TDef_risoatt_app class TDef_risoatt_app : public TSkeleton_application { public: virtual void main_loop(); }; void TDef_risoatt_app::main_loop() { TDef_risoatt_msk msk; while (msk.run() != K_QUIT) msk.esegui(); } int ci0600(int argc, char *argv[]) { TDef_risoatt_app a; a.run (argc, argv, TR("Gestione Disponibilità Risorse / Attrezzature")); return TRUE; }