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

}

void MainForm::redrawtable(){

    int i,j;

    for (i=0; i<trainTimeTable->numRows(); i++)

for (j=0; j<trainTimeTable->numCols(); j++)

    trainTimeTable->clearCell(i,j);

     trainTimeTable->setNumRows(nelem+1);

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

switch(base[i]->id){

case 0:

    {

trainTimeTable->setText(i,0,QString::fromLocal8Bit(resolvestat(base[i]->stcode)));

QString dist;

dist.setNum(base[i]->stcode);

trainTimeTable->setText(i,2,dist);

if (base[i]->dist>=0)

{

    dist.setNum(base[i]->dist);

    trainTimeTable->setText(i,1,dist);

}

if (base[i]->arr_h!=25)

dist.sprintf("%02d:%02d",base[i]->arr_h,base[i]->arr_m);

else

    dist.sprintf("-----");

trainTimeTable->setText(i,3,dist);

if (base[i]->dec_h!=25)

    dist.sprintf("%02d:%02d",base[i]->dec_h,base[i]->dec_m);

else dist.sprintf("-----");

trainTimeTable->setText(i,5,dist);

int stop=getstop(i);

if (stop!=0)

    dist.sprintf("%02d",stop);

else dist.sprintf("--");

trainTimeTable->setText(i,4,dist);

    }

    break;

    case 1: {}

    break;

    case 2: {

chnum=(datastr10*)base[i];

QChar lett1((ushort)chnum->lett1),lett2((ushort)chnum->lett2);

QString trnum;

trnum.setNum(chnum->trnum);

trainTimeTable->setText(i,0,QString(tr("Train No "))+trnum+lett1+lett2);

    }

    break;

case 3:

chrail=(datastr11*)base[i];

trainTimeTable->setText(i,0,QString::fromLocal8Bit(resolveroad(chrail->dorcode))+' '+tr("railway"));

break;

    }

default:

    QString debugln;

    debugln.setNum(base[i]->id);

    trainTimeTable->setText(i,1,debugln);

    trainTimeTable->setText(i,0,QString(tr("Unrecognized data")));

    trainTimeTable->setText(i,1,debugln);

    break;

}

    }

}

int MainForm::getstop(int nrec){

    int arr,dec;

    if ((base[nrec]->dec_h==25)||(base[nrec]->arr_h==25)) return 0;

    if (base[nrec]->dec_h<base[nrec]->arr_h) dec=(base[nrec]->dec_h+24)*60+base[nrec]->dec_m;

    else

                                                                                                                                                                                                              dec=(int)base[nrec]->dec_h*60+(int)base[nrec]->dec_m;

    arr=(int)base[nrec]->arr_h*60+(int)base[nrec]->arr_m;

    return (dec-arr);

}

void MainForm::editchrailway()

{

    chroadForm  *chrdForm = new chroadForm( this, "chrform", TRUE );

    if (chrdForm->exec())

    {

int i;

if (trainTimeTable->currentRow()<nelem)

{

    for (i=nelem;i>trainTimeTable->currentRow(); i--)

base[i]=base[i-1];

    i=trainTimeTable->currentRow();

}

else i=nelem;

base[i]=new datastr00;

chrail=(datastr11*)base[i];

chrail->id=3;

QString railw=chrdForm->chrcomboBox->currentText();

chrail->dorcode=resolveroadcode(railw.local8Bit());

nelem++;

redrawtable();

 }

    delete chrdForm;

}

void MainForm::editinsertstation()

{   

    EditStationForm  *editstatForm = new EditStationForm( this, "editstat", TRUE );

    editstatForm->setCaption(tr("Insert New Station Record"));

    if (editstatForm->exec())

    {

int i;

if (trainTimeTable->currentRow()<nelem)

{

    for (i=nelem;i>trainTimeTable->currentRow(); i--)

base[i]=base[i-1];

    i=trainTimeTable->currentRow();

}

else i=nelem;

base[i]=new datastr00;

QTime tm;

base[i]->id=0;

if (!(editstatForm->IgnoreArrTimecheckBox->isChecked()))

{

    tm=editstatForm->ArrtimeEdit->time();

    base[i]->arr_h=tm.hour();

    base[i]->arr_m=tm.minute();

}

else base[i]->arr_h=25;

                                                                                                                                                                                                                                         if (!(editstatForm->IgnoreDepTimecheckBox->isChecked()))

{

    tm=editstatForm->DeptimeEdit->time();

    base[i]->dec_h=tm.hour();