Corretta la gestione degli errori e visualizzazione del MsgBox finale.

Corretta gestione dell'errore di disco pieno.


git-svn-id: svn://10.65.10.50/trunk@1621 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
angelo 1995-07-20 09:06:33 +00:00
parent 14ac0c0356
commit 4db02131c2

View File

@ -64,7 +64,7 @@ HIDDEN int CGetField(const char *fieldname,RecDes* recd,RecType recin,long* d)
class TIsam_date_converter : public TApplication class TIsam_date_converter : public TApplication
{ {
TFilename _logfile; TFilename _logfile;
bool _errors_found;
protected: protected:
virtual bool create () ; virtual bool create () ;
virtual bool destroy(); virtual bool destroy();
@ -83,9 +83,6 @@ bool TIsam_date_converter::create() // initvar e arrmask
{ {
TApplication::create(); TApplication::create();
_logfile.temp("convlog");
FILE * fp = fopen((const char*)_logfile,"w");
fclose(fp);
update(); update();
return FALSE; return FALSE;
} }
@ -99,6 +96,11 @@ bool TIsam_date_converter::destroy() // releasev e arrmask
void TIsam_date_converter::update() void TIsam_date_converter::update()
{ {
_logfile.temp("cnvlog");
FILE * fp = fopen(_logfile,"w");
fclose(fp);
_errors_found = FALSE;
long firm = get_firm(); long firm = get_firm();
TString pref; TString pref;
if (firm == 0) pref = prefix().name(); if (firm == 0) pref = prefix().name();
@ -132,9 +134,13 @@ void TIsam_date_converter::update()
else prefix().set(pref); else prefix().set(pref);
set_autoload_new_files(TRUE); set_autoload_new_files(TRUE);
end_wait(); end_wait();
if (_errors_found)
{
TString80 s; TString80 s;
s << "Esaminare il file di log " << _logfile << " in caso di errori." ; s << "Esaminare il file di log " << _logfile << " per il riepilogo degli errori." ;
message_box(s); message_box(s);
} else
::remove(_logfile);
} }
void TIsam_date_converter::update_dir() void TIsam_date_converter::update_dir()
@ -204,13 +210,16 @@ int TIsam_date_converter::convert_file(int logicnum)
TDir dir; TDir dir;
TTrec r; TTrec r;
int err = NOERR; int err = NOERR;
bool restore_original=FALSE; bool restore_original=FALSE, retry_file=FALSE;
r.get(logicnum); r.get(logicnum);
RecDes *rd=r.rec(); RecDes *rd=r.rec();
TRecnotype i; TRecnotype i;
const int nflds = r.fields(); const int nflds = r.fields();
const int nkeys = r.keys(); const int nkeys = r.keys();
do // External loop creation file in case of a disk full error.
{ // Appending records can easily reduce disk space!
dir.get(logicnum); dir.get(logicnum);
if (dir.len() == 0 || nflds < 1 || nkeys < 1) return 0; if (dir.len() == 0 || nflds < 1 || nkeys < 1) return 0;
const char * fp = dir.name(); const char * fp = dir.name();
@ -218,16 +227,34 @@ int TIsam_date_converter::convert_file(int logicnum)
const TRecnotype nitems = dir.eod(); const TRecnotype nitems = dir.eod();
const TRecnotype neox = dir.eox(); const TRecnotype neox = dir.eox();
TFile f(dir.len()); TFile f(dir.len());
old.ext("dta"); old.ext("dta");
if (fexist(old)) if (fexist(old))
{ {
f.open(old); f.open(old);
{ {
TSystemisamfile newfile(logicnum); TSystemisamfile newfile(logicnum);
bool retry = FALSE;
if (newfile.build(10) != NOERR) do // Internal loop creation file in case of a disk full error.
{ // The program asks to continue (suspending momentanely execution),
newfile.build(10); // permitting the user to switch to a DOS session and free space on disk.
switch (newfile.status())
{
case NOERR:
retry=FALSE;
break;
case _isfilefull:
if (!yesno_box("Il disco e' pieno. Non riesco a creare il file %s. Riprovo?", fp))
{
message_box("Liberare spazio sull'unita' interessata e rieseguire la conversione.");
stop_run();
}
retry=TRUE;
break;
default:
fatal_box("Non riesco a creare il file %s : errore n. %d", fp, newfile.status()); fatal_box("Non riesco a creare il file %s : errore n. %d", fp, newfile.status());
break;
}
} while (retry);
} }
TString s(80); TString s(80);
@ -246,9 +273,11 @@ int TIsam_date_converter::convert_file(int logicnum)
tslog.add(rd->Fd[j].Name); tslog.add(rd->Fd[j].Name);
const int tslog_items = tslog.items(); const int tslog_items = tslog.items();
const int ts_items = ts.items(); const int ts_items = ts.items();
for (i = 1; newfile.good() && i <= dir.eod(); i++) for (i = 1; newfile.good() && i <= dir.eod(); i++)
{ {
f.read(newfile.curr().string(),i); f.read(newfile.curr().string(),i);
newfile.curr().setdirty();
if (newfile.curr().string()[0] == '\0') if (newfile.curr().string()[0] == '\0')
{ {
newfile.curr().recall(); newfile.curr().recall();
@ -283,11 +312,27 @@ int TIsam_date_converter::convert_file(int logicnum)
::remove(old); ::remove(old);
old.ext("ndx"); old.ext("ndx");
::remove(old); ::remove(old);
restore_original=FALSE;
retry_file=FALSE;
}
else
{
_errors_found=TRUE;
if (err == _isfilefull)
{
if (!yesno_box("Il disco e' pieno. Non riesco a scrivere sul file %s. Riprovo?", fp))
{
message_box("Liberare spazio sull'unita' interessata e rieseguire la conversione.");
retry_file=FALSE;
} else
retry_file=TRUE;
} }
else else
{ {
error_box("Errore n.ro %d nella conversione dell' archivio %s:\n %ld records non convertiti.", error_box("Errore n.ro %d nella conversione dell' archivio %s:\n %ld records non convertiti.",
err, fp, nitems - i + 2); err, fp, nitems - i + 2);
retry_file=FALSE;
}
restore_original=TRUE; restore_original=TRUE;
} }
} }
@ -311,7 +356,27 @@ int TIsam_date_converter::convert_file(int logicnum)
if (!fexist(s)) // Crea il file solo se non esiste il .DBF if (!fexist(s)) // Crea il file solo se non esiste il .DBF
{ {
TSystemisamfile f(logicnum); TSystemisamfile f(logicnum);
f.build(10L); bool retry = FALSE;
do
{
f.build(10);
switch (f.status())
{
case NOERR:
break;
case _isfilefull:
if (!yesno_box("Il disco e' pieno. Non riesco a creare il file %s. Riprovo?", fp))
{
message_box("Liberare spazio sull'unita' interessata e rieseguire la conversione.");
stop_run();
}
retry=TRUE;
break;
default:
fatal_box("Non riesco a creare il file %s : errore n. %d", fp, f.status());
break;
}
} while (retry);
} }
} }
} }
@ -335,16 +400,21 @@ int TIsam_date_converter::convert_file(int logicnum)
dir.eox()=neox; dir.eox()=neox;
dir.put(logicnum,_nordir,_sysdirop); dir.put(logicnum,_nordir,_sysdirop);
FILE *fp = fopen((const char*)_logfile,"a"); if (!retry_file)
{
FILE *f = fopen((const char*)_logfile,"a");
old.ext("dta"); old.ext("dta");
fprintf(fp,"File: %s (%d). %ld records non convertiti. Errore %d.\n", fprintf(f,"File: %s (%d). %ld records non convertiti. Errore %d.\n",
(const char*) old, logicnum, nitems-i+2, err); (const char*) old, logicnum, nitems-i+2, err);
fclose(fp); fclose(f);
} }
}
} while (retry_file && (err == _isfilefull));
if (err == _isfilefull) // This happens only when the user decides to answer NO.
stop_run();
return err; return err;
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
TIsam_date_converter a; TIsam_date_converter a;