Spostate le funzioni Head_body record in libreria
git-svn-id: svn://10.65.10.50/trunk@4399 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
bfdc1b7989
commit
28750a5b09
452
mg/mg1100.cpp
452
mg/mg1100.cpp
@ -1,4 +1,4 @@
|
||||
#include <relapp.h>
|
||||
#include <relapp.h>
|
||||
#include <utility.h>
|
||||
#include <tabutil.h>
|
||||
#include <msksheet.h>
|
||||
@ -6,257 +6,31 @@
|
||||
#include <assoc.h>
|
||||
#include <checks.h>
|
||||
#include <defmask.h>
|
||||
#include <varrec.h>
|
||||
#include "..\mg\mglib01.h"
|
||||
#include "..\cg\cglib.h"
|
||||
#include "..\ve\velib03.h"
|
||||
#include "mg1100.h"
|
||||
|
||||
//**************************************
|
||||
// classe per il controllo dei record composti da una testata e N righe
|
||||
// è implementato come un TRectype che contiene anche un TRecord_array
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//********************
|
||||
//********************
|
||||
// maschera dell'applicazione "Gestione interattiva movimenti di magazzino"
|
||||
//
|
||||
class THead_body_record : public TAuto_variable_rectype {
|
||||
|
||||
TRecord_array _rows; // Array di TRectype per le righe
|
||||
bool _nuovo;
|
||||
int _file; // file principale (
|
||||
int _rowsfilenum; // file delle righe
|
||||
|
||||
protected:
|
||||
long get_next_key(char provv, int anno, const char* codnum) const;
|
||||
virtual TRectype & row(int index); // riga del corpo
|
||||
virtual void put_str(const char* fieldname, const char* val);
|
||||
long renum(long numdoc = 0);
|
||||
// @ cmember funzione per estrarre dal record della testata la chiave delle righe
|
||||
virtual void copy_linekey(const TRectype headrecord, TRectype linesrecord)=0;
|
||||
|
||||
public:
|
||||
//***********************
|
||||
// struttura
|
||||
const TAuto_variable_rectype& head() const { return *this; } // Ritorna la testata del documento
|
||||
TAuto_variable_rectype& head() { return *this; } // Ritorna la testata del documento
|
||||
|
||||
int rows() const { return _rows.rows(); }
|
||||
|
||||
const TRectype& operator[](int index) const
|
||||
{ return (const TRectype&)((THead_body_record *)this)->row(index); }
|
||||
TRectype& operator[](int index)
|
||||
{ return (TRectype&)row(index); }
|
||||
|
||||
TRectype & insert_row(int row, const char *tipo = NULL);
|
||||
TRectype & new_row(const char *tipo = NULL);
|
||||
bool destroy_row(int n, bool pack = FALSE) { return _rows.destroy_row(n, pack); }
|
||||
void destroy_rows() { _rows.destroy_rows(); }
|
||||
|
||||
//***********************
|
||||
// record e I/O
|
||||
void dirty_fields();
|
||||
|
||||
virtual TRectype & operator =(const TRectype & r);
|
||||
virtual TRectype & operator =(const char * r);
|
||||
virtual void zero(const char * fieldname);
|
||||
virtual void zero(char c = '\0');
|
||||
|
||||
void reset_fields(TAuto_variable_rectype & rec) { rec.remove_field(); }
|
||||
void set_fields(TAuto_variable_rectype & rec);
|
||||
|
||||
int read(const TRectype& rec);
|
||||
|
||||
int write(bool re = FALSE) const;
|
||||
int rewrite() const { return write(TRUE); }
|
||||
int remove() const;
|
||||
|
||||
//**************************
|
||||
THead_body_record(int hfn, int rfn,const char *numfield);
|
||||
THead_body_record(const TBaseisamfile* i,int rfn,const char *numfield);
|
||||
THead_body_record(const TRectype & r,int rfn,const char *numfield);
|
||||
THead_body_record(const TVariable_rectype & r,int rfn,const char *numfield);
|
||||
virtual ~THead_body_record();
|
||||
};
|
||||
|
||||
THead_body_record::THead_body_record(int hfn, int rfn,const char *numfield):
|
||||
_rows(rfn,numfield), // inizializza il record array delle righe
|
||||
TAuto_variable_rectype(hfn)
|
||||
{
|
||||
_file=hfn; // file principale
|
||||
_rowsfilenum=rfn; // file delle righe
|
||||
}
|
||||
|
||||
THead_body_record::THead_body_record(const TBaseisamfile* i,int rfn,const char *numfield):
|
||||
TAuto_variable_rectype(i)
|
||||
{
|
||||
}
|
||||
THead_body_record::THead_body_record(const TRectype & r,int rfn,const char *numfield):
|
||||
TAuto_variable_rectype(r)
|
||||
{
|
||||
}
|
||||
THead_body_record::THead_body_record(const THead_body_record& r):
|
||||
TAuto_variable_rectype(r)
|
||||
{
|
||||
// copia..
|
||||
}
|
||||
|
||||
int THead_body_record::read(const TRectype& rec)
|
||||
{
|
||||
head() = rec;
|
||||
TRectype line_key(_rows.key());
|
||||
|
||||
copy_linekey(head(),line_key);
|
||||
|
||||
TLocalisamfile afile(_file);
|
||||
int err = TRectype::read(afile);
|
||||
if (err == NOERR)
|
||||
{
|
||||
_nuovo = FALSE;
|
||||
_rows.read(line_key); //ok
|
||||
}
|
||||
else
|
||||
{
|
||||
// nuovo oggetto: resetta tutto
|
||||
_nuovo = TRUE;
|
||||
head() = rec;
|
||||
destroy_rows();
|
||||
_rows.set_key(&line_key); // ok
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
int THead_body_record::write(bool re) const
|
||||
{
|
||||
const bool nuovo = _nuovo; // E' nuovo di zecca!
|
||||
if (nuovo && re) // quindi ...
|
||||
re = FALSE; // ... non fare la rewrite
|
||||
|
||||
TLocalisamfile afile(_file);
|
||||
int err = NOERR;
|
||||
if (re)
|
||||
{
|
||||
err = _rows.write(re);
|
||||
if (err == NOERR)
|
||||
{
|
||||
err = TRectype::rewrite(afile);
|
||||
if (err != NOERR)
|
||||
err = TRectype::write(afile);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nuovo)
|
||||
{
|
||||
THead_body_record& myself = *(THead_body_record*)this;
|
||||
//if (numero() <= 0)
|
||||
// myself.renum();
|
||||
do
|
||||
{
|
||||
err = TRectype::write(afile);
|
||||
if (err == _isreinsert)
|
||||
myself.renum();
|
||||
} while (err == _isreinsert);
|
||||
myself._nuovo = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = TRectype::write(afile);
|
||||
if (err != NOERR)
|
||||
err = TRectype::rewrite(afile);
|
||||
}
|
||||
if (err == NOERR)
|
||||
err = _rows.write(re);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
int THead_body_record::remove() const
|
||||
{
|
||||
TLocalisamfile afile(_file);
|
||||
int err = _rows.remove();
|
||||
if (err == NOERR)
|
||||
err = TRectype::remove(afile);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class TMov_mag : public THead_body_record {
|
||||
TString16 _nextcod;
|
||||
|
||||
public:
|
||||
// IO ad alto livello
|
||||
const char *get_next_key() ;
|
||||
int read(int numreg);
|
||||
int remove();
|
||||
// gestione saldi
|
||||
int save_line_minus();
|
||||
int save_line_plus();
|
||||
int update_balances();
|
||||
// costruttori e distruttori
|
||||
TMov_mag();
|
||||
virtual ~TMov_mag() {};
|
||||
};
|
||||
|
||||
TMov_mag::TMov_mag() :
|
||||
TRelation(LF_MOVMAG)
|
||||
{
|
||||
}
|
||||
|
||||
TMov_mag::remove()
|
||||
{
|
||||
/*
|
||||
// controlla le righe da togliere
|
||||
if ((res=((TSheet_field &)_msk->field(F_RIGHE)).record()->remove())==NOERR ) {
|
||||
// effettua la variazione dei saldi
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *TMov_mag::get_next_key()
|
||||
{
|
||||
TLocalisamfile f(LF_MOVMAG);
|
||||
f.last();
|
||||
int a=atoi(f.get("NUMREG"))+1;
|
||||
return _nextcod.format("%d|%d",F_NUMREG,a);
|
||||
}
|
||||
|
||||
//*******
|
||||
// gestione delle variazione dei saldi
|
||||
//
|
||||
//
|
||||
int TMov_mag::save_line_plus()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TMov_mag::save_line_minus()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TMov_mag::update_balances()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//*****
|
||||
//*****
|
||||
// maschera dei movimenti di magazzino
|
||||
class TMask_movmag: public TMask {
|
||||
TMov_mag * mov_mag;
|
||||
TMag_livelli * livelli_giac; // oggetto gestione livelli di giacenza
|
||||
static bool handle_sheetrighe(TMask_field &fld, KEY k); // handler delle righe
|
||||
TString price_codart;
|
||||
real price_quant;
|
||||
bool price_proposed;
|
||||
real proposed_price(TString codart, real quant);
|
||||
static bool handle_righeprezzo(TMask_field &f, KEY k); // notify delle righe
|
||||
static bool handle_codcaus(TMask_field &fld, KEY k); // handler delle righe
|
||||
static bool handle_numreg(TMask_field &, KEY); // handler del campo anno delle giacenze
|
||||
static bool handle_datacomp(TMask_field &, KEY); // handler del numero di registrazione
|
||||
public:
|
||||
TMask_movmag(TMag_livelli *l_m,TMov_mag * m_m);
|
||||
virtual ~TMask_movmag();
|
||||
@ -267,18 +41,23 @@ static void sheetrighe_get(TSheet_field &fld_righe, int item);
|
||||
|
||||
// costruttore della maschera anagrafica di magazzino
|
||||
//TMask_movmag::TMask_movmag() :
|
||||
TMask_movmag::TMask_movmag(TMag_livelli *l_m,TMov_mag * m_m) : TMask("mg1100")
|
||||
TMask_movmag::TMask_movmag(TMag_livelli *l_m,TMov_mag * m_m)
|
||||
: TMask("mg1100")
|
||||
{
|
||||
|
||||
// oggetti dell'applciazione
|
||||
// oggetti dell'applicazione
|
||||
livelli_giac= l_m;
|
||||
mov_mag = m_m;
|
||||
|
||||
set_handler(F_NUMREG, handle_numreg);
|
||||
// setta handler e notify
|
||||
set_handler(F_DATACOMP, handle_datacomp);
|
||||
set_handler(F_CODCAUS, handle_codcaus);
|
||||
set_handler(F_RIGHE, handle_sheetrighe);
|
||||
((TSheet_field &)field(F_RIGHE)).sheet_mask().field(F_PREZZO).set_handler(handle_righeprezzo);
|
||||
((TSheet_field &)field(F_RIGHE)).sheet_mask().field(F_CODART).set_handler(handle_righeprezzo);
|
||||
((TSheet_field &)field(F_RIGHE)).sheet_mask().field(F_QUANT).set_handler(handle_righeprezzo);
|
||||
((TSheet_field &)field(F_RIGHE)).set_userget(sheetrighe_get);
|
||||
((TSheet_field &)field(F_RIGHE)).set_userput(sheetrighe_put);
|
||||
((TSheet_field &)field(F_RIGHE)).set_lines_record(*m_m->rows_record());
|
||||
|
||||
// setta i campi della maschera
|
||||
// per la pagina giacenze
|
||||
@ -321,11 +100,9 @@ TMask_movmag::TMask_movmag(TMag_livelli *l_m,TMov_mag * m_m) : TMask("mg1100")
|
||||
|
||||
TMask_movmag::~TMask_movmag()
|
||||
{
|
||||
delete livelli_giac;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// item varies from 1 to items()
|
||||
void TMask_movmag::sheetrighe_get(TSheet_field &fld_righe, int item)
|
||||
{
|
||||
@ -360,77 +137,104 @@ void TMask_movmag::sheetrighe_put(TSheet_field &fld_righe, int item)
|
||||
|
||||
|
||||
|
||||
bool TMask_movmag::handle_sheetrighe(TMask_field &fld, KEY k)
|
||||
bool TMask_movmag::handle_righeprezzo(TMask_field &f, KEY k)
|
||||
{
|
||||
TSheet_field &f= (TSheet_field &)fld; // typecast del campo al suo sheet corrispondente
|
||||
TMask_movmag &m= (TMask_movmag &)fld.mask();
|
||||
int line;
|
||||
if (k==K_SPACE)
|
||||
{
|
||||
// entrata nella modifica
|
||||
m.mov_mag->save_line_minus(line);
|
||||
}
|
||||
if (k==K_TAB && fld.focusdirty())
|
||||
{
|
||||
// uscita dalla modifica
|
||||
m.mov_mag->save_line_plus(line);
|
||||
}
|
||||
if (k==K_ENTER)
|
||||
{
|
||||
m.mov_mag->update_balances();
|
||||
}
|
||||
TSheet_field &sh=(TSheet_field &)(*f.mask().get_sheet());
|
||||
TMask_movmag &m=(TMask_movmag &)sh.mask();
|
||||
if (k==K_TAB && f.focusdirty())
|
||||
{
|
||||
m.price_proposed=FALSE;
|
||||
// in caso di nuova linea o prezzo nullo, propone il prezzo in base alla causale
|
||||
if (!f.mask().get(F_QUANT).blank() &&
|
||||
!f.mask().get(F_CODART).blank() &&
|
||||
f.mask().get(F_PREZZO).blank() &&
|
||||
(m.price_proposed==FALSE))
|
||||
{
|
||||
m.price_proposed=TRUE;
|
||||
real prz=m.proposed_price(f.mask().get(F_CODART),
|
||||
f.mask().get_real(F_QUANT));
|
||||
f.mask().set(F_PREZZO,prz);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
real TMask_movmag::proposed_price(TString codart,
|
||||
real quant)
|
||||
{
|
||||
real rv("0");
|
||||
TCausale_magazzino cau(get(F_CODCAUS));
|
||||
TLocalisamfile anamag(LF_ANAMAG);
|
||||
anamag.put("CODART",codart);
|
||||
anamag.read();
|
||||
switch (cau.get_tipoprz()) {
|
||||
// prezzo
|
||||
case 'P': {
|
||||
TLocalisamfile umart(LF_UMART);
|
||||
TConfig cfgditta(CONFIG_DITTA);
|
||||
TCondizione_vendita cv(&cfgditta,&anamag,&umart);
|
||||
|
||||
cv.put_listino(get(F_CODCONDV),get(F_CATVEN),get(F_TIPOCF),get(F_CODCF));
|
||||
cv.ricerca(codart,quant);
|
||||
rv=cv.get_prezzo();
|
||||
}
|
||||
break;
|
||||
// costo
|
||||
case 'C': {
|
||||
rv=anamag.get_real("ULTCOS1");
|
||||
}
|
||||
break;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool TMask_movmag::handle_codcaus(TMask_field &fld, KEY k)
|
||||
{
|
||||
if (k==K_TAB)
|
||||
{
|
||||
TMask_movmag &m= (TMask_movmag &)fld.mask();
|
||||
m.mov_mag->save_line_minus();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool TMask_movmag::handle_numreg(TMask_field &fld, KEY k)
|
||||
bool TMask_movmag::handle_datacomp(TMask_field &fld, KEY k)
|
||||
{
|
||||
if (k==K_ENTER)
|
||||
{
|
||||
}
|
||||
if (k == K_TAB && fld.focusdirty())
|
||||
{
|
||||
|
||||
int codes=((TMask_movmag &)fld.mask()).mov_mag->codice_esercizio(TDate(fld.get()));
|
||||
if (codes>0)
|
||||
fld.mask().field(F_ANNOES).set(codes);
|
||||
else
|
||||
{
|
||||
fld.error_box("La data indicata non appartiene a nessuno degli esercizi contabili inseriti ") ;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
// handle
|
||||
bool TMask_movmag::handle_rmov_um(TMask_field &fld, KEY k)
|
||||
{
|
||||
if (k==K_ENTER)
|
||||
{
|
||||
TTable cau("CAU");
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class TApp_movmag: public TRelation_application {
|
||||
TMask_movmag *_msk; // maschera principale
|
||||
TMov_mag * _mov_mag; // relazione principale di un solo file (movimenti di magazzino)
|
||||
TMag_livelli * _livelli_giac;// oggetto handler per i livelli di le giacenze
|
||||
int _lastnumreg;
|
||||
TMag_livelli * _livelli_giac;// oggetto handler per i livelli di giacenza
|
||||
TRelation * _rel; // relazione contenente il file movimenti
|
||||
TLocalisamfile * _rmovmag; // file aperto per utilizzarne il record
|
||||
virtual bool user_create();
|
||||
virtual bool user_destroy();
|
||||
virtual TMask *get_mask(int) { return _msk; }
|
||||
virtual bool changing_mask(int) { return FALSE; }
|
||||
virtual TRelation *get_relation() const { return _mov_mag; }
|
||||
virtual void init_insert_mode(TMask &);
|
||||
virtual const char *get_next_key() ;
|
||||
virtual int read(TMask& m);
|
||||
virtual bool remove();
|
||||
virtual int write(const TMask& m);
|
||||
virtual int rewrite(const TMask& m);
|
||||
virtual TRelation *get_relation() const { return _rel; }
|
||||
virtual const char *get_next_key();
|
||||
// virtual int read(TMask& m);
|
||||
// virtual bool remove();
|
||||
// virtual int write(const TMask& m);
|
||||
// virtual int rewrite(const TMask& m);
|
||||
|
||||
TString16 _nextcod;
|
||||
public:
|
||||
TApp_movmag() {};
|
||||
virtual ~TApp_movmag() {};
|
||||
@ -441,18 +245,26 @@ inline TApp_movmag& app() { return (TApp_movmag&) main_app(); }
|
||||
|
||||
bool TApp_movmag::user_create()
|
||||
{
|
||||
// apre la maschera e dispone gli sheet
|
||||
|
||||
_rmovmag = new TLocalisamfile(LF_RMOVMAG);
|
||||
TMov_mag * m_m= new TMov_mag; // record del movimento di magazzino
|
||||
|
||||
// gestione giacenza a livelli
|
||||
_livelli_giac= new TMag_livelli("FCG");
|
||||
_mov_mag= new TMov_mag;
|
||||
_msk= new TMask_movmag(_livelli_giac,_mov_mag);
|
||||
// maschera specifica con gli handler dei movimenti
|
||||
_msk= new TMask_movmag(_livelli_giac,m_m);
|
||||
// relazione con un solo file (LF_MOVMAG) ma col record Head_Body
|
||||
_rel= new TRelation(LF_MOVMAG);
|
||||
_rel->lfile().set_curr(m_m);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool TApp_movmag::user_destroy()
|
||||
{
|
||||
delete _rmovmag;
|
||||
delete _rel;
|
||||
delete _msk;
|
||||
delete _mov_mag;
|
||||
delete _livelli_giac;
|
||||
|
||||
return TRUE;
|
||||
@ -461,40 +273,7 @@ bool TApp_movmag::user_destroy()
|
||||
// autonumerazione
|
||||
const char *TApp_movmag::get_next_key()
|
||||
{
|
||||
return _mov_mag->get_next_key();
|
||||
}
|
||||
|
||||
// rimozione
|
||||
bool TApp_movmag::remove()
|
||||
{
|
||||
int res;
|
||||
_mov_mag->remove();
|
||||
return (res && TRelation_application::remove());
|
||||
}
|
||||
|
||||
int TApp_movmag::read(TMask& m)
|
||||
{
|
||||
int err=TRelation_application::read(m);
|
||||
return err;
|
||||
}
|
||||
|
||||
int TApp_movmag::write(const TMask& m)
|
||||
{
|
||||
int err= TRelation_application::write(m);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int TApp_movmag::rewrite(const TMask& m)
|
||||
{
|
||||
|
||||
int err= TRelation_application::rewrite(m);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void TApp_movmag::init_insert_mode(TMask &m)
|
||||
{
|
||||
return _nextcod.format("%d|%s",F_NUMREG,((TMov_mag &)_rel->curr()).get_next_key());
|
||||
}
|
||||
|
||||
int mg1100(int argc, char* argv[])
|
||||
@ -507,4 +286,3 @@ int mg1100(int argc, char* argv[])
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user