Разработка программы на языке C/С++, страница 4

   datafile.readBlock((char *)base[i],(Q_LONG)9);

i++;

    }

    nelem=i;

    datafile.close();

    QString trnum;

    if ((header[0]->id==1)&&(header[1]->id==1))

    {

trnum.setNum(header[0]->trnum);

QChar lett1((ushort)header[0]->lett),lett2((ushort)header[1]->lett);

TrainNametextLabel->setText(trnum+lett1+lett2+" "+QString::fromLocal8Bit(resolvestat(header[0]->stcode))+" - "+QString::fromLocal8Bit(resolvestat(header[1]->stcode)));

    }

    redrawtable();

    fopened=TRUE;

    enableActions();

    return;

}

void MainForm::enableActions()

{

    editchnumAction->setEnabled(TRUE);

    editchrailwayAction->setEnabled(TRUE);

    editdeleterecordAction->setEnabled(TRUE);

    editinsertstatAction->setEnabled(TRUE);

    editrecordAction->setEnabled(TRUE);

    fileSaveAction->setEnabled(TRUE);

    fileSaveAsAction->setEnabled(TRUE);

    filechangetrainpropertiesAction->setEnabled(TRUE);

}

void MainForm::fileSave()

{

    if (filename.isEmpty()) fileSaveAs();

    datafile.setName(filename);

    if (!datafile.open(IO_ReadWrite|IO_Truncate))

    {

                                                                                                                                                                                                         QMessageBox::critical(

this, tr("Train Timetable Editor -- Error"),

QString( tr("An error occured while opening file for write" )),

"&OK", QString::null,QString::null, 1, 1 );

return;

    }

    int i;

    for (i=0; i<4; i++)

                                                                                                                                                                                                        datafile.writeBlock((char *)header[i],(Q_LONG)9);

    for (i=0; i<nelem; i++)

                                                                                                                                                                                                        datafile.writeBlock((char *)base[i],(Q_LONG)9);

    datafile.close();

    isChanged=FALSE;

    return;

}

void MainForm::fileSaveAs()

{

    QString fname = QFileDialog::getSaveFileName(

    QString::null, tr("Train timetables (*.trn)"), this,

    "file save as", tr("Train Timetable Editor -- File Save As" ));

    if ( ! fname.isEmpty() ) {

int ans = 0;

                                                                                                                                                                                                                                         if ( QFile::exists( fname ) )

    ans = QMessageBox::warning(

    this, tr("Train Timetable Editor -- Overwrite File"),

    QString( tr("Overwrite\n'%1'?") ).

    arg( filename ),

    tr("&Yes"), tr("&No"), QString::null, 1, 1 );

                                                                                                                                                                                                                                         if ( ans == 0 ) {

    filename = fname;

    fileSave();

    return;

}

    }

}

void MainForm::fileExit()

{

    // a.exit( 0 );

}

void MainForm::helpAbout()

{

    HelpAboutForm  *helpaboutForm = new HelpAboutForm( this, "help about", TRUE );

    helpaboutForm->exec();

    delete helpaboutForm;

}

void MainForm::destroy()

{

    if (fopened) deleteall();

    freeresolvedata();

    freerresolvedata();

}

void MainForm::deleteall()

{

   int i;

    for (i=0; i<4; i++)

                                                                                                                                                                                                                                  delete header[i];

    for (i=0; i<nelem; i++)

                                                                                                                                                                                                                                  delete base[i];