Ejemplo n.º 1
0
AVPicture *FFwrapper::Scaler::scale(AVPicture *input, const AVCodecContext *src_ctx) {
    size_t picture_size;

    if (!out_buf) {
        picture_size = avpicture_get_size(pixfmt, width, height);
        out_buf = (uint8_t *)av_malloc(picture_size);
        if (!out_buf) {
            throw AllocationError("frame buffer");
        }

        ctx = sws_getContext(
            src_ctx->width, src_ctx->height, src_ctx->pix_fmt,
            width, height, pixfmt,
            SWS_FAST_BILINEAR | SWS_PRINT_INFO, 0, 0, 0
        );
        if (!ctx) {
            throw AllocationError("swscale context");
        }

        avpicture_fill(&out, out_buf, pixfmt, width, height);
    }

    sws_scale(ctx, input->data, input->linesize, 0, src_ctx->height, out.data, out.linesize);

    return &out;
}
Ejemplo n.º 2
0
Vector *createVector( int size )
{
	Vector *temp;

	if( ( temp = (Vector*)malloc( sizeof( Vector ) ) ) == NULL )
		AllocationError();

	if( ( temp->v = (double*)malloc( sizeof( double ) * size ) ) == NULL )
		AllocationError();

	temp->size = size;

	return temp;
}
Ejemplo n.º 3
0
void* BlinkM::Memory::allocate(size_t size) {
  try {
    void* p = ::operator new(size);
  }
  catch (std::exception& exception) {
    throw AllocationError();
  }
}
Ejemplo n.º 4
0
Matrix *createMatrix( int width, int height )
{
	Matrix *temp;

	if( ( temp = (Matrix*)malloc( sizeof( Matrix ) ) ) == NULL )
		AllocationError();

	if( ( temp->a = (double**)malloc( sizeof(double*) * height ) ) == NULL )
		AllocationError();

	for ( int i = 0; i < height; i++ ) {
		if( ( temp->a[i] = (double*)malloc( sizeof(double) * width ) ) == NULL )
			AllocationError();
	}

	temp->width = width;
	temp->height = height;

	return temp;
}
Ejemplo n.º 5
0
FFwrapper::Decoder::Decoder(enum CodecID id) {

    codec = avcodec_find_decoder(id);
    if (!codec) {
        throw NoCodecError("could not find codec");
    }

    ctx = avcodec_alloc_context( );
    if (!ctx) {
        throw AllocationError("allocating codec context");
    }

    frame = avcodec_alloc_frame( );
    if (!frame) {
        throw AllocationError("allocating frame");
    }

    if (avcodec_open(ctx, codec) < 0) {
        throw CodecError("failed to open codec");
    }
}
Ejemplo n.º 6
0
FFwrapper::AudioResampler::AudioResampler(int in_ch, int in_rate, enum SampleFormat in_fmt, int out_ch, int out_rate) 
    : buf(NULL), buf_size(0), ctx(NULL) {

    ctx = av_audio_resample_init(
        out_ch, in_ch, out_rate, in_rate,       /* in, out parameters */
        SAMPLE_FMT_S16, in_fmt,         /* output, input formats */
        16, 10, 0, 0.8                          /* filter length, log2 phase count, linear?, cutoff */
    );

    if (!ctx) {
        throw AllocationError("audio resampling context");
    }
}
Ejemplo n.º 7
0
void Pokedex::GetAllPokemonsByLevel(int trainerID, int ** pokemons,
		int *numOfPokemon) {
	if (trainerID == 0||!pokemons ||!numOfPokemon) {
		throw InvalidInput();
	}
	if (trainerID < 0) {
		*numOfPokemon = mainLevelTree.getSize();
		int* pokemonArray = (int*) malloc(sizeof(int) * *numOfPokemon);
		if (pokemonArray == NULL) {
			throw AllocationError();
		}
		Pokemon* levelArray = mainLevelTree.inOrder();
		for (int i = 0; i < *numOfPokemon; i++) {
			pokemonArray[i] = levelArray[i].getID();
		}
		delete[] levelArray;
		*pokemons = pokemonArray;
		return;
	}

	Iterator<Trainer> trainer = trainers.find(TrainerCompare(trainerID));
	if (trainer == trainers.end()) {
		throw Failure();
	}
	//avlTree<Pokemon, pokemonCompareByLevel> trainerLevelTree =	(*trainer).getLevelTree();
	//*numOfPokemon = trainerLevelTree.getSize();
	*numOfPokemon = (*trainer).getLevelTree().getSize();
	int* pokemonArray = (int*) malloc(sizeof(int) * *numOfPokemon);
	if (pokemonArray == NULL) {
		throw AllocationError();
	}
	Pokemon* levelArray = (*trainer).getLevelTree().inOrder();
	for (int i = 0; i < *numOfPokemon; i++) {
		pokemonArray[i] = levelArray[i].getID();
	}
	*pokemons = pokemonArray;
	delete[] levelArray;
	return;
}
Ejemplo n.º 8
0
short *FFwrapper::AudioResampler::resample(void *in, size_t in_len, size_t *out_len) {
    *out_len = 2 * in_len; /* FFmpeg needs a way to find this out */
    if (*out_len > buf_size) {
        fprintf(stderr, "warning: resample buffer being reallocated\n");
        buf = (short *) av_realloc(buf, *out_len * sizeof(short));
        if (!buf) {
            buf_size = 0;
            throw AllocationError("audio resample buffer");
        }
        buf_size = *out_len;
    }

    *out_len = audio_resample(ctx, buf, (short *) in, in_len);
    if (*out_len == 0) {
        return NULL;
    } else {
        return buf;
    }
}
Ejemplo n.º 9
0
Archivo: Tmsrpt01.c Proyecto: ems/TMS
BOOL FAR TMSRPT01(TMSRPTPassedDataDef *pPassedData)
{
  REPORTPARMSDef REPORTPARMS;
  HFILE hfOutputFile;
  BOOL  bKeepGoing = FALSE;
  BOOL  bRC;
  int   maxSelectedPatternNodes = 100;
  int   nI;
  int   nJ;
  int   nK;
  int   nL;
  int   numSelectedPatternNodes;
  int   rcode2;

  long  *pSelectedPatternNodes = NULL;

  pPassedData->nReportNumber = 0;
  pPassedData->numDataFiles = 1;
//
//  See what he wants
//
  REPORTPARMS.nReportNumber = pPassedData->nReportNumber;
  REPORTPARMS.ROUTESrecordID = m_RouteRecordID;
  REPORTPARMS.SERVICESrecordID = m_ServiceRecordID;
  REPORTPARMS.PATTERNNAMESrecordID = NO_RECORD;
  REPORTPARMS.COMMENTSrecordID = NO_RECORD;
  REPORTPARMS.pRouteList = NULL;
  REPORTPARMS.pServiceList = NULL;
  REPORTPARMS.flags = RPFLAG_ROUTES | RPFLAG_SERVICES | RPFLAG_PATTERNNAMES | RPFLAG_COMMENTS;
  bRC = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_RPTPARMS),
        hWndMain, (DLGPROC)RPTPARMSMsgProc, (LPARAM)&REPORTPARMS);
  if(!bRC)
  {
    return(FALSE);
  }
//
//  Check the list of routes and services
//
  if(REPORTPARMS.numRoutes == 0 || REPORTPARMS.numServices == 0)
  {
    goto deallocate;
  }
//
//  Open the output file
//
  strcpy(tempString, szReportsTempFolder);
  strcat(tempString, "\\tmsrpt01.txt");
  hfOutputFile = _lcreat(tempString, 0);
  if(hfOutputFile == HFILE_ERROR)
  {
    LoadString(hInst, ERROR_202, szFormatString, sizeof(szFormatString));
    sprintf(szarString, szFormatString, tempString);
    MessageBeep(MB_ICONSTOP);
    MessageBox((HWND)NULL, szarString, TMS, MB_ICONSTOP);
    goto deallocate;
  }
  strcpy(pPassedData->szReportDataFile[0], tempString);
//
//  Allocate the nodes arrays
//
  pSelectedPatternNodes = (long *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(long) * maxSelectedPatternNodes); 
  if(pSelectedPatternNodes == NULL)
  {
    AllocationError(__FILE__, __LINE__, FALSE);
    goto deallocate;
  }
//
//  Load any header and trailer special characters
//
  LoadHeadersAndTrailers01();
//
//  Loop through the routes
//
  SetCursor(hCursorWait);
  for(nI = 0; nI < REPORTPARMS.numRoutes; nI++)
  {
    ROUTESKey0.recordID = REPORTPARMS.pRouteList[nI];
    rcode2 = btrieve(B_GETEQUAL, TMS_ROUTES, &ROUTES, &ROUTESKey0, 0);
    if(rcode2 != 0)
    {
      continue;
    }
//
//  Loop through the services
//
    for(nJ = 0; nJ < REPORTPARMS.numServices; nJ++)
    {
      SERVICESKey0.recordID = REPORTPARMS.pServiceList[nJ];
      rcode2 = btrieve(B_GETEQUAL, TMS_SERVICES, &SERVICES, &SERVICESKey0, 0);
      if(rcode2 != 0)
      {
        continue;
      }
//
//  Loop through the directions
//
      for(nK = 0; nK < 2; nK++)
      {
        if(ROUTES.DIRECTIONSrecordID[nK] == NO_RECORD)
        {
          continue;
        }
//
//  Find the selected pattern nodes
//
        numSelectedPatternNodes = 0;
        PATTERNNAMESKey0.recordID = REPORTPARMS.PATTERNNAMESrecordID;
        rcode2 = btrieve(B_GETEQUAL, TMS_PATTERNNAMES, &PATTERNNAMES, &PATTERNNAMESKey0, 0);
        if(rcode2 == 0)
        {
          PATTERNSKey2.ROUTESrecordID = REPORTPARMS.pRouteList[nI];
          PATTERNSKey2.SERVICESrecordID = REPORTPARMS.pServiceList[nJ];
          PATTERNSKey2.directionIndex = nK;
          PATTERNSKey2.PATTERNNAMESrecordID = PATTERNNAMES.recordID;
          PATTERNSKey2.nodeSequence = NO_RECORD;
          rcode2 = btrieve(B_GETGREATEROREQUAL, TMS_PATTERNS, &PATTERNS, &PATTERNSKey2, 2);
          while(rcode2 == 0 &&
                PATTERNS.ROUTESrecordID == REPORTPARMS.pRouteList[nI] &&
                PATTERNS.SERVICESrecordID == REPORTPARMS.pServiceList[nJ] &&
                PATTERNS.directionIndex == nK &&
                PATTERNS.PATTERNNAMESrecordID == PATTERNNAMES.recordID)
          {
            if(!(PATTERNS.flags & PATTERNS_FLAG_BUSSTOP))
            {
              pSelectedPatternNodes[numSelectedPatternNodes++] = PATTERNS.NODESrecordID;
              if(numSelectedPatternNodes >= maxSelectedPatternNodes)
              {
                maxSelectedPatternNodes += 50;
                pSelectedPatternNodes = (long *)HeapReAlloc(GetProcessHeap(),
                      HEAP_ZERO_MEMORY, pSelectedPatternNodes, sizeof(long) * maxSelectedPatternNodes); 
                if(pSelectedPatternNodes == NULL)
                {
                  AllocationError(__FILE__, __LINE__, TRUE);
                  goto deallocate;
                }
              }
            }
            rcode2 = btrieve(B_GETNEXT, TMS_PATTERNS, &PATTERNS, &PATTERNSKey2, 2);
          }
        }
        if(numSelectedPatternNodes == 0)
        {
          continue;
        }
//
//  Write out the id record
//
        strcpy(tempString, szRSDHeader);
        strncpy(szarString, ROUTES.number, ROUTES_NUMBER_LENGTH);
        trim(szarString, ROUTES_NUMBER_LENGTH);
        strcat(tempString, szarString);
        strcat(tempString, " ");
        strncpy(szarString, ROUTES.name, ROUTES_NAME_LENGTH);
        trim(szarString, ROUTES_NAME_LENGTH);
        strcat(tempString, szarString);
        strcat(tempString, " ");
        DIRECTIONSKey0.recordID = ROUTES.DIRECTIONSrecordID[nK];
        btrieve(B_GETEQUAL, TMS_DIRECTIONS, &DIRECTIONS, &DIRECTIONSKey0, 0);
        strncpy(szarString, DIRECTIONS.abbrName, DIRECTIONS_ABBRNAME_LENGTH);
        trim(szarString, DIRECTIONS_ABBRNAME_LENGTH);
        strcat(tempString, szarString);
        strcat(tempString, " ");
        strncpy(szarString, SERVICES.name, SERVICES_NAME_LENGTH);
        trim(szarString, SERVICES_NAME_LENGTH);
        strcat(tempString, szarString);
        strcat(tempString, szRSDTrailer);
        strcat(tempString, "\r\n");
        _lwrite(hfOutputFile, tempString, strlen(tempString));
//
//  Write out the number of nodes record
//
        strcpy(tempString, szNumNodesHeader);
        if(strcmp(szNumNodesHeader, "") != 0)
        {
          strcat(tempString, " ");
        }
        sprintf(szarString, "%d", numSelectedPatternNodes);
        strcat(tempString, szarString);
        strcat(tempString, szNumNodesTrailer);
        strcat(tempString, "\r\n");
        _lwrite(hfOutputFile, tempString, strlen(tempString));
//
//  Cycle through, and write out, the pattern nodes
//
        for(nL = 0; nL < numSelectedPatternNodes; nL++)
        {
          strcpy(tempString, szEachNodeHeader);
          NODESKey0.recordID = pSelectedPatternNodes[nL];
          btrieve(B_GETEQUAL, TMS_NODES, &NODES, &NODESKey0, 0);
          strncpy(szarString, NODES.intersection, NODES_INTERSECTION_LENGTH);
          trim(szarString, NODES_INTERSECTION_LENGTH);
          strcat(tempString, szarString);
          strcat(tempString, szEachNodeTrailer);
          strcat(tempString, "\r\n");
          _lwrite(hfOutputFile, tempString, strlen(tempString));
        }  // nL
      }  // nK
    }  // nJ
  }  // nI
  bKeepGoing = TRUE;
//
//  Free allocated memory
//
  deallocate:
    TMSHeapFree(REPORTPARMS.pRouteList);
    TMSHeapFree(REPORTPARMS.pServiceList);
    TMSHeapFree(pSelectedPatternNodes);
    _lclose(hfOutputFile);
    SetCursor(hCursorArrow);
    if(!bKeepGoing)
    {
      return(FALSE);
    }
//
//  All done
//
  return(TRUE);
}
Ejemplo n.º 10
0
Archivo: ADDBLOCK.c Proyecto: ems/TMS
BOOL CALLBACK ADDBLOCKMsgProc(HWND hWndDlg, UINT Message, WPARAM wParam, LPARAM lParam)
{
  typedef struct STATSStruct
  {
    float dhdDist;
    long  dhdTime;
    long  layTime;
    float revDist;
    long  revTime;
  } STATSDef;
  typedef struct PARMSStruct
  {
    BOOL bStandard;
    BOOL bDropback;
    BOOL bInterlining;
    BOOL bServiceWrap;
    BOOL bDeadheading;
    BOOL bDeadheadAll;
    long maxDeadheadTime;
  } PARMSDef;
  static PDISPLAYINFO   pDI;
  static HANDLE hCtlALLROUTES;
  static HANDLE hCtlCC;
  static HANDLE hCtlCOMMENTCODE;
  static HANDLE hCtlORROUTE;
  static HANDLE hCtlFROMROUTE;
  static HANDLE hCtlFROMSERVICE;
  static HANDLE hCtlLISTBOXTITLE;
  static HANDLE hCtlTRIPS;
  static HANDLE hCtlMIN;
  static HANDLE hCtlMINVEHICLES;
  static HANDLE hCtlMAX;
  static HANDLE hCtlMAXVEHICLES;
  static HANDLE hCtlILYES;
  static HANDLE hCtlILNO;
  static HANDLE hCtlSWYES;
  static HANDLE hCtlSWNO;
  static HANDLE hCtlDHYES;
  static HANDLE hCtlDHNO;
  static HANDLE hCtlDEADHEADALL;
  static HANDLE hCtlDEADHEADTHOSE;
  static HANDLE hCtlDEADHEADMINS;
  static HANDLE hCtlTEXT_MINUTES;
  static HANDLE hCtlIDREMOVE;
  static HANDLE hCtlIDPREVIEW;
  static HANDLE hCtlIDOPTIMAL;
  static HANDLE hCtlIDMANUAL;
  static HANDLE hCtlSTANDARD;
  static HANDLE hCtlDROPBACK;
  static HANDLE hCtlDEADHEADSTOUSE;
  static int    tabPos[TABSET] = {32};
  GenerateTripDef      GTResults;
  GetConnectionTimeDef GCTData;
  PARMSDef PARMS;
  BLOCKSDef  *pTRIPSChunk;
  LAYOVERDef *pLayover;
  float  distance;
  short  int wmId;
  short  int wmEvent;
  BOOL   bFound;
  BOOL   bEnable;
  BOOL   bAbort;
  char   routeName[ROUTES_NAME_LENGTH + 1];
  char   routeNumber[ROUTES_NUMBER_LENGTH + 1];
  char   serviceName[SERVICES_NAME_LENGTH + 1];
  long   fromRouteRecordID;
  long   fromServiceRecordID;
  long   lastBlock;
  long   minutes;
  long   percent;
  long   tempLong;
  long   minVehicles;
  long   maxVehicles;
  long   commentRecordID;
  long   position;
  long   flags;
  long   dhd;
  WORD   DlgWidthUnits;
  int adjustedTabPos[TABSET];
  int nI;
  int nJ;
  int nK;
  int nRc;
  int rcode2;
  int numRoutes;
  int numTrips;
  int maxTrips;
  int numComments;
  int numSelected;
  int fromRoutePosition;
  int fromServicePosition;
  int blockingType;
  int layoverType;

  long *pTRIPSrecordIDs = NULL;
  int  *pSelected = NULL;

  switch(Message)
  {
//
//  WM_INITDIALOG - Initialize the dialog
//
    case WM_INITDIALOG:
      pDI = (PDISPLAYINFO)lParam;
      if(pDI == NULL)
      {
        SendMessage(hWndDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), (LPARAM)0);
        break;
      }
      m_numConnectionAlerts = 0;
//
//  Set up some control handles for later use
//
      hCtlALLROUTES = GetDlgItem(hWndDlg, ADDBLOCK_ALLROUTES);
      hCtlCC = GetDlgItem(hWndDlg, ADDBLOCK_CC);
      hCtlCOMMENTCODE = GetDlgItem(hWndDlg, ADDBLOCK_COMMENTCODE);
      hCtlORROUTE = GetDlgItem(hWndDlg, ADDBLOCK_ORROUTE);
      hCtlFROMROUTE = GetDlgItem(hWndDlg, ADDBLOCK_FROMROUTE);
      hCtlFROMSERVICE = GetDlgItem(hWndDlg, ADDBLOCK_FROMSERVICE);
      hCtlLISTBOXTITLE = GetDlgItem(hWndDlg, ADDBLOCK_LISTBOXTITLE);
      hCtlTRIPS = GetDlgItem(hWndDlg, ADDBLOCK_TRIPS);
      hCtlMIN = GetDlgItem(hWndDlg, ADDBLOCK_MIN);
      hCtlMINVEHICLES = GetDlgItem(hWndDlg, ADDBLOCK_MINVEHICLES);
      hCtlMAX = GetDlgItem(hWndDlg, ADDBLOCK_MAX);
      hCtlMAXVEHICLES = GetDlgItem(hWndDlg, ADDBLOCK_MAXVEHICLES);
      hCtlILYES = GetDlgItem(hWndDlg, ADDBLOCK_ILYES);
      hCtlILNO = GetDlgItem(hWndDlg, ADDBLOCK_ILNO);
      hCtlSWYES = GetDlgItem(hWndDlg, ADDBLOCK_SWYES);
      hCtlSWNO = GetDlgItem(hWndDlg, ADDBLOCK_SWNO);
      hCtlDHYES = GetDlgItem(hWndDlg, ADDBLOCK_DHYES);
      hCtlDHNO = GetDlgItem(hWndDlg, ADDBLOCK_DHNO);
      hCtlDEADHEADALL = GetDlgItem(hWndDlg, ADDBLOCK_DEADHEADALL);
      hCtlDEADHEADTHOSE = GetDlgItem(hWndDlg, ADDBLOCK_DEADHEADTHOSE);
      hCtlDEADHEADMINS = GetDlgItem(hWndDlg, ADDBLOCK_DEADHEADMINS);
      hCtlTEXT_MINUTES = GetDlgItem(hWndDlg, ADDBLOCK_TEXT_MINUTES);
      hCtlIDREMOVE = GetDlgItem(hWndDlg, IDREMOVE);
      hCtlIDPREVIEW = GetDlgItem(hWndDlg, IDPREVIEW);
      hCtlIDOPTIMAL = GetDlgItem(hWndDlg, IDOPTIMAL);
      hCtlIDMANUAL = GetDlgItem(hWndDlg, IDMANUAL);
      hCtlSTANDARD = GetDlgItem(hWndDlg, ADDBLOCK_STANDARD);
      hCtlDROPBACK = GetDlgItem(hWndDlg, ADDBLOCK_DROPBACK);
      hCtlDEADHEADSTOUSE = GetDlgItem(hWndDlg, ADDBLOCK_DEADHEADSTOUSE);
//
//  Set up the tab stops for ADDBLOCK_LISTBOXTITLE and ADDBLOCK_TRIPS
//
      DlgWidthUnits = LOWORD(GetDialogBaseUnits()) / 4;
      for(nJ = 0; nJ < TABSET; nJ++)
      {
        adjustedTabPos[nJ] = (DlgWidthUnits * tabPos[nJ] * 2);
      }
      SendMessage(hCtlLISTBOXTITLE, LB_SETTABSTOPS, (WPARAM)TABSET, (LPARAM)adjustedTabPos);
      LoadString(hInst, TEXT_019, tempString, TEMPSTRING_LENGTH);
      SendMessage(hCtlLISTBOXTITLE, LB_ADDSTRING, 0, (LONG)(LPSTR)tempString);
      SendMessage(hCtlTRIPS, LB_SETTABSTOPS, (WPARAM)TABSET, (LPARAM)adjustedTabPos);
//
//  Default to all routes and this service
//
      SendMessage(hCtlALLROUTES, BM_SETCHECK, (WPARAM)TRUE, (LPARAM)0);
      if(SetUpServiceList(hWndDlg, ADDBLOCK_FROMSERVICE, pDI->fileInfo.serviceRecordID) == 0)
      {
        SendMessage(hWndDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), (LPARAM)0);
        break;
      }
//
//  Set up the route listbox
//
      numRoutes = 0;
      SendMessage(hCtlFROMROUTE, LB_RESETCONTENT, (WPARAM)(WPARAM)0, (LPARAM)0);
      rcode2 = btrieve(B_GETFIRST, TMS_ROUTES, &ROUTES, &ROUTESKey1, 1);
      while(rcode2 == 0)
      {
        strncpy(tempString, ROUTES.number, ROUTES_NUMBER_LENGTH);
        trim(tempString, ROUTES_NUMBER_LENGTH);
        strncpy(szarString, ROUTES.name, ROUTES_NAME_LENGTH);
        trim(szarString, ROUTES_NAME_LENGTH);
        strcat(tempString, " - ");
        strcat(tempString, szarString);
        nI = (int)SendMessage(hCtlFROMROUTE, LB_ADDSTRING, (WPARAM)0, (LONG)(LPSTR)tempString);
        SendMessage(hCtlFROMROUTE, LB_SETITEMDATA, (WPARAM)nI, ROUTES.recordID);
        numRoutes++;
        rcode2 = btrieve(B_GETNEXT, TMS_ROUTES, &ROUTES, &ROUTESKey1, 1);
      }
      if(numRoutes == 0)
      {
        TMSError(hWndDlg, MB_ICONSTOP, ERROR_008, (HANDLE)NULL);
        SendMessage(hWndDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL,0), (LPARAM)0);
        break;
      }
//
//  Comment codes combo box
//
     numComments = SetUpCommentList(hWndDlg, ADDBLOCK_COMMENTCODE);
      if(numComments == 0)
      {
        EnableWindow(hCtlCC, FALSE);
        EnableWindow(hCtlCOMMENTCODE, FALSE);
      }
//
//  Default to "Min" vechicle requirements, but with a blank field
//
      SendMessage(hCtlMIN, BM_SETCHECK, (WPARAM)TRUE, (LPARAM)0);
      SendMessage(hCtlMINVEHICLES, WM_SETTEXT, (WPARAM)0, (LONG)(LPSTR)"");
//
//  Default to allowing deadheading, service wraps, and interlining
//
      SendMessage(hCtlILYES, BM_SETCHECK, (WPARAM)TRUE, (LPARAM)0);
      SendMessage(hCtlSWYES, BM_SETCHECK, (WPARAM)TRUE, (LPARAM)0);
      SendMessage(hCtlDHYES, BM_SETCHECK, (WPARAM)TRUE, (LPARAM)0);
      SendMessage(hCtlDEADHEADALL, BM_SETCHECK, (WPARAM)TRUE, (LPARAM)0);
//
//  Clear out edit controls associated with a spin control
//
      SendMessage(hCtlDEADHEADMINS, WM_SETTEXT, (WPARAM)0, (LONG)(LPSTR)"");
//
//  Default to this table's blocking technique
//
      if(pDI->fileInfo.fileNumber == TMS_STANDARDBLOCKS)
      {
        SendMessage(hCtlSTANDARD, BM_SETCHECK, (WPARAM)TRUE, (LPARAM)0);
        EnableWindow(hCtlDROPBACK, FALSE);
      }
      else
      {
        SendMessage(hCtlDROPBACK, BM_SETCHECK, (WPARAM)TRUE, (LPARAM)0);
        EnableWindow(hCtlSTANDARD, FALSE);
      }
//
//  Set up the m_pPICKEDTRIPS structure
//
      if(m_pPICKEDTRIPS == NULL)
      {
        m_pPICKEDTRIPS = (PICKEDTRIPSDef *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PICKEDTRIPSDef) * m_maxPICKEDTRIPS); 
        if(m_pPICKEDTRIPS == NULL)
        {
          AllocationError(__FILE__, __LINE__, FALSE);
          goto OptimalBlockCleanup;
        }
      }
//
//  Set up the "destination"
//
      flags = PLACEMENT_ROUTE | PLACEMENT_SERVICE;
      DisplayPlacement(hWndDlg, ADDBLOCK_DESTINATION, pDI, flags);
      break;
//
//  WM_CLOSE
//
    case WM_CLOSE:
      SendMessage(hWndDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), (LPARAM)0);
      break;
//
//  WM_COMMAND
//
//  Note: The outbound and inbound direction buttons get
//         disabled when the route is set to "All routes"
//
    case WM_COMMAND:
      wmId = LOWORD(wParam);
      wmEvent = HIWORD(wParam);
      switch(wmId)
      {
//
//  ADDBLOCK_ALLROUTES radio button
//
        case ADDBLOCK_ALLROUTES:
          SendMessage(hCtlFROMROUTE, LB_SETSEL, (WPARAM)(FALSE), (LPARAM)(-1));
          SendMessage(hCtlCOMMENTCODE, CB_SETCURSEL, (WPARAM)(-1), (LPARAM)0);
          break;
//
//  ADDBLOCK_CC radio button
//
        case ADDBLOCK_CC:
          SendMessage(hCtlCOMMENTCODE, CB_SETCURSEL, (WPARAM)0, (LPARAM)0);
          break;
//
//  ADDBLOCK_ORROUTE radio button
//
        case ADDBLOCK_ORROUTE:
          SendMessage(hCtlCOMMENTCODE, CB_SETCURSEL, (WPARAM)(-1), (LPARAM)0);
          nI = (int)SendMessage(hCtlFROMROUTE, LB_GETCURSEL, (WPARAM)0, (LPARAM)0);
          if(nI == CB_ERR)
          {
            nJ = (int)SendMessage(hCtlFROMROUTE, LB_GETCOUNT, (WPARAM)0, (LPARAM)0);
            if(nJ == 0)
              break;
            for(nI = 0; nI < nJ; nI++)
            {
              tempLong = SendMessage(hCtlFROMROUTE, LB_GETITEMDATA, (WPARAM)nI, (LPARAM)0);
              if(tempLong == pDI->fileInfo.routeRecordID)
              {
                SendMessage(hCtlFROMROUTE, LB_SETCURSEL, (WPARAM)nI, (LPARAM)0);
                break;
              }
            }
          }
//
//  ADDBLOCK_FROMROUTE listbox
//
        case ADDBLOCK_FROMROUTE:
          switch(wmEvent)
          {
            case LBN_SELCHANGE:
              if(SendMessage(hCtlALLROUTES, BM_GETCHECK, (WPARAM)0, (LPARAM)0))
              {
                SendMessage(hCtlALLROUTES, BM_SETCHECK, (WPARAM)FALSE, (LPARAM)0);
                SendMessage(hCtlORROUTE, BM_SETCHECK, (WPARAM)TRUE, (LPARAM)0);
              }
              break;
          }
          break;
//
//  ADDBLOCK_LISTBOXTITLE
//
        case ADDBLOCK_LISTBOXTITLE:  // Title string
          SendMessage(hCtlLISTBOXTITLE, LB_SETSEL, (WPARAM)FALSE, (LPARAM)(-1));
          break;
//
//  ADDBLOCK_TRIPS
//
        case ADDBLOCK_TRIPS: // List box
          switch(wmEvent)
          {
            case LBN_SELCHANGE:
            case LBN_SELCANCEL:
              bEnable = SendMessage(hCtlTRIPS, LB_GETSELCOUNT, (WPARAM)0, (LPARAM)0) > 0;
              EnableWindow(hCtlIDREMOVE, bEnable);
              EnableWindow(hCtlIDPREVIEW, bEnable);
              break;
 
            case LBN_DBLCLK:
              SendMessage(hWndDlg, WM_COMMAND, MAKEWPARAM(IDPREVIEW, 0), (LPARAM)0);
              EnableWindow(hCtlIDPREVIEW, TRUE);
              break;
          }
          break;
//
//  ADDBLOCK_MIN
//
        case ADDBLOCK_MIN:
          EnableWindow(hCtlMINVEHICLES, TRUE);
          EnableWindow(hCtlMAXVEHICLES, FALSE);
          break;
//
//  ADDBLOCK_MAX
//
        case ADDBLOCK_MAX:
          EnableWindow(hCtlMINVEHICLES, FALSE);
          EnableWindow(hCtlMAXVEHICLES, TRUE);
          break;
//
//  ADDBLOCK_DHYES / ADDBLOCK_DHNO
//
        case ADDBLOCK_DHYES:
        case ADDBLOCK_DHNO:
          bEnable = SendMessage(hCtlDHYES, BM_GETCHECK, (WPARAM)0, (LPARAM)0);
          EnableWindow(hCtlDEADHEADALL, bEnable);
          EnableWindow(hCtlDEADHEADSTOUSE, bEnable);
          EnableWindow(hCtlDEADHEADTHOSE, bEnable);
          EnableWindow(hCtlDEADHEADMINS, bEnable);
          EnableWindow(hCtlTEXT_MINUTES, bEnable);
          break;
//
//  IDPREVIEW
//
        case IDPREVIEW: // Button text: "Preview"
          nI = SendMessage(hCtlTRIPS, LB_GETSELCOUNT, (WPARAM)0, (LPARAM)0);
          if(nI == 0 || nI == LB_ERR)
          {
            break;
          }
          pSelected = (int *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(int) * nI); 
          if(pSelected == NULL)
          {
            AllocationError(__FILE__, __LINE__, FALSE);
            break;
          }
          numSelected = (int)SendMessage(hCtlTRIPS, LB_GETSELITEMS, (WPARAM)nI, (LPARAM)pSelected);
          if(numSelected >= m_maxPICKEDTRIPS)
          {
            m_maxPICKEDTRIPS += (numSelected + 1);
            m_pPICKEDTRIPS = (PICKEDTRIPSDef *)HeapReAlloc(GetProcessHeap(),
                  HEAP_ZERO_MEMORY, m_pPICKEDTRIPS, sizeof(PICKEDTRIPSDef) * m_maxPICKEDTRIPS); 
            if(m_pPICKEDTRIPS == NULL)
            {
              AllocationError(__FILE__, __LINE__, TRUE);
              break;
            }
          }
          for(nI = 0; nI < numSelected; nI++)
          {
            position = SendMessage(hCtlTRIPS, LB_GETITEMDATA, (WPARAM)pSelected[nI], (LPARAM)0);
            fromRoutePosition = LOWORD(position);
            fromServicePosition = HIWORD(position);
            m_pPICKEDTRIPS[nI].ROUTESrecordID = SendMessage(hCtlFROMROUTE,
                  LB_GETITEMDATA, (WPARAM)fromRoutePosition, (LPARAM)0);
            m_pPICKEDTRIPS[nI].SERVICESrecordID = SendMessage(hCtlFROMSERVICE,
                  CB_GETITEMDATA, (WPARAM)fromServicePosition, (LPARAM)0);
          }
          DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_PREVIEWT),
                hWndDlg, (DLGPROC)PREVIEWTMsgProc, (LPARAM)numSelected);
          TMSHeapFree(pSelected);
          break;
//
//  IDADD
//
        case IDADD: // Button text: "&Add Trip(s)"
//
//  Get the service
//
          fromServicePosition =
                (int)SendMessage(hCtlFROMSERVICE, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
          if(fromServicePosition == CB_ERR)
          {
            break;
          }
          fromServiceRecordID =
                SendMessage(hCtlFROMSERVICE, CB_GETITEMDATA, (WPARAM)fromServicePosition, (LPARAM)0);
          SERVICESKey0.recordID = fromServiceRecordID;
          btrieve(B_GETEQUAL, TMS_SERVICES, &SERVICES, &SERVICESKey0, 0);
          strncpy(serviceName, SERVICES.name, SERVICES_NAME_LENGTH);
          trim(serviceName, SERVICES_NAME_LENGTH);
//
//  Get the route(s)
//
//  All
//
          if(SendMessage(hCtlALLROUTES, BM_GETCHECK, (WPARAM)0, (LPARAM)0))
          {
            SendMessage(hCtlFROMROUTE, LB_SETSEL, (WPARAM)(TRUE), (LPARAM)(-1));
          }
//
//  Those labelled...
//
          else if(SendMessage(hCtlCC, BM_GETCHECK, (WPARAM)0, (LPARAM)0))
          {
             nK = (int)SendMessage(hCtlCOMMENTCODE, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
             commentRecordID = (nK == CB_ERR ? NO_RECORD : 
                   SendMessage(hCtlCOMMENTCODE, CB_GETITEMDATA, (WPARAM)nK, (LPARAM)0));
            if(commentRecordID == NO_RECORD)
            {
              break;
            }
            nJ = (int)SendMessage(hCtlFROMROUTE, LB_GETCOUNT, (WPARAM)0, (LPARAM)0);
            for(nI = 0; nI < nJ; nI++)
            {
              ROUTESKey0.recordID = SendMessage(hCtlFROMROUTE, LB_GETITEMDATA, (WPARAM)nI, (LPARAM)0);
              rcode2 = btrieve(B_GETEQUAL, TMS_ROUTES, &ROUTES, &ROUTESKey0, 0);
              if(ROUTES.COMMENTSrecordID == commentRecordID)
              {
                SendMessage(hCtlFROMROUTE, LB_SETSEL, (WPARAM)TRUE, (LPARAM)nI);
              }
            }
          }  
//
//  Got the selections - continue
//
          nI = (int)SendMessage(hCtlFROMROUTE, LB_GETSELCOUNT, (WPARAM)0, (LPARAM)0);
          if(nI == 0 || nI == LB_ERR)
          {
            break;
          }
          pSelected = (int *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(int) * nI); 
          if(pSelected == NULL)
          {
            AllocationError(__FILE__, __LINE__, FALSE);
            break;
          }
          numSelected = (int)SendMessage(hCtlFROMROUTE, LB_GETSELITEMS, (WPARAM)nI, (LPARAM)pSelected);
//
//  Add the results to the "to be blocked" list box
//  
          for(nI = 0; nI < numSelected; nI++)
          {
            fromRoutePosition = pSelected[nI];
            fromRouteRecordID = SendMessage(hCtlFROMROUTE, LB_GETITEMDATA, (WPARAM)fromRoutePosition, (LPARAM)0);
//
//  Before we go any further, let's see if we've got this one already
//
            position = MAKELONG(fromRoutePosition, fromServicePosition);
            nJ = SendMessage(hCtlTRIPS, LB_GETCOUNT, (WPARAM)0, (LPARAM)0);
            for(bFound = FALSE, nK = 0; nK < nJ; nK++)
            {
              tempLong = SendMessage(hCtlTRIPS, LB_GETITEMDATA, (WPARAM)nK, (LPARAM)0);
              if(tempLong == position)
              {
                bFound = TRUE;
                break;
              }
            }
            if(bFound)
            {
              continue;
            }
//
//  Not found
//
            EnableWindow(hCtlIDOPTIMAL, TRUE);
            EnableWindow(hCtlIDMANUAL, TRUE);
//
//  Display it
//
            ROUTESKey0.recordID = fromRouteRecordID;
            btrieve(B_GETEQUAL, TMS_ROUTES, &ROUTES, &ROUTESKey0, 0);
            strncpy(routeNumber, ROUTES.number, ROUTES_NUMBER_LENGTH);
            trim(routeNumber, ROUTES_NUMBER_LENGTH);
            strncpy(routeName, ROUTES.name, ROUTES_NAME_LENGTH);
            trim(routeName, ROUTES_NAME_LENGTH);
            strcpy(tempString, routeNumber);
            strcat(tempString, " - ");
            strcat(tempString, routeName);
            tempString[tabPos[0]] = '\0';
            strcat(tempString, "\t");
            strcat(tempString, serviceName);
            nK = (int)SendMessage(hCtlTRIPS, LB_ADDSTRING, (WPARAM)0, (LONG)(LPSTR)tempString);
            SendMessage(hCtlTRIPS, LB_SETITEMDATA, (WPARAM)nK, (LPARAM)position);
          }
          SendMessage(hCtlFROMROUTE, LB_SETSEL, (WPARAM)FALSE, (LPARAM)(-1));
          TMSHeapFree(pSelected);
          break;
//
//  IDREMOVE
//
        case IDREMOVE: // Button text: "Remove"
          nI = (int)SendMessage(hCtlTRIPS, LB_GETSELCOUNT, (WPARAM)0, (LPARAM)0);
          if(nI == 0 || nI == LB_ERR)
          {
            break;
          }
          pSelected = (int *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(int) * nI); 
          if(pSelected == NULL)
          {
            AllocationError(__FILE__, __LINE__, FALSE);
            break;
          }
          numSelected = (int)SendMessage(hCtlTRIPS, LB_GETSELITEMS, (WPARAM)nI, (LPARAM)pSelected);
//
//  Process the list from the back to the front
//
          for(nI = numSelected - 1; nI >= 0; nI--)
          {
            SendMessage(hCtlTRIPS, LB_DELETESTRING, (WPARAM)pSelected[nI], (LPARAM)0);
          }
          if(SendMessage(hCtlTRIPS, LB_GETCOUNT, (WPARAM)0, (LPARAM)0) == 0)
          {
            EnableWindow(hCtlIDOPTIMAL, FALSE);
            EnableWindow(hCtlIDMANUAL, FALSE);
          }
          EnableWindow(hCtlIDREMOVE, FALSE);
          EnableWindow(hCtlIDPREVIEW, FALSE);
          TMSHeapFree(pSelected);
          break;
//
//  IDCANCEL
//
        case IDCANCEL:
          EndDialog(hWndDlg, FALSE);
          break;
//
//  IDHELP
//
        case IDHELP:
          WinHelp(hWndDlg, szarHelpFile, HELP_CONTEXT, The_Standard_Blocks_Table);
          break;
//
//  IDMANUAL and IDOPTIMAL
//
        case IDMANUAL:
        case IDOPTIMAL:
          m_bNetworkMode = FALSE;
//
//  Get the parameters
//
          PARMS.bStandard = SendMessage(hCtlSTANDARD, BM_GETCHECK, (WPARAM)0, (LPARAM)0);
          PARMS.bDropback = SendMessage(hCtlDROPBACK, BM_GETCHECK, (WPARAM)0, (LPARAM)0);
//
//  Standard and Dropback are mutually exclusive on a manual block
//
          if(wmId == IDMANUAL)
          {
            if(PARMS.bStandard && PARMS.bDropback)
            {
              TMSError(hWndDlg, MB_ICONSTOP, ERROR_134, hCtlSTANDARD);
              break;
            }
          }
//
//  At least one of Standard or Dropback must be chosen prior to pressing Optimal
//
          else
          {
            if(!PARMS.bStandard && !PARMS.bDropback)
            {
              TMSError(hWndDlg, MB_ICONSTOP, ERROR_135, hCtlSTANDARD);
              break;
            }
          }
//
//  Get the rest of the parameters
//
          PARMS.bInterlining = SendMessage(hCtlILYES, BM_GETCHECK, (WPARAM)0, (LPARAM)0);
          PARMS.bServiceWrap = SendMessage(hCtlSWYES, BM_GETCHECK, (WPARAM)0, (LPARAM)0);
          PARMS.bDeadheading = SendMessage(hCtlDHYES, BM_GETCHECK, (WPARAM)0, (LPARAM)0);
          if(!PARMS.bDeadheading)
          {
            PARMS.bDeadheadAll = FALSE;
            PARMS.maxDeadheadTime = NO_TIME;
          }
          else
          {
            SendMessage(hCtlDEADHEADMINS, WM_GETTEXT,
                  (WPARAM)TEMPSTRING_LENGTH, (LONG)(LPSTR)tempString);
            if(strcmp(tempString, "") == 0)
            {
              PARMS.bDeadheadAll = TRUE;
              PARMS.maxDeadheadTime = NO_TIME;
            }
            else
            {
              PARMS.bDeadheadAll = FALSE;
              PARMS.maxDeadheadTime = atol(tempString) * 60;
            }
          }
//
//  Build the list of selected trips
//
          m_numPICKEDTRIPS = SendMessage(hCtlTRIPS, LB_GETCOUNT, (WPARAM)0, (LPARAM)0);
          if(m_numPICKEDTRIPS >= m_maxPICKEDTRIPS)
          {
            m_maxPICKEDTRIPS += (m_numPICKEDTRIPS + 1);
            m_pPICKEDTRIPS = (PICKEDTRIPSDef *)HeapReAlloc(GetProcessHeap(),
                  HEAP_ZERO_MEMORY, m_pPICKEDTRIPS, sizeof(PICKEDTRIPSDef) * m_maxPICKEDTRIPS); 
            if(m_pPICKEDTRIPS == NULL)
            {
              AllocationError(__FILE__, __LINE__, TRUE);
              break;
            }
          }
          for(nI = 0; nI < m_numPICKEDTRIPS; nI++)
          {
            position = SendMessage(hCtlTRIPS, LB_GETITEMDATA, (WPARAM)nI, (LPARAM)0);
            fromRoutePosition = LOWORD(position);
            fromServicePosition = HIWORD(position);
            m_pPICKEDTRIPS[nI].ROUTESrecordID = SendMessage(hCtlFROMROUTE,
                  LB_GETITEMDATA, (WPARAM)fromRoutePosition, (LPARAM)0);
            m_pPICKEDTRIPS[nI].SERVICESrecordID = SendMessage(hCtlFROMSERVICE,
                  CB_GETITEMDATA, (WPARAM)fromServicePosition, (LPARAM)0);
          }
//
//  Dropback blocking isn't permitted unless it's been "standard" blocked already
//
          if(PARMS.bDropback)
          {
            bAbort = FALSE;
            for(nI = 0; nI < m_numPICKEDTRIPS; nI++)
            {
              if(bAbort)
                break;
              for(nJ = 0; nJ < 2; nJ++)
              {
                if(bAbort)
                  break;
                ROUTESKey0.recordID = m_pPICKEDTRIPS[nI].ROUTESrecordID;
                btrieve(B_GETEQUAL, TMS_ROUTES, &ROUTES, &ROUTESKey0, 0);
                if(ROUTES.DIRECTIONSrecordID[nJ] == NO_RECORD)
                  continue;
                TRIPSKey1.ROUTESrecordID = m_pPICKEDTRIPS[nI].ROUTESrecordID;
                TRIPSKey1.SERVICESrecordID = m_pPICKEDTRIPS[nI].SERVICESrecordID;
                TRIPSKey1.directionIndex = nJ;
                TRIPSKey1.tripSequence = NO_TIME;
                rcode2 = btrieve(B_GETGREATEROREQUAL, TMS_TRIPS, &TRIPS, &TRIPSKey1, 1);
                while(rcode2 == 0 &&
                      TRIPS.ROUTESrecordID == m_pPICKEDTRIPS[nI].ROUTESrecordID &&
                      TRIPS.SERVICESrecordID == m_pPICKEDTRIPS[nI].SERVICESrecordID &&
                      TRIPS.directionIndex == nJ)
                {
                  if(TRIPS.standard.blockNumber == 0)
                  {
                    LoadString(hInst, TEXT_245, szFormatString, sizeof(szFormatString));
                    strncpy(routeNumber, ROUTES.number, ROUTES_NUMBER_LENGTH);
                    trim(routeNumber, ROUTES_NUMBER_LENGTH);
                    strncpy(routeName, ROUTES.name, ROUTES_NAME_LENGTH);
                    trim(routeName, ROUTES_NAME_LENGTH);
                    SERVICESKey0.recordID = m_pPICKEDTRIPS[nI].SERVICESrecordID;
                    btrieve(B_GETEQUAL, TMS_SERVICES, &SERVICES, &SERVICESKey0, 0);
                    strncpy(serviceName, SERVICES.name, SERVICES_NAME_LENGTH);
                    trim(serviceName, SERVICES_NAME_LENGTH);
                    sprintf(tempString, szFormatString, serviceName, routeNumber, routeName);
                    MessageBeep(MB_ICONSTOP);
                    MessageBox(hWndDlg, tempString, TMS, MB_OK);
                    bAbort = TRUE;
                    break;
                  }
                  rcode2 = btrieve(B_GETNEXT, TMS_TRIPS, &TRIPS, &TRIPSKey1, 1);
                }
              }
            }
            if(bAbort)
              break;
          }
//  
//  IDMANUAL - Go into MANBLOCK
//
          if(wmId == IDMANUAL)
          {
            pDI->otherData = (long)(&PARMS);
            nRc = BlockDialog(pDI);
            if(nRc)
            {
              EndDialog(hWndDlg, TRUE);
            }
            break;
          }
//
//  IDOPTIMAL
//
          for(blockingType = 0; blockingType < 2; blockingType++)
          {
            if(blockingType == 0)
            {
              if(!PARMS.bStandard)
              {
                continue;
              }
              StatusBarStart(hWndDlg, "Optimal Standard Blocking Status");
              pTRIPSChunk = &TRIPS.standard;
              pLayover = &StandardLayover;
              layoverType = TMS_STANDARDBLOCKS;
            }
            else
            {
              if(!PARMS.bDropback)
              {
                continue;
              }
              StatusBarStart(hWndDlg, "Optimal Dropback Blocking Status");
              pTRIPSChunk = &TRIPS.dropback;
              pLayover = &DropbackLayover;
              layoverType = TMS_DROPBACKBLOCKS;
            }
            StatusBar(-1L, -1L);
            StatusBarText("Initializing...");
//
//  Initialize the interlining option
//
            BLSetOptions(SendMessage(hCtlILYES, BM_GETCHECK, (WPARAM)0, (LPARAM)0));
//
//  Loop through numPICKEDTRIPS to determine what we're dealing with
//
            StatusBarText("Examining selected trips...");
            m_numConnectionAlerts = 0;
            maxTrips = 512;
            pTRIPSrecordIDs = (long *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(long) * maxTrips); 
            if(pTRIPSrecordIDs == NULL)
            {
              AllocationError(__FILE__, __LINE__, FALSE);
              goto OptimalBlockCleanup;
            }
            for(numTrips = 0, nI = 0; nI < m_numPICKEDTRIPS; nI++)
            {
              StatusBar((long)nI, (long)m_numPICKEDTRIPS);
              if(StatusBarAbort())
              {
                goto OptimalBlockCleanup;
              }
              m_bEstablishRUNTIMES = TRUE;
              TRIPSKey1.ROUTESrecordID = m_pPICKEDTRIPS[nI].ROUTESrecordID;
              TRIPSKey1.SERVICESrecordID = m_pPICKEDTRIPS[nI].SERVICESrecordID;
              TRIPSKey1.directionIndex = NO_RECORD;
              TRIPSKey1.tripSequence = NO_RECORD;
              rcode2 = btrieve(B_GETGREATEROREQUAL, TMS_TRIPS, &TRIPS, &TRIPSKey1, 1);
              while(rcode2 == 0 &&
                    (m_pPICKEDTRIPS[nI].ROUTESrecordID == NO_RECORD ||
                          TRIPS.ROUTESrecordID == m_pPICKEDTRIPS[nI].ROUTESrecordID) &&
                    (m_pPICKEDTRIPS[nI].SERVICESrecordID == NO_RECORD ||
                          TRIPS.SERVICESrecordID == m_pPICKEDTRIPS[nI].SERVICESrecordID))
              {
                if(pTRIPSChunk->blockNumber == 0)
                {
                  if(numTrips >= maxTrips)
                  {
                    maxTrips += 512;
                    pTRIPSrecordIDs = (long *)HeapReAlloc(GetProcessHeap(),
                          HEAP_ZERO_MEMORY, pTRIPSrecordIDs, sizeof(long) * maxTrips); 
                    if(pTRIPSrecordIDs == NULL)
                    {
                      AllocationError(__FILE__, __LINE__, TRUE);
                      goto OptimalBlockCleanup;
                    }
                  }
                  pTRIPSrecordIDs[numTrips++] = TRIPS.recordID;
                }
                rcode2 = btrieve(B_GETNEXT, TMS_TRIPS, &TRIPS, &TRIPSKey1, 1);
              }
            }
            if((m_numTripsForBlocker = numTrips) == 0)
            {
              TMSError(hWndDlg, MB_ICONSTOP, ERROR_102, (HANDLE)NULL);
              goto OptimalBlockCleanup;
            }
//
//  If m_numConnectionAlerts is non-zero, blow him off
//
            if(m_numConnectionAlerts != 0)
            {
              TMSError(hWndDlg, MB_ICONSTOP, ERROR_173, (HANDLE)NULL);
              goto OptimalBlockCleanup;
            }
//
//  Make sure that we're not going in with bad values for min & max layover
//
            if(pLayover->minimum.type == NO_RECORD ||
                  pLayover->maximum.type == NO_RECORD ||
                  (pLayover->maximum.type == 0 && pLayover->maximum.minutes == 0))
            {
              MessageBeep(MB_ICONSTOP);
              LoadString(hInst, ERROR_030, szarString, sizeof(szarString));
              MessageBox(hWndDlg, szarString, TMS, MB_ICONSTOP);
              nRc = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_LAYOVER),
                    hWndDlg, (DLGPROC)LAYOVERMsgProc, (LPARAM)layoverType);
              if(!nRc)
                goto OptimalBlockCleanup;
            }
//
//  Generate trip data into TRIPINFO
//
            StatusBarText("Building trip data...");
            StatusBar(0L, 0L);
            BLInitNetwork();
            for(nI = 0; nI < numTrips; nI++)
            {
              StatusBar((long)nI, (long)numTrips);
              if(StatusBarAbort())
                goto OptimalBlockCleanup;
              TRIPSKey0.recordID = pTRIPSrecordIDs[nI];
              btrieve(B_GETEQUAL, TMS_TRIPS, &TRIPS, &TRIPSKey0, 0);
              nJ = GenerateTrip(TRIPS.ROUTESrecordID, TRIPS.SERVICESrecordID,
                    TRIPS.directionIndex, TRIPS.PATTERNNAMESrecordID,
                    TRIPS.timeAtMLP, GENERATETRIP_FLAG_DISPLAYERRORS, &GTResults);
//
//  If we've got a one-node trip, fool the blocker
//
              if(GTResults.firstNODESrecordID == GTResults.lastNODESrecordID &&
                    GTResults.firstNodeTime == GTResults.lastNodeTime)
              {
                GTResults.lastNodeTime++;
              }
              if(nJ != 0)
              {
                TRIPINFODef TRIPINFOrec;
                TRIPINFOrec.TRIPSrecordID = TRIPS.recordID;
                TRIPINFOrec.BUSTYPESrecordID = TRIPS.BUSTYPESrecordID;
                TRIPINFOrec.ROUTESrecordID = TRIPS.ROUTESrecordID;
//
//  If we're doing a dropback, and the standard block pulls out or in,
//  then replace the start/end node/time with the pullout/in gar/time.
//
//  Check pullouts
//
                if(PARMS.bStandard || TRIPS.standard.POGNODESrecordID == NO_RECORD)
                {
                  TRIPINFOrec.startNODESrecordID = GTResults.firstNODESrecordID;
                  TRIPINFOrec.startTime = GTResults.firstNodeTime;
                }
                else
                {
                  GCTData.fromPATTERNNAMESrecordID = TRIPS.PATTERNNAMESrecordID;
                  GCTData.toPATTERNNAMESrecordID = TRIPS.PATTERNNAMESrecordID;
                  GCTData.fromROUTESrecordID = TRIPS.ROUTESrecordID;
                  GCTData.fromSERVICESrecordID = TRIPS.SERVICESrecordID;
                  GCTData.toROUTESrecordID = TRIPS.ROUTESrecordID;
                  GCTData.toSERVICESrecordID = TRIPS.SERVICESrecordID;
                  GCTData.fromNODESrecordID = TRIPS.standard.POGNODESrecordID;
                  GCTData.toNODESrecordID = GTResults.firstNODESrecordID;
                  GCTData.timeOfDay = GTResults.firstNodeTime;
                  dhd = GetConnectionTime(GCT_FLAG_DEADHEADTIME, &GCTData, &distance);
                  distance = (float)fabs((double)distance);
                  if(dhd == NO_TIME)
                    dhd = 0;
                  TRIPINFOrec.startNODESrecordID = TRIPS.standard.POGNODESrecordID;
                  TRIPINFOrec.startTime = GTResults.firstNodeTime - dhd;
                }
//
//  Check pullins
//
                if(PARMS.bStandard || TRIPS.standard.PIGNODESrecordID == NO_RECORD)
                {
                  TRIPINFOrec.endNODESrecordID = GTResults.lastNODESrecordID;
                  TRIPINFOrec.endTime = GTResults.lastNodeTime;
                }
                else
                {
                  GCTData.fromPATTERNNAMESrecordID = TRIPS.PATTERNNAMESrecordID;
                  GCTData.toPATTERNNAMESrecordID = TRIPS.PATTERNNAMESrecordID;
                  GCTData.fromROUTESrecordID = TRIPS.ROUTESrecordID;
                  GCTData.fromSERVICESrecordID = TRIPS.SERVICESrecordID;
                  GCTData.toROUTESrecordID = TRIPS.ROUTESrecordID;
                  GCTData.toSERVICESrecordID = TRIPS.SERVICESrecordID;
                  GCTData.fromNODESrecordID = GTResults.lastNODESrecordID;
                  GCTData.toNODESrecordID = TRIPS.standard.PIGNODESrecordID;
                  GCTData.timeOfDay = GTResults.lastNodeTime;
                  dhd = GetConnectionTime(GCT_FLAG_DEADHEADTIME, &GCTData, &distance);
                  distance = (float)fabs((double)distance);
                  if(dhd == NO_TIME)
                    dhd = 0;
                  TRIPINFOrec.endNODESrecordID = TRIPS.standard.PIGNODESrecordID;
                  TRIPINFOrec.endTime = GTResults.lastNodeTime + dhd;
                }
//
//  Figure out the minimum layover
//
                if(pTRIPSChunk->layoverMin != NO_TIME)
                  TRIPINFOrec.layoverMin = pTRIPSChunk->layoverMin;
                else
                {
                  minutes = pLayover->minimum.minutes  * 60;
                  percent = (GTResults.lastNodeTime - GTResults.firstNodeTime) * pLayover->minimum.percent / 100;
                  if(pLayover->minimum.type == 0)
                    TRIPINFOrec.layoverMin = minutes;
                  else if(pLayover->minimum.type == 1)
                    TRIPINFOrec.layoverMin = percent;
                  else if(pLayover->minimum.type == 2)
                    TRIPINFOrec.layoverMin =
                          pLayover->minimum.lower ? min(minutes, percent) : max(minutes, percent);
                }
//
//  Figure out the maximum layover
//
                if(pTRIPSChunk->layoverMax != NO_TIME)
                  TRIPINFOrec.layoverMax = pTRIPSChunk->layoverMax;
                else
                {
                  minutes = pLayover->maximum.minutes * 60;
                  percent = (GTResults.lastNodeTime - GTResults.firstNodeTime) * pLayover->maximum.percent / 100;
                  if(pLayover->maximum.type == 0)
                    TRIPINFOrec.layoverMax = minutes;
                  else if(pLayover->maximum.type == 1)
                    TRIPINFOrec.layoverMax = percent;
                  else if(pLayover->maximum.type == 2)
                    TRIPINFOrec.layoverMax =
                          pLayover->maximum.lower ? min(minutes, percent) : max(minutes, percent);
                }
//
//  And generate the trip arc
//
                BLGenerateTripArc( &TRIPINFOrec );
              }
            }
//
//  If m_numConnectionAlerts is non-zero, blow him off
//
            if(m_numConnectionAlerts != 0)
            {
              TMSError(hWndDlg, MB_ICONSTOP, ERROR_173, (HANDLE)NULL);
              goto OptimalBlockCleanup;
            }
//
//  Generate the wait arcs between the trips
//
            StatusBarText("Generating wait arcs...");
            StatusBar(-1L, -1L);
            BLGenerateWaitArcs(FALSE);
//
//  Generate deadhead and equivalence data into DEADHEADINFO
//
            rcode2 = btrieve(B_GETFIRST, TMS_CONNECTIONS, &CONNECTIONS, &CONNECTIONSKey0, 0);
            numDeadheadsForBlocker = 0;
            while(rcode2 == 0)
            {
              if(StatusBarAbort())
                goto OptimalBlockCleanup;
              if(PARMS.bDeadheading)
              {
                if((CONNECTIONS.flags & CONNECTIONS_FLAG_DEADHEADTIME) &&
                      (PARMS.bDeadheadAll || CONNECTIONS.connectionTime <= PARMS.maxDeadheadTime))
                {
                  DEADHEADINFODef DEADHEADINFOrec;
                  DEADHEADINFOrec.fromTimeOfDay = CONNECTIONS.fromTimeOfDay;
                  DEADHEADINFOrec.toTimeOfDay = CONNECTIONS.toTimeOfDay;
                  DEADHEADINFOrec.fromNODESrecordID = CONNECTIONS.fromNODESrecordID;
                  DEADHEADINFOrec.toNODESrecordID = CONNECTIONS.toNODESrecordID;
                  DEADHEADINFOrec.flags = CONNECTIONS.flags;
                  DEADHEADINFOrec.deadheadTime = CONNECTIONS.connectionTime;
                  BLGenerateDeadheadArcs( &DEADHEADINFOrec );
                  numDeadheadsForBlocker++;
                }
              }
              if(CONNECTIONS.flags & CONNECTIONS_FLAG_EQUIVALENT)
              {
                DEADHEADINFODef DEADHEADINFOrec;
                DEADHEADINFOrec.fromTimeOfDay = CONNECTIONS.fromTimeOfDay;
                DEADHEADINFOrec.toTimeOfDay = CONNECTIONS.toTimeOfDay;
                DEADHEADINFOrec.fromNODESrecordID = CONNECTIONS.fromNODESrecordID;
                DEADHEADINFOrec.toNODESrecordID = CONNECTIONS.toNODESrecordID;
                DEADHEADINFOrec.flags = CONNECTIONS.flags;
                DEADHEADINFOrec.deadheadTime = 0;
                BLGenerateDeadheadArcs( &DEADHEADINFOrec );
                numDeadheadsForBlocker++;
              }
              rcode2 = btrieve(B_GETNEXT, TMS_CONNECTIONS, &CONNECTIONS, &CONNECTIONSKey0, 0);
            }
            if(StatusBarAbort())
              goto OptimalBlockCleanup;
//
//  Get the minimum and maximum number of vehicles parameters.
//  This only applies to Optimal, so it's done here rather than above.
//
            if(SendMessage(hCtlMIN, BM_GETCHECK, (WPARAM)0, (LPARAM)0))
            {
              maxVehicles = NO_TIME;
              SendMessage(hCtlMINVEHICLES, WM_GETTEXT,
                    (WPARAM)TEMPSTRING_LENGTH, (LONG)(LPSTR)tempString);
              if(strcmp(tempString, "") == 0)
                minVehicles = NO_TIME;
              else
                minVehicles = atol(tempString);
            }
            else
            {
              minVehicles = NO_TIME;
              SendMessage(hCtlMAXVEHICLES, WM_GETTEXT,
                    (WPARAM)TEMPSTRING_LENGTH, (LONG)(LPSTR)tempString);
              if(strcmp(tempString, "") == 0)
                maxVehicles = NO_TIME;
              else
                maxVehicles = atol(tempString);
            }
//
//  Call the blocker
//
            m_pBLOCKSDATA = (BLOCKSDATADef *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BLOCKSDATADef) * m_numTripsForBlocker); 
            if(m_pBLOCKSDATA == NULL)
            {
              AllocationError(__FILE__, __LINE__, FALSE);
              goto OptimalBlockCleanup;
            }
            StatusBarText("Optimal blocking in progress...");
            sblock(minVehicles, maxVehicles);
            if(StatusBarAbort())
            {
              goto OptimalBlockCleanup;
            }
//
//  Update the file with the results
//
            lastBlock = GetNewBlockNumber(pDI);
            StatusBarText("Blocking complete - writing results...");
            StatusBarEnableCancel(FALSE);
            for(nJ = 0; nJ < numTrips; nJ++)
            {
              StatusBar((long)nJ, (long)numTrips);
              TRIPSKey0.recordID = m_pBLOCKSDATA[nJ].TRIPSrecordID;
              if((rcode2 = btrieve(B_GETEQUAL, TMS_TRIPS, &TRIPS, &TRIPSKey0, 0)) != 0)
              {
                MessageBeep(MB_ICONSTOP);
                LoadString(hInst, ERROR_015, szarString, sizeof(szarString));
                SetFocus(hCtlFROMROUTE);
                MessageBox(hWndDlg, szarString, TMS, MB_ICONSTOP);
                goto OptimalBlockCleanup;
              }
              GenerateTrip(TRIPS.ROUTESrecordID, TRIPS.SERVICESrecordID,
                    TRIPS.directionIndex, TRIPS.PATTERNNAMESrecordID,
                    TRIPS.timeAtMLP, GENERATETRIP_FLAG_DISPLAYERRORS, &GTResults);
              pTRIPSChunk->blockNumber = m_pBLOCKSDATA[nJ].blockNumber + lastBlock;
              pTRIPSChunk->RGRPROUTESrecordID = pDI->fileInfo.routeRecordID;
              pTRIPSChunk->SGRPSERVICESrecordID = pDI->fileInfo.serviceRecordID;
              pTRIPSChunk->blockSequence = GTResults.firstNodeTime;
              btrieve(B_UPDATE, TMS_TRIPS, &TRIPS, &TRIPSKey0, 0);
            }

            OptimalBlockCleanup:
              BLCleanup();
              TMSHeapFree(m_pBLOCKSDATA);
              TMSHeapFree(pTRIPSrecordIDs);
              m_numTripsForBlocker = 0;
              StatusBarEnd();
          }  // blockingType

          EndDialog(hWndDlg, TRUE);
          break;
       }
     break;    //  End of WM_COMMAND

    default:
      return FALSE;
  }

  return TRUE;
} //  End of ADDBLOCKMsgProc
Ejemplo n.º 11
0
void InitTravelMatrix(long SERVICESrecordID, BOOL bDisplayStatus)
{
  typedef struct PATHStruct
  {
    long NODESrecordID;
    long ROUTESrecordID;
    long directionIndex;
    long PATTERNNAMESrecordID;
    long nodeSequence;
  } PATHDef;
  typedef struct COMBINEDStruct
  {
    long fromNODESrecordID;
    long toNODESrecordID;
    long ROUTESrecordID;
    long directionIndex;
    long PATTERNNAMESrecordID;
    int  fromNodePos;
    int  toNodePos;
  } COMBINEDDef;
  typedef struct BESTStruct
  {
    long fromNODESrecordID;
    long toNODESrecordID;
    long TRIPSrecordID;
    long cushionTime;
    long dwellTime;
    long tripTime[2];
  } BESTDef;
  PATHDef from[UPPERLIMIT];
  PATHDef to[UPPERLIMIT];
  COMBINEDDef fromTo[UPPERLIMIT];
  GenerateTripDef      GTResults;
  GetConnectionTimeDef GCTData;
  float distance;
  long fromEquiv[UPPERLIMIT];
  long toEquiv[UPPERLIMIT];
  long NODESrecordID;
  long nodeList[50];
  long fromNODESrecordID;
  long toNODESrecordID;
  long deadheadTime;
  BOOL bFound;
  int  rcode2;
  int  numNodes;
  int  nI;
  int  nJ;
  int  nK;
  int  nL;
  int  nM;
  int  pos;
  int  numFromEquiv;
  int  numToEquiv;
  int  numFromTo;
  int  numFrom;
  int  numTo;
  int  serviceIndex;

//
//  Set up the service index
//
  SERVICESKey0.recordID = SERVICESrecordID;
  btrieve(B_GETEQUAL, TMS_SERVICES, &SERVICES, &SERVICESKey0, 0);
  serviceIndex = SERVICES.number - 1;
  if(serviceIndex < 0 || serviceIndex > NODES_RELIEFLABELS_LENGTH - 1)
  {
    serviceIndex = 0;
  }
  strncpy(szarString, SERVICES.name, SERVICES_NAME_LENGTH);
  trim(szarString, SERVICES_NAME_LENGTH);
//
//  Show the status bar
//
  if(bDisplayStatus)
  {
    sprintf(tempString, "Status for service %s", szarString);
    StatusBarStart(NULL, tempString);
    LoadString(hInst, TEXT_135, tempString, TEMPSTRING_LENGTH);
    StatusBarText(tempString);
  }
//
//  Set up the node equivalences
//
  rcode2 = btrieve(B_GETFIRST, TMS_CONNECTIONS, &CONNECTIONS, &CONNECTIONSKey0, 0);
  numNodeEquiv = 0;
  while(rcode2 == 0 && numNodeEquiv < MAXNODEEQUIV)
  {
    if(CONNECTIONS.flags & CONNECTIONS_FLAG_EQUIVALENT)
    {
      NODEEQUIV[numNodeEquiv].fromNODESrecordID = CONNECTIONS.fromNODESrecordID;
      NODEEQUIV[numNodeEquiv].toNODESrecordID = CONNECTIONS.toNODESrecordID;
      numNodeEquiv++;
    }
    rcode2 = btrieve(B_GETNEXT, TMS_CONNECTIONS, &CONNECTIONS, &CONNECTIONSKey0, 0);
  }
//
//  Set up, along with all garages, all relief points
//
  rcode2 = btrieve(B_GETFIRST, TMS_NODES, &NODES, &NODESKey0, 0);
  numNodes = 0;
  while(rcode2 == 0)
  {
    if(NODES.flags & NODES_FLAG_GARAGE ||
          (NODES.reliefLabels[serviceIndex] != ' ' && NODES.reliefLabels[serviceIndex] != '-'))
    {
      nodeList[numNodes] = NODES.recordID;
      numNodes++;
    }
    rcode2 = btrieve(B_GETNEXT, TMS_NODES, &NODES, &NODESKey0, 0);
  }
//
//  Free any previous incarnation of the travel matrix
//
  for(nI = 0; nI < numInTM[serviceIndex]; nI++)
  {
    TMSHeapFree(TRAVELMATRIX[serviceIndex][nI].pTrips);
  }
//
//  Build the matrix
//
  numInTM[serviceIndex] = 0;
  for(nI = 0; nI < numNodes - 1; nI++)
  {
    if(bDisplayStatus)
    {
      StatusBar((long)nI, (long)numNodes);
    }
    for(nJ = 1; nJ < numNodes; nJ++)
    {
      for(nK = 0; nK < 2; nK++)
      {
        fromNODESrecordID = nK == 0 ? nodeList[nI] : nodeList[nJ];
        toNODESrecordID = nK == 0 ? nodeList[nJ] : nodeList[nI];
//
//  Get the node equivalences from the NODEEQUIV structure
//
        numFromEquiv = 0;
        numToEquiv = 0;
        for(nL = 0; nL < numNodeEquiv; nL++)
        {
          if(NODEEQUIV[nL].fromNODESrecordID == fromNODESrecordID)
          {
            fromEquiv[numFromEquiv++] = NODEEQUIV[nL].toNODESrecordID;
          }
          else if(NODEEQUIV[nL].toNODESrecordID == fromNODESrecordID)
          {
            fromEquiv[numFromEquiv++] = NODEEQUIV[nL].fromNODESrecordID;
          }
          else if(NODEEQUIV[nL].fromNODESrecordID == toNODESrecordID)
          {
            toEquiv[numToEquiv++] = NODEEQUIV[nL].toNODESrecordID;
          }
          else if(NODEEQUIV[nL].toNODESrecordID == toNODESrecordID)
          {
            toEquiv[numToEquiv++] = NODEEQUIV[nL].fromNODESrecordID;
          }
        }
//
//  Ok, we know where we are (fromNODESrecordID) and where we have to go to (toNODESrecordID).
//
//  The algorithm is find the route required to get us from a to b in the shortest time,
//  placing instructions in "travelInstructions".
//
//  First, get a list of patterns that fromNODESrecordID (or one of its equivalences) reside in.
//  Note that we keep PATTERNS.NODESrecordID, as it may actually be the substituted, equivalent, node.
//
        numFrom = 0;
        for(nL = 0; nL < numFromEquiv + 1; nL++)
        {
          NODESrecordID = nL == 0 ? fromNODESrecordID : fromEquiv[nL - 1];
          PATTERNSKey1.NODESrecordID = NODESrecordID;
          rcode2 = btrieve(B_GETEQUAL, TMS_PATTERNS, &PATTERNS, &PATTERNSKey1, 1);
          while(rcode2 == 0 && PATTERNS.NODESrecordID == NODESrecordID)
          {
            if(PATTERNS.SERVICESrecordID == SERVICESrecordID)
            {
              from[numFrom].NODESrecordID = PATTERNS.NODESrecordID;
              from[numFrom].ROUTESrecordID = PATTERNS.ROUTESrecordID;
              from[numFrom].directionIndex = PATTERNS.directionIndex;
              from[numFrom].PATTERNNAMESrecordID = PATTERNS.PATTERNNAMESrecordID;
              from[numFrom].nodeSequence = PATTERNS.nodeSequence;
              numFrom++;
            }
            rcode2 = btrieve(B_GETNEXT, TMS_PATTERNS, &PATTERNS, &PATTERNSKey1, 1);
          }
        }
//
//  If there weren't any, cycle through
//
        if(numFrom == 0)
        {
          continue;
        }
//
//  Now, get a list of patterns that toNODESrecordID are in.
//
        numTo = 0;
        for(nL = 0; nL < numToEquiv + 1; nL++)
        {
          NODESrecordID = nL == 0 ? toNODESrecordID : toEquiv[nL - 1];
          PATTERNSKey1.NODESrecordID = NODESrecordID;
          rcode2 = btrieve(B_GETEQUAL, TMS_PATTERNS, &PATTERNS, &PATTERNSKey1, 1);
          while(rcode2 == 0 && PATTERNS.NODESrecordID == NODESrecordID)
          {
            if(PATTERNS.SERVICESrecordID == SERVICESrecordID)
            {
              to[numTo].NODESrecordID = PATTERNS.NODESrecordID;
              to[numTo].ROUTESrecordID = PATTERNS.ROUTESrecordID;
              to[numTo].directionIndex = PATTERNS.directionIndex;
              to[numTo].PATTERNNAMESrecordID = PATTERNS.PATTERNNAMESrecordID;
              to[numTo].nodeSequence = PATTERNS.nodeSequence;
              numTo++;
            }
            rcode2 = btrieve(B_GETNEXT, TMS_PATTERNS, &PATTERNS, &PATTERNSKey1, 1);
          }
        }
//
//  If there weren't any, cycle through
//
        if(numTo == 0)
          continue;
//
//  Develop a list of patterns that have both the from and to nodes
//  on them, and that have the "to" node following the "from" node.
//
//  First, "merge" the lists
//
        numFromTo = 0;
        for(nL = 0; nL < numFrom; nL++)
        {
          for(nM = 0; nM < numTo; nM++)
          {
            if(from[nL].ROUTESrecordID == to[nM].ROUTESrecordID &&
                  from[nL].directionIndex == to[nM].directionIndex &&
                  from[nL].PATTERNNAMESrecordID == to[nM].PATTERNNAMESrecordID &&
                  from[nL].nodeSequence < to[nM].nodeSequence)
            {
              fromTo[numFromTo].fromNODESrecordID = from[nL].NODESrecordID;
              fromTo[numFromTo].toNODESrecordID = to[nM].NODESrecordID;
              fromTo[numFromTo].ROUTESrecordID = from[nL].ROUTESrecordID;
              fromTo[numFromTo].directionIndex = from[nL].directionIndex;
              fromTo[numFromTo].PATTERNNAMESrecordID = from[nL].PATTERNNAMESrecordID;
              fromTo[numFromTo].fromNodePos = NO_RECORD;
              fromTo[numFromTo].toNodePos = NO_RECORD;
              numFromTo++;
            }
          }
        }
//
//  Did we get any?
//
        if(numFromTo == 0)
          continue;
//
//  Second, establish fromNodePos and toNodePos so we
//  know where to look on the tripTimes array later on
//
        for(nL = 0; nL < numFromTo; nL++)
        {
          PATTERNSKey2.ROUTESrecordID = fromTo[nL].ROUTESrecordID;
          PATTERNSKey2.SERVICESrecordID = SERVICESrecordID;
          PATTERNSKey2.directionIndex = fromTo[nL].directionIndex;
          PATTERNSKey2.PATTERNNAMESrecordID = fromTo[nL].PATTERNNAMESrecordID;
          PATTERNSKey2.nodeSequence = NO_RECORD;
          rcode2 = btrieve(B_GETGREATER, TMS_PATTERNS, &PATTERNS, &PATTERNSKey2, 2);
          pos = 0;
          while(rcode2 == 0 &&
                PATTERNS.ROUTESrecordID == fromTo[nL].ROUTESrecordID &&
                PATTERNS.SERVICESrecordID == SERVICESrecordID &&
                PATTERNS.directionIndex == fromTo[nL].directionIndex &&
                PATTERNSKey2.PATTERNNAMESrecordID == fromTo[nL].PATTERNNAMESrecordID)
          {
            if(!(PATTERNS.flags & PATTERNS_FLAG_BUSSTOP))
            {
              if(PATTERNS.NODESrecordID == fromTo[nL].fromNODESrecordID &&
                    fromTo[nL].fromNodePos == NO_RECORD)
              {
                fromTo[nL].fromNodePos = pos;
              }
              else if(PATTERNS.NODESrecordID == fromTo[nL].toNODESrecordID &&
                    fromTo[nL].toNodePos == NO_RECORD)
              {
                fromTo[nL].toNodePos = pos;
                break;
              }
              pos++;
            }
            rcode2 = btrieve(B_GETNEXT, TMS_PATTERNS, &PATTERNS, &PATTERNSKey2, 2);
          } 
        }
//
//  Build the matrix
//
        TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].fromNODESrecordID = fromNODESrecordID; // nodeList[nI];
        TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].toNODESrecordID = toNODESrecordID; // nodeList[nJ];
        TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips = 
              (TMTRIPSDef *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TMTRIPSDef) * 50); 
        if(TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips == NULL)
        {
          AllocationError(__FILE__, __LINE__, FALSE);
          return;
        }
        TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].currentAlloc = 50;
        TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].numTrips = 0;
        for(nL = 0; nL < numFromTo; nL++)
        {
          TRIPSKey1.ROUTESrecordID = fromTo[nL].ROUTESrecordID;
          TRIPSKey1.SERVICESrecordID = SERVICESrecordID;
          TRIPSKey1.directionIndex = fromTo[nL].directionIndex;
          TRIPSKey1.tripSequence = NO_RECORD;
          rcode2 = btrieve(B_GETGREATEROREQUAL, TMS_TRIPS, &TRIPS, &TRIPSKey1, 1);
          while(rcode2 == 0 &&
                TRIPS.ROUTESrecordID == fromTo[nL].ROUTESrecordID &&
                TRIPS.SERVICESrecordID == SERVICESrecordID &&
                TRIPS.directionIndex == fromTo[nL].directionIndex)
          {
            if(TRIPS.PATTERNNAMESrecordID == fromTo[nL].PATTERNNAMESrecordID)
            {
              GenerateTrip(TRIPS.ROUTESrecordID, TRIPS.SERVICESrecordID,
                    TRIPS.directionIndex, TRIPS.PATTERNNAMESrecordID,
                    TRIPS.timeAtMLP, GENERATETRIP_FLAG_DISPLAYERRORS, &GTResults);
              nM = TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].numTrips;
              TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips[nM].TRIPSrecordID = TRIPS.recordID;
              TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips[nM].tripTime[0] = GTResults.tripTimes[fromTo[nL].fromNodePos];
              TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips[nM].tripTime[1] = GTResults.tripTimes[fromTo[nL].toNodePos];
              TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].numTrips++;
              if(TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].numTrips >= TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].currentAlloc)
              {
                TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].currentAlloc += 50;
                TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips = 
                      (TMTRIPSDef *)HeapReAlloc(GetProcessHeap(),
                      HEAP_ZERO_MEMORY, TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips,
                      sizeof(TMTRIPSDef) * TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].currentAlloc); 
                if(TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips == NULL)
                {
                  AllocationError(__FILE__, __LINE__, TRUE);
                  return;
                }
              }
            }
            rcode2 = btrieve(B_GETNEXT, TMS_TRIPS, &TRIPS, &TRIPSKey1, 1);
          }
//
//  Pass 2 - check on pullouts and pullins
//
          rcode2 = btrieve(B_GETFIRST, TMS_TRIPS, &TRIPS, &TRIPSKey2, 2);
          while(rcode2 == 0)
          {
//
//  Pullout
//
            if(TRIPS.SERVICESrecordID == SERVICESrecordID &&
                  TRIPS.standard.POGNODESrecordID == fromNODESrecordID)
            {
              PATTERNSKey1.NODESrecordID = toNODESrecordID;
              rcode2 = btrieve(B_GETEQUAL, TMS_PATTERNS, &PATTERNS, &PATTERNSKey1, 1);
              bFound = FALSE;
              while(rcode2 == 0 && PATTERNS.NODESrecordID == toNODESrecordID)
              {
                if(PATTERNS.ROUTESrecordID == TRIPS.ROUTESrecordID &&
                      PATTERNS.SERVICESrecordID == TRIPS.SERVICESrecordID &&
                      PATTERNS.directionIndex == TRIPS.directionIndex &&
                      PATTERNS.PATTERNNAMESrecordID == TRIPS.PATTERNNAMESrecordID)
                {
                  bFound = TRUE;
                  break;
                }
                rcode2 = btrieve(B_GETNEXT, TMS_PATTERNS, &PATTERNS, &PATTERNSKey1, 1);
              }
              if(bFound)
              {
                PATTERNSKey2.ROUTESrecordID = TRIPS.ROUTESrecordID;
                PATTERNSKey2.SERVICESrecordID = TRIPS.SERVICESrecordID;
                PATTERNSKey2.directionIndex = TRIPS.directionIndex;
                PATTERNSKey2.PATTERNNAMESrecordID = TRIPS.PATTERNNAMESrecordID;
                PATTERNSKey2.nodeSequence = NO_RECORD;
                rcode2 = btrieve(B_GETGREATER, TMS_PATTERNS, &PATTERNS, &PATTERNSKey2, 2);
                pos = 0;
                while(rcode2 == 0 &&
                      PATTERNS.ROUTESrecordID == TRIPS.ROUTESrecordID &&
                      PATTERNS.SERVICESrecordID == TRIPS.SERVICESrecordID &&
                      PATTERNS.directionIndex == TRIPS.directionIndex &&
                      PATTERNSKey2.PATTERNNAMESrecordID == TRIPS.PATTERNNAMESrecordID)
                {
                  if(!(PATTERNS.flags & PATTERNS_FLAG_BUSSTOP))
                  {
                    if(PATTERNS.NODESrecordID == toNODESrecordID)
                      break;
                    pos++;
                  }
                  rcode2 = btrieve(B_GETNEXT, TMS_PATTERNS, &PATTERNS, &PATTERNSKey2, 2);
                } 
                GenerateTrip(TRIPS.ROUTESrecordID, TRIPS.SERVICESrecordID,
                      TRIPS.directionIndex, TRIPS.PATTERNNAMESrecordID,
                      TRIPS.timeAtMLP, GENERATETRIP_FLAG_DISPLAYERRORS, &GTResults);
                GCTData.fromPATTERNNAMESrecordID = TRIPS.PATTERNNAMESrecordID;
                GCTData.toPATTERNNAMESrecordID = TRIPS.PATTERNNAMESrecordID;
                GCTData.fromROUTESrecordID = TRIPS.ROUTESrecordID;
                GCTData.fromSERVICESrecordID = TRIPS.SERVICESrecordID;
                GCTData.toROUTESrecordID = TRIPS.ROUTESrecordID;
                GCTData.toSERVICESrecordID = TRIPS.SERVICESrecordID;
                GCTData.fromNODESrecordID = TRIPS.standard.POGNODESrecordID;
                GCTData.toNODESrecordID = GTResults.firstNODESrecordID;
                GCTData.timeOfDay = GTResults.firstNodeTime;
                deadheadTime = GetConnectionTime(GCT_FLAG_DEADHEADTIME, &GCTData, &distance);
                distance = (float)fabs((double)distance);
                if(deadheadTime != NO_RECORD)
                {
                  nM = TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].numTrips;
                  TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips[nM].TRIPSrecordID = TRIPS.recordID;
                  TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips[nM].tripTime[0] = GTResults.firstNodeTime - deadheadTime;
                  TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips[nM].tripTime[1] = GTResults.tripTimes[pos];
                  TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].numTrips++;
                  if(TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].numTrips >= TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].currentAlloc)
                  {
                    TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].currentAlloc += 50;
                    TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips = 
                          (TMTRIPSDef *)HeapReAlloc(GetProcessHeap(),
                          HEAP_ZERO_MEMORY, TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips,
                          sizeof(TMTRIPSDef) * TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].currentAlloc); 
                    if(TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips == NULL)
                    {
                      AllocationError(__FILE__, __LINE__, FALSE);
                      return;
                    }
                  }
                }
              }
            }
//
//  Pullin
//
            if(TRIPS.SERVICESrecordID == SERVICESrecordID &&
                  TRIPS.standard.PIGNODESrecordID == toNODESrecordID)
            {
              PATTERNSKey1.NODESrecordID = fromNODESrecordID;
              rcode2 = btrieve(B_GETEQUAL, TMS_PATTERNS, &PATTERNS, &PATTERNSKey1, 1);
              bFound = FALSE;
              while(rcode2 == 0 && PATTERNS.NODESrecordID == fromNODESrecordID)
              {
                if(PATTERNS.ROUTESrecordID == TRIPS.ROUTESrecordID &&
                      PATTERNS.SERVICESrecordID == TRIPS.SERVICESrecordID &&
                      PATTERNS.directionIndex == TRIPS.directionIndex &&
                      PATTERNS.PATTERNNAMESrecordID == TRIPS.PATTERNNAMESrecordID)
                {
                  bFound = TRUE;
                  break;
                }
                rcode2 = btrieve(B_GETNEXT, TMS_PATTERNS, &PATTERNS, &PATTERNSKey1, 1);
              }
              if(bFound)
              {
                PATTERNSKey2.ROUTESrecordID = TRIPS.ROUTESrecordID;
                PATTERNSKey2.SERVICESrecordID = TRIPS.SERVICESrecordID;
                PATTERNSKey2.directionIndex = TRIPS.directionIndex;
                PATTERNSKey2.PATTERNNAMESrecordID = TRIPS.PATTERNNAMESrecordID;
                PATTERNSKey2.nodeSequence = NO_RECORD;
                rcode2 = btrieve(B_GETGREATER, TMS_PATTERNS, &PATTERNS, &PATTERNSKey2, 2);
                pos = 0;
                while(rcode2 == 0 &&
                      PATTERNS.ROUTESrecordID == TRIPS.ROUTESrecordID &&
                      PATTERNS.SERVICESrecordID == TRIPS.SERVICESrecordID &&
                      PATTERNS.directionIndex == TRIPS.directionIndex &&
                      PATTERNSKey2.PATTERNNAMESrecordID == TRIPS.PATTERNNAMESrecordID)
                {
                  if(!(PATTERNS.flags & PATTERNS_FLAG_BUSSTOP))
                  {
                    if(PATTERNS.NODESrecordID == fromNODESrecordID)
                      break;
                    pos++;
                  }
                  rcode2 = btrieve(B_GETNEXT, TMS_PATTERNS, &PATTERNS, &PATTERNSKey2, 2);
                } 
                GenerateTrip(TRIPS.ROUTESrecordID, TRIPS.SERVICESrecordID,
                      TRIPS.directionIndex, TRIPS.PATTERNNAMESrecordID,
                      TRIPS.timeAtMLP, GENERATETRIP_FLAG_DISPLAYERRORS, &GTResults);
                GCTData.fromPATTERNNAMESrecordID = TRIPS.PATTERNNAMESrecordID;
                GCTData.toPATTERNNAMESrecordID = TRIPS.PATTERNNAMESrecordID;
                GCTData.fromROUTESrecordID = TRIPS.ROUTESrecordID;
                GCTData.fromSERVICESrecordID = TRIPS.SERVICESrecordID;
                GCTData.toROUTESrecordID = TRIPS.ROUTESrecordID;
                GCTData.toSERVICESrecordID = TRIPS.SERVICESrecordID;
                GCTData.fromNODESrecordID = GTResults.lastNODESrecordID;
                GCTData.toNODESrecordID = TRIPS.standard.PIGNODESrecordID;
                GCTData.timeOfDay = GTResults.lastNodeTime;
                deadheadTime = GetConnectionTime(GCT_FLAG_DEADHEADTIME, &GCTData, &distance);
                distance = (float)fabs((double)distance);
                if(deadheadTime != NO_RECORD)
                {
                  nM = TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].numTrips;
                  TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips[nM].TRIPSrecordID = TRIPS.recordID;
                  TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips[nM].tripTime[0] = GTResults.tripTimes[pos];
                  TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips[nM].tripTime[1] = GTResults.lastNodeTime + deadheadTime;
                  TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].numTrips++;
                  if(TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].numTrips >= TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].currentAlloc)
                  {
                    TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].currentAlloc += 50;
                    TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips = 
                          (TMTRIPSDef *)HeapReAlloc(GetProcessHeap(),
                          HEAP_ZERO_MEMORY, TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips,
                          sizeof(TMTRIPSDef) * TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].currentAlloc); 
                    if(TRAVELMATRIX[serviceIndex][numInTM[serviceIndex]].pTrips == NULL)
                    {
                      AllocationError(__FILE__, __LINE__, FALSE);
                      return;
                    }
                  }
                }
              }
            }
            rcode2 = btrieve(B_GETNEXT, TMS_TRIPS, &TRIPS, &TRIPSKey2, 2);
          }
        }// nL
        numInTM[serviceIndex]++;
      }  // nK
    }    // nJ
  }      // nI
  if(bDisplayStatus)
  {
    StatusBar((long)numNodes, (long)numNodes);
    StatusBarEnd();
  }
}
Ejemplo n.º 12
0
void CCCFrontEnd::PopulateListCtrl()
{
//
//  Populate the list control
//
  CString s;
  LVITEM LVI;
  char   dummy[256];
  int    rcode2;
  int    nI;

  pListCtrlLIST->DeleteAllItems();

  rcode2 = btrieve(B_STAT, TMS_COMPLAINTS, &BSTAT, dummy, 0);
  if(rcode2 != 0 || BSTAT.numRecords == 0)
  {
    pButtonEXISTING->EnableWindow(FALSE);
  }
  else
  {
    if(BSTAT.numRecords > 0)
    {
      pCCFESORT = (CCFESORTDef *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CCFESORTDef) * BSTAT.numRecords); 
      if(pCCFESORT == NULL)
      {
        bAllowSort = FALSE;
        pButtonEXISTING->EnableWindow(FALSE);
        AllocationError(__FILE__, __LINE__, FALSE);
      }
      else
      {
        bAllowSort = TRUE;
        pListCtrlLIST->SetItemCount((int)BSTAT.numRecords);
        rcode2 = btrieve(B_GETFIRST, TMS_COMPLAINTS, &COMPLAINTS, &COMPLAINTSKey2, 2);
        for(nI = 0; nI < BSTAT.numRecords; nI++)
        {
          if(!((COMPLAINTS.flags & COMPLAINTS_FLAG_CANCELLED) && !m_bDisplayCancelled))
          {
            strncpy(tempString, COMPLAINTS.referenceNumber, COMPLAINTS_REFERENCENUMBER_LENGTH);
            trim(tempString, COMPLAINTS_REFERENCENUMBER_LENGTH);
//
//  Reference number
//
            LVI.mask = LVIF_TEXT;
            LVI.iItem = nI;
            LVI.iSubItem = 0;
            LVI.pszText = tempString;
            if(bAllowSort)
            {
              strcpy(pCCFESORT[nI].szReferenceNumber, tempString);
              LVI.mask |= LVIF_PARAM;
              LVI.lParam = (LPARAM)&pCCFESORT[nI];
            }
            LVI.iItem = pListCtrlLIST->InsertItem(&LVI);
//
//  Status
//
            LVI.mask = LVIF_TEXT;
            LVI.iSubItem = 1;
            if(COMPLAINTS.flags & COMPLAINTS_FLAG_CLOSED)
            {
              s.LoadString(TEXT_230);
            }
            else if(COMPLAINTS.flags & COMPLAINTS_FLAG_CANCELLED)
            {
              s.LoadString(TEXT_231);
            }
            else
            {
              s.LoadString(TEXT_229);
            }
            strcpy(tempString, s);
            LVI.pszText = tempString;
            if(bAllowSort)
            {
              strcpy(pCCFESORT[nI].szStatus, tempString);
            }
            pListCtrlLIST->SetItem(&LVI);
//
//  Name
//
            if(COMPLAINTS.CUSTOMERSrecordID == NO_RECORD)
            {
              s.LoadString(TEXT_237);
              strcpy(tempString, s);
            }
            else
            {
              CUSTOMERSKey0.recordID = COMPLAINTS.CUSTOMERSrecordID;
              btrieve(B_GETEQUAL, TMS_CUSTOMERS, &CUSTOMERS, &CUSTOMERSKey0, 0);
              strncpy(tempString, CUSTOMERS.lastName, CUSTOMERS_LASTNAME_LENGTH);
              trim(tempString, CUSTOMERS_LASTNAME_LENGTH);
              strcat(tempString, ", ");
              strncpy(szarString, CUSTOMERS.firstName, CUSTOMERS_FIRSTNAME_LENGTH);
              trim(szarString, CUSTOMERS_FIRSTNAME_LENGTH);
              strcat(tempString, szarString);
            }
            LVI.mask = LVIF_TEXT;
            LVI.iSubItem = 2;
            LVI.pszText = tempString;
            if(bAllowSort)
            {
              strcpy(pCCFESORT[nI].szName, tempString);
            }
            pListCtrlLIST->SetItem(&LVI);
          }
          rcode2 = btrieve(B_GETNEXT, TMS_COMPLAINTS, &COMPLAINTS, &COMPLAINTSKey2, 2);
        }
      }
    }
  }
}
Ejemplo n.º 13
0
BOOL CCCFrontEnd::OnInitDialog() 
{
 	CDialog::OnInitDialog();

  CString s;
//
//  Default to no display of cancelled records
//
  m_bDisplayCancelled = FALSE;
//
//  Make all future memory pointers NULL
//
  pCCFESORT = NULL;
  CCFE.pCCREFER = NULL;
//
//  Set up the pointers to the controls
//
  pButtonNEW = (CButton *)GetDlgItem(CCFE_NEW);
  pButtonEXISTING = (CButton *)GetDlgItem(CCFE_EXISTING);
  pListCtrlLIST = (CListCtrl *)GetDlgItem(CCFE_LIST);
  pButtonTHISISA = (CButton *)GetDlgItem(CCFE_THISISA);
 	pWndDATETIME = GetDlgItem(CCFE_DATETIME);
  pWndRECEIVEDBY = GetDlgItem(CCFE_RECEIVEDBY);
  pButtonCOMPLAINT = (CButton *)GetDlgItem(CCFE_COMPLAINT);
  pButtonCOMMENDATION = (CButton *)GetDlgItem(CCFE_COMMENDATION);
  pButtonSERVICEREQUEST = (CButton *)GetDlgItem(CCFE_SERVICEREQUEST);
  pButtonMISCELLANEOUS = (CButton *)GetDlgItem(CCFE_MISCELLANEOUS);
  pStaticJUMPTO_TEXT = (CStatic *)GetDlgItem(CCFE_JUMPTO_TEXT);
  pEditJUMPTO = (CEdit *)GetDlgItem(CCFE_JUMPTO);
  pButtonDISPLAYCANCELLED = (CButton *)GetDlgItem(CCFE_DISPLAYCANCELLED);
  pButtonREOPEN = (CButton *)GetDlgItem(IDREOPEN);

  DWORD dwExStyles = pListCtrlLIST->GetExtendedStyle();
  pListCtrlLIST->SetExtendedStyle(dwExStyles | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_INFOTIP);
//
//  Set up the characters that the "referenceNumber" is prefixed by
//
//  Complaint, Commendation, or Service Request
//
  strncpy(cPrefix, "CMSL", 4);
//
//  Get the current date and time and put it on the group box
//  
  CTime time = CTime::GetCurrentTime();
 	CString strTime = time.Format(_T("%A, %B %d, %Y at %I:%M:%S%p"));
//
//  Set up the timer to update the date/time
//
  pWndDATETIME->SetWindowText(strTime);
 	pWndDATETIME->SetTimer(0x1000, 1000, TimerProc);
//
//  Display the user name
//
  pWndRECEIVEDBY->SetWindowText(userName);
//
//  Set up the list control
//
  LVCOLUMN LVC;
  LVC.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
  LVC.fmt = LVCFMT_LEFT;
  LVC.cx = 100;
  LVC.pszText = "Number";
  pListCtrlLIST->InsertColumn(0, &LVC);
  LVC.cx = 100;
  LVC.pszText = "Status";
  pListCtrlLIST->InsertColumn(1, &LVC);
  LVC.cx = 300;
  LVC.pszText = "Name";
  pListCtrlLIST->InsertColumn(2, &LVC);
  bSortForward[0] = TRUE;
  bSortForward[1] = TRUE;
  bSortForward[2] = TRUE;
  PopulateListCtrl();
//
//  Disable the list control for now
//
  pListCtrlLIST->EnableWindow(FALSE);
  pStaticJUMPTO_TEXT->EnableWindow(FALSE);
  pEditJUMPTO->EnableWindow(FALSE);

  pButtonNEW->SetCheck(TRUE);
  pButtonCOMPLAINT->SetCheck(TRUE);
  pButtonCOMPLAINT->SetFocus();
//
//  Set up the referral structure
//
  int nI;

  CCFE.numReferrals = m_numReferrals;

  if(m_numReferrals == 0)
  {
    CCFE.pCCREFER = NULL;
  }
  else
  {
    CCFE.pCCREFER = (CCREFERDef *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CCREFERDef) * m_numReferrals); 
    if(CCFE.pCCREFER == NULL)
    {
      AllocationError(__FILE__, __LINE__, FALSE);
    }
    else
    {
      for(nI = 0; nI < m_numReferrals; nI++)
      {
        strcpy(CCFE.pCCREFER[nI].szName, m_Referrals[nI].szName);
        strcpy(CCFE.pCCREFER[nI].szDepartment, m_Referrals[nI].szDepartment);
        strcpy(CCFE.pCCREFER[nI].szEmailAddress, m_Referrals[nI].szEmailAddress);
        CCFE.pCCREFER[nI].flags = 0;
      }
    }
  }

  ReleaseCapture();


 	return FALSE;  // return TRUE unless you set the focus to a control
                 // EXCEPTION: OCX Property Pages should return FALSE
}
Ejemplo n.º 14
0
BOOL CStopConnection::OnInitDialog() 
{
	CDialog::OnInitDialog();

//
//  Set up the pointers to the controls
//	
  pListCtrlFROM = (CListCtrl *)GetDlgItem(STOPCONNECTION_FROM);
  pListCtrlTO = (CListCtrl *)GetDlgItem(STOPCONNECTION_TO);
  pEditDISTANCE = (CEdit *)GetDlgItem(STOPCONNECTION_DISTANCE);
  pStaticMEASURE = (CStatic *)GetDlgItem(STOPCONNECTION_MEASURE);
  pButtonNA = (CButton *)GetDlgItem(STOPCONNECTION_NA);
  pButtonCC = (CButton *)GetDlgItem(STOPCONNECTION_CC);
  pComboBoxCOMMENTCODE = (CComboBox *)GetDlgItem(STOPCONNECTION_COMMENTCODE);

  DWORD dwExStyles = pListCtrlFROM->GetExtendedStyle();
  pListCtrlFROM->SetExtendedStyle(dwExStyles | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_INFOTIP);
  dwExStyles = pListCtrlTO->GetExtendedStyle();
  pListCtrlTO->SetExtendedStyle(dwExStyles | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_INFOTIP);

  pStaticMEASURE->SetWindowText(distanceMeasure == PREFERENCES_MILES ? "miles" : "km");
//
//  Display the hourglass
//
  HCURSOR hCursor = SetCursor(hCursorWait);
//
//  Set up the list controls
//
  LVCOLUMN LVC;
  LVC.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
  LVC.fmt = LVCFMT_LEFT;
  LVC.cx = 50;
  LVC.pszText = "Abbr";
  pListCtrlFROM->InsertColumn(0, &LVC);
  pListCtrlTO->InsertColumn(0, &LVC);
  LVC.cx = 400;
  LVC.pszText = "Address / Intersection";
  pListCtrlFROM->InsertColumn(1, &LVC);
  pListCtrlTO->InsertColumn(1, &LVC);
  bSortForwardFrom[0] = TRUE;
  bSortForwardFrom[1] = TRUE;
  bSortForwardTo[0] = TRUE;
  bSortForwardTo[1] = TRUE;
//
//  Populate the list controls
//
  LVITEM LVI;
  char   dummy[256];
  int    rcode2;
  int    nI;

  rcode2 = btrieve(B_STAT, TMS_NODES, &BSTAT, dummy, 0);
  if(rcode2 != 0 || BSTAT.numRecords == 0)
  {
    BSTAT.numRecords = 1000;
  }
  m_pSCSORT = (SCSORTDef *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SCSORTDef) * BSTAT.numRecords); 
  if(m_pSCSORT == NULL)
  {
    AllocationError(__FILE__, __LINE__, TRUE);
  }
  m_bAllowSort = m_pSCSORT != NULL;
  pListCtrlFROM->SetItemCount((int)BSTAT.numRecords);
  pListCtrlTO->SetItemCount((int)BSTAT.numRecords);
  rcode2 = btrieve(B_GETFIRST, TMS_NODES, &NODES, &NODESKey2, 2);
  int selectedFrom = NO_RECORD;
  int selectedTo = NO_RECORD;
  for(nI = 0; nI < BSTAT.numRecords; nI++)
  {
    if(rcode2 != 0)
    {
      break;
    }
    strncpy(tempString, NODES.abbrName, NODES_ABBRNAME_LENGTH);
    trim(tempString, NODES_ABBRNAME_LENGTH);
    LVI.mask = LVIF_TEXT;
    LVI.iItem = nI;
    LVI.iSubItem = 0;
    LVI.pszText = tempString;
    if(m_bAllowSort)
    {
      m_pSCSORT[nI].NODESrecordID = NODES.recordID;
      strcpy(m_pSCSORT[nI].abbrName, tempString);
      LVI.mask |= LVIF_PARAM;
      LVI.lParam = (LPARAM)&m_pSCSORT[nI];
    }
    LVI.iItem = pListCtrlFROM->InsertItem(&LVI);
    LVI.iItem = pListCtrlTO->InsertItem(&LVI);
    strncpy(tempString, NODES.intersection, NODES_INTERSECTION_LENGTH);
    trim(tempString, NODES_INTERSECTION_LENGTH);
    LVI.mask = LVIF_TEXT;
    LVI.iSubItem = 1;
    LVI.pszText = tempString;
    if(m_bAllowSort)
    {
      strcpy(m_pSCSORT[nI].intersection, tempString);
    }
    pListCtrlFROM->SetItem(&LVI);
    pListCtrlTO->SetItem(&LVI);
    if(m_pCONNECTIONS->fromNODESrecordID == NODES.recordID)
    {
      selectedFrom = nI;
    }
    if(m_pCONNECTIONS->toNODESrecordID == NODES.recordID)
    {
      selectedTo = nI;
    }
    rcode2 = btrieve(B_GETNEXT, TMS_NODES, &NODES, &NODESKey2, 2);
  }
//
//  Highlight any selections
//
  if(selectedFrom != NO_RECORD)
  {
    ListView_SetItemState(pListCtrlFROM->m_hWnd, selectedFrom, LVIS_SELECTED, LVIS_SELECTED);
    pListCtrlFROM->EnsureVisible(selectedFrom, TRUE);
  }
  if(selectedTo != NO_RECORD)
  {
    ListView_SetItemState(pListCtrlTO->m_hWnd, selectedTo, LVIS_SELECTED, LVIS_SELECTED);
    pListCtrlTO->EnsureVisible(selectedTo, TRUE);
  }
//
//  Set the distance
//
  sprintf(tempString, "%5.2f", m_pCONNECTIONS->distance);
  pEditDISTANCE->SetWindowText(tempString);
//
//  And the Comment
//
  int  numComments;
  BOOL bFound;
  
  numComments = SetUpCommentList(m_hWnd, STOPCONNECTION_COMMENTCODE);
  if(numComments == 0)
  {
    pButtonCC->EnableWindow(FALSE);
    pComboBoxCOMMENTCODE->EnableWindow(FALSE);
  }
  for(bFound = FALSE, nI = 0; nI < numComments; nI++)
  {
    if(pComboBoxCOMMENTCODE->GetItemData(nI) == (DWORD)m_pCONNECTIONS->COMMENTSrecordID)
    {
      pComboBoxCOMMENTCODE->SetCurSel(nI);
      bFound = TRUE;
      break;
    }
  }
  if(bFound)
  {
    pButtonCC->SetCheck(TRUE);
  }
  else
  {
    pButtonNA->SetCheck(TRUE);
  }
//
//  Restore the cursor and leave
//
  SetCursor(hCursor);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
Ejemplo n.º 15
0
Archivo: DELETERUNS.c Proyecto: ems/TMS
/* Replace this with EM_
void DELETERUNSEvent(VBXEVENT FAR *lpEvent)
{
  switch(lpEvent->ID)
  {
    case DELETERUNS_FROM:
    case DELETERUNS_TO:
      switch(lpEvent->EventIndex)
      {
        case Event_MhIntInput_Change:
          SendDlgItemMessage(hWnd, selection, BM_SETCHECK, (WPARAM)FALSE, (LPARAM)0);
          SendMessage(hCtlFROMTITLE, BM_SETCHECK, (WPARAM)TRUE, (LPARAM)0);
          selection = DELETERUNS_FROMTITLE;
          break;
      }
      break;
  }
}
*/
BOOL CALLBACK DELETERUNSMsgProc(HWND hWndDlg, UINT Message, WPARAM wParam, LPARAM lParam)
{
  PROPOSEDRUNDef PROPOSEDRUN;
  COSTDef COST;
  int     nI;
  int     nJ;
  int     nK;
  int     rcode2;
  long    fromRunNumber;
  long    toRunNumber;
  BOOL    deleteFromFirst;
  BOOL    deleteToLast;
  BOOL    bFinished;
  HCURSOR saveCursor;
  int     numSelected;
  long    thisRun;
  long    recordID;
  int     numPieces;
  long    runType;
  long    runNumber;
  short int wmId;

  int    *pSelections = NULL;

  switch(Message)
  {
//
//  WM_INITDIALOG - Initialize the dialog
//
    case WM_INITDIALOG:
      hWnd = hWndDlg;
      pDI = (PDISPLAYINFO)lParam;
      if(pDI == NULL)
      {
        SendMessage(hWndDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), (LPARAM)0);
        break;
      }
//
//  Set up the handles to the controls
//
      hCtlALL = GetDlgItem(hWndDlg, DELETERUNS_ALL);
      hCtlALLILLEGAL = GetDlgItem(hWndDlg, DELETERUNS_ALLILLEGAL);
      hCtlFROMTITLE = GetDlgItem(hWndDlg, DELETERUNS_FROMTITLE);
      hCtlFROM = GetDlgItem(hWndDlg, DELETERUNS_FROM);
      hCtlTO = GetDlgItem(hWndDlg, DELETERUNS_TO);
      hCtlSPECIFICRUNS = GetDlgItem(hWndDlg, DELETERUNS_SPECIFICRUNS);
      hCtlRUNSOFRUNTYPE = GetDlgItem(hWndDlg, DELETERUNS_RUNSOFRUNTYPE);
      hCtlLISTBOX = GetDlgItem(hWndDlg, DELETERUNS_LISTBOX);
//
//  Default to DELETERUNS_ALL
//
      selection = DELETERUNS_ALL;
      SendMessage(hCtlALL, BM_SETCHECK, (WPARAM)TRUE, (LPARAM)0);
      break;
//
//  WM_CLOSE
//
    case WM_CLOSE:
      SendMessage(hWndDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), (LPARAM)0);
      break;
//
//  WM_COMMAND
//
    case WM_COMMAND:
      wmId = LOWORD(wParam);
      switch(wmId)
      {
//
//  Radio buttons
//
//  DELETERUNS_ALL
//  DELETERUNS_ALLILLEGAL
//  DELETERUNS_FROMTITLE
//  DELETERUNS_SPECIFICRUNS
//  DELETERUNS_RUNSOFRUNTYPE
//
        case DELETERUNS_ALL:
        case DELETERUNS_ALLILLEGAL:
        case DELETERUNS_FROMTITLE:
        case DELETERUNS_SPECIFICRUNS:
        case DELETERUNS_RUNSOFRUNTYPE:
          SendDlgItemMessage(hWndDlg, selection, BM_SETCHECK, (WPARAM)FALSE, (LPARAM)0);
          selection = wmId;
          SendMessage(hCtlLISTBOX, LB_RESETCONTENT, (WPARAM)0, (LPARAM)0);
          EnableWindow(hCtlLISTBOX, (wmId == DELETERUNS_SPECIFICRUNS || wmId == DELETERUNS_RUNSOFRUNTYPE));
//
//  If he clicks FROMTITLE, set the focus to FROM
//
          if(wmId == DELETERUNS_FROMTITLE)
            SetFocus(hCtlFROM);
//
//  Specific runs - get all the runs on this service
//
          else if(wParam == DELETERUNS_SPECIFICRUNS)
          {
            RUNSKey1.DIVISIONSrecordID = pDI->fileInfo.divisionRecordID;
            RUNSKey1.SERVICESrecordID = pDI->fileInfo.serviceRecordID;
            RUNSKey1.runNumber = NO_RECORD;
            RUNSKey1.pieceNumber = NO_RECORD;
            rcode2 = btrieve(B_GETGREATER, TMS_RUNS, &RUNS, &RUNSKey1, 1);
            while(rcode2 == 0 &&
                  RUNS.DIVISIONSrecordID == pDI->fileInfo.divisionRecordID &&
                  RUNS.SERVICESrecordID == pDI->fileInfo.serviceRecordID)
            {
              ltoa(RUNS.runNumber, tempString, 10);
              if(RUNS.pieceNumber == 1)
              {
                nK = SendMessage(hCtlLISTBOX, LB_ADDSTRING, (WPARAM)0, (LONG)(LPSTR)tempString);
                SendMessage(hCtlLISTBOX, LB_SETITEMDATA, (WPARAM)nK, RUNS.runNumber);
              }
              rcode2 = btrieve(B_GETNEXT, TMS_RUNS, &RUNS, &RUNSKey1, 1);
            }
            SetFocus(hCtlLISTBOX);
          }
//
//  Runs of run type - display the active run type names
//
          else if(wParam == DELETERUNS_RUNSOFRUNTYPE)
          {
            for(nI = 0; nI < NUMRUNTYPES; nI++)
              for(nJ = 0; nJ < NUMRUNTYPESLOTS; nJ++)
                if(RUNTYPE[nI][nJ].flags & RTFLAGS_INUSE)
                {
                  nK = SendMessage(hCtlLISTBOX, LB_ADDSTRING,
                        (WPARAM)0, (LONG)(LPSTR)RUNTYPE[nI][nJ].localName);
                  SendMessage(hCtlLISTBOX, LB_SETITEMDATA, (WPARAM)nK, MAKELPARAM(nI, nJ));
                }
            SetFocus(hCtlLISTBOX);
          }
          break;
//
//  IDCANCEL
//
        case IDCANCEL:
          EndDialog(hWndDlg, FALSE);
          break;
//
//  IDOK
//
        case IDOK:
          bFinished = TRUE;
          saveCursor = SetCursor(hCursorWait);
//
//  Process the selection
//
          switch(selection)
          {
//
//  All
//
            case DELETERUNS_ALL:
              RUNSKey1.DIVISIONSrecordID = pDI->fileInfo.divisionRecordID;
              RUNSKey1.SERVICESrecordID = pDI->fileInfo.serviceRecordID;
              RUNSKey1.runNumber = NO_RECORD;
              RUNSKey1.pieceNumber = NO_RECORD;
              rcode2 = btrieve(B_GETGREATER, TMS_RUNS, &RUNS, &RUNSKey1, 1);
              while(rcode2 == 0 &&
                    RUNS.DIVISIONSrecordID == pDI->fileInfo.divisionRecordID &&
                    RUNS.SERVICESrecordID == pDI->fileInfo.serviceRecordID)
              {
                btrieve(B_DELETE, TMS_RUNS, &RUNS, &RUNSKey1, 1);
                rcode2 = btrieve(B_GETNEXT, TMS_RUNS, &RUNS, &RUNSKey1, 1);
              }
              break;
//
//  All illegal runs
//
            case DELETERUNS_ALLILLEGAL:
              RUNSKey1.DIVISIONSrecordID = pDI->fileInfo.divisionRecordID;
              RUNSKey1.SERVICESrecordID = pDI->fileInfo.serviceRecordID;
              RUNSKey1.runNumber = NO_RECORD;
              RUNSKey1.pieceNumber = NO_RECORD;
              rcode2 = btrieve(B_GETGREATER, TMS_RUNS, &RUNS, &RUNSKey1, 1);
              while(rcode2 == 0 &&
                    RUNS.DIVISIONSrecordID == pDI->fileInfo.divisionRecordID &&
                    RUNS.SERVICESrecordID == pDI->fileInfo.serviceRecordID)
              {
                if(RUNS.pieceNumber == 1)
                {
                  recordID = RUNS.recordID;
                  runNumber = RUNS.runNumber;
                  numPieces = GetRunElements(hWnd, &RUNS, &PROPOSEDRUN, &COST, TRUE);
                  RUNSKey0.recordID = recordID;
                  btrieve(B_GETEQUAL, TMS_RUNS, &RUNS, &RUNSKey0, 0);
                  btrieve(B_GETPOSITION, TMS_RUNS, &RUNS, &RUNSKey0, 0);
                  btrieve(B_GETDIRECT, TMS_RUNS, &RUNS, &RUNSKey1, 1);
                  if(RUNSVIEW[numPieces - 1].payTime == 0L)
                  {
                    for(nI = 0; nI < numPieces; nI ++)
                    {
                      btrieve(B_DELETE, TMS_RUNS, &RUNS, &RUNSKey1, 1);
                      btrieve(B_GETNEXT, TMS_RUNS, &RUNS, &RUNSKey1, 1);
                    }
                  }
                }
                RUNSKey1.DIVISIONSrecordID = pDI->fileInfo.divisionRecordID;
                RUNSKey1.SERVICESrecordID = pDI->fileInfo.serviceRecordID;
                RUNSKey1.runNumber = runNumber + 1;
                RUNSKey1.pieceNumber = NO_RECORD;
                rcode2 = btrieve(B_GETGREATER, TMS_RUNS, &RUNS, &RUNSKey1, 1);
              }
              break;
//
//  From run to run
//
            case DELETERUNS_FROMTITLE:
              SendMessage(hCtlFROM, WM_GETTEXT, (WPARAM)TEMPSTRING_LENGTH, (LONG)(LPSTR)tempString);
              if((deleteFromFirst = strcmp(tempString, "") == 0) == FALSE)
                fromRunNumber = atol(tempString);
              SendMessage(hCtlTO, WM_GETTEXT, (WPARAM)TEMPSTRING_LENGTH, (LONG)(LPSTR)tempString);
              if((deleteToLast = strcmp(tempString, "") == 0) == FALSE)
                toRunNumber = atol(tempString);
              if(deleteFromFirst && deleteToLast)
              {
                TMSError(hWndDlg, MB_ICONSTOP, ERROR_141, (HANDLE)NULL);
                bFinished = FALSE;
                break;
              }
              if(!deleteFromFirst && !deleteToLast && fromRunNumber > toRunNumber)
              {
                TMSError(hWndDlg, MB_ICONSTOP, ERROR_142, (HANDLE)NULL);
                bFinished = FALSE;
                break;
              }
              RUNSKey1.DIVISIONSrecordID = pDI->fileInfo.divisionRecordID;
              RUNSKey1.SERVICESrecordID = pDI->fileInfo.serviceRecordID;
              RUNSKey1.runNumber = (deleteFromFirst ? NO_RECORD : fromRunNumber);
              RUNSKey1.pieceNumber = NO_RECORD;
              rcode2 = btrieve(B_GETGREATER, TMS_RUNS, &RUNS, &RUNSKey1, 1);
              while(rcode2 == 0 &&
                    RUNS.DIVISIONSrecordID == pDI->fileInfo.divisionRecordID &&
                    RUNS.SERVICESrecordID == pDI->fileInfo.serviceRecordID)
              {
                if(!deleteToLast && RUNS.runNumber > toRunNumber)
                  break;
                btrieve(B_DELETE, TMS_RUNS, &RUNS, &RUNSKey1, 1);
                rcode2 = btrieve(B_GETNEXT, TMS_RUNS, &RUNS, &RUNSKey1, 1);
              }
              break;
//
//  Specific runs and specific runtypes
//
            case DELETERUNS_SPECIFICRUNS:
            case DELETERUNS_RUNSOFRUNTYPE:
              numSelected = SendMessage(hCtlLISTBOX, LB_GETSELCOUNT, (WPARAM)0, (LPARAM)0);
              if(numSelected == 0 || numSelected == LB_ERR)
              {
                break;
              }
              pSelections = (int *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(int) * numSelected); 
              if(pSelections == NULL)
              {
                AllocationError(__FILE__, __LINE__, FALSE);
                break;
              }
              SendMessage(hCtlLISTBOX, LB_GETSELITEMS, (WPARAM)numSelected, (LPARAM)pSelections);
              if(selection == DELETERUNS_SPECIFICRUNS)
              {
                for(nI = 0; nI < numSelected; nI++)
                {
                  thisRun = SendMessage(hCtlLISTBOX, LB_GETITEMDATA, (WPARAM)pSelections[nI], (LPARAM)0);
                  RUNSKey1.DIVISIONSrecordID = pDI->fileInfo.divisionRecordID;
                  RUNSKey1.SERVICESrecordID = pDI->fileInfo.serviceRecordID;
                  RUNSKey1.runNumber = thisRun;
                  RUNSKey1.pieceNumber = NO_RECORD;
                  rcode2 = btrieve(B_GETGREATER, TMS_RUNS, &RUNS, &RUNSKey1, 1);
                  while(rcode2 == 0 &&
                        RUNS.DIVISIONSrecordID == pDI->fileInfo.divisionRecordID &&
                        RUNS.SERVICESrecordID == pDI->fileInfo.serviceRecordID &&
                        RUNS.runNumber == thisRun)
                  {
                    btrieve(B_DELETE, TMS_RUNS, &RUNS, &RUNSKey1, 1);
                    rcode2 = btrieve(B_GETNEXT, TMS_RUNS, &RUNS, &RUNSKey1, 1);
                  }
                }
              }
              else  // DELETERUNS_RUNSOFRUNTYPE
              {
                RUNSKey1.DIVISIONSrecordID = pDI->fileInfo.divisionRecordID;
                RUNSKey1.SERVICESrecordID = pDI->fileInfo.serviceRecordID;
                RUNSKey1.runNumber = NO_RECORD;
                RUNSKey1.pieceNumber = NO_RECORD;
                rcode2 = btrieve(B_GETGREATER, TMS_RUNS, &RUNS, &RUNSKey1, 1);
                while(rcode2 == 0 &&
                      RUNS.DIVISIONSrecordID == pDI->fileInfo.divisionRecordID &&
                      RUNS.SERVICESrecordID == pDI->fileInfo.serviceRecordID)
                {
                  if(RUNS.pieceNumber == 1)
                  {
                    recordID = RUNS.recordID;
                    runNumber = RUNS.runNumber;
                    numPieces = GetRunElements(hWnd, &RUNS, &PROPOSEDRUN, &COST, TRUE);
                    RUNSKey0.recordID = recordID;
                    btrieve(B_GETEQUAL, TMS_RUNS, &RUNS, &RUNSKey0, 0);
                    btrieve(B_GETPOSITION, TMS_RUNS, &RUNS, &RUNSKey0, 0);
                    btrieve(B_GETDIRECT, TMS_RUNS, &RUNS, &RUNSKey1, 1);
                    for(nI = 0; nI < numSelected; nI++)
                    {
                      runType = SendMessage(hCtlLISTBOX, LB_GETITEMDATA, (WPARAM)pSelections[nI], (LPARAM)0);
                      if(RUNSVIEW[0].runType == runType)
                      {
                        for(nJ = 0; nJ < numPieces; nJ ++)
                        {
                          btrieve(B_DELETE, TMS_RUNS, &RUNS, &RUNSKey1, 1);
                          btrieve(B_GETNEXT, TMS_RUNS, &RUNS, &RUNSKey1, 1);
                        }
                        break;
                      }
                    }
                  }
                  RUNSKey1.DIVISIONSrecordID = pDI->fileInfo.divisionRecordID;
                  RUNSKey1.SERVICESrecordID = pDI->fileInfo.serviceRecordID;
                  RUNSKey1.runNumber = runNumber + 1;
                  RUNSKey1.pieceNumber = NO_RECORD;
                  rcode2 = btrieve(B_GETGREATER, TMS_RUNS, &RUNS, &RUNSKey1, 1);
                }
              }
              TMSHeapFree(pSelections);
              break;
          }
          SetCursor(saveCursor);
          if(bFinished)
            EndDialog(hWndDlg, TRUE);
          break;
      }
      break;

    default:
      return FALSE;
  }
  return TRUE;
}
Ejemplo n.º 16
0
Archivo: ADDRUN.c Proyecto: ems/TMS
BOOL CALLBACK ADDRUNMsgProc(HWND hWndDlg, UINT Message, WPARAM wParam, LPARAM lParam)
{
 static  PDISPLAYINFO pDI;
 static  HANDLE hCtlALLRGRPS;
 static  HANDLE hCtlALLWITHLABEL;
 static  HANDLE hCtlLABELS;
 static  HANDLE hCtlORRGRP;
 static  HANDLE hCtlRGRP;
 static  HANDLE hCtlSGRP;
 static  HANDLE hCtlNA;
 static  HANDLE hCtlONLYASSIGNED;
 static  HANDLE hCtlNODELIST;
 static  HANDLE hCtlLISTBOXTITLE;
 static  HANDLE hCtlBLOCKS;
 static  HANDLE hCtlIDREMOVE;
 static  HANDLE hCtlIDINTERACTIVE;
 static  HANDLE hCtlIDVISUAL;
 static  long   RGRPRouteRecordID;
 static  long   SGRPServiceRecordID;
 static  int    tabPos[TABSET] = {22, 32};
 static  int    selectedFrom;
 static  int    numRoutes;
 HCURSOR saveCursor;
 WORD    DlgWidthUnits;
 BOOL    bFound;
 char    RGRPNumber[ROUTES_NUMBER_LENGTH + 1];
 char    RGRPName[ROUTES_NAME_LENGTH + 1];
 char    SGRPName[SERVICES_NAME_LENGTH + 1];
 char    NODEName[NODES_ABBRNAME_LENGTH + 1];
 char    dummy[256];
 int     adjustedTabPos[TABSET];
 int     nI;
 int     nJ;
 int     rcode2;
 int     numGarages;
 int     nRc;

 short int wmId;
 short int wmEvent;
 long flags;
 long tempLong;
  int numSelected;
  long position;
  BLOCKSINDEXDef BLOCKSINDEX;
  int selectedLabel;
  long commentsRecordID;
  BLOCKSDef *pTRIPSChunk;
  int serviceIndex;
  long SERVICESrecordID;
  long NODESrecordID;
  long ROUTESrecordID;
  int  garageIndex;
  int  numBlocks;
  int  bEnable;

  int *pSelected = NULL;

 switch(Message)
 {
//
//  WM_INITDIALOG - Initialize the dialog
//
    case WM_INITDIALOG:
      pDI = (PDISPLAYINFO)lParam;
      if(pDI == NULL)
      {
        SendMessage(hWndDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), (LPARAM)0);
        break;
      }
//
//  Set up the handle to the controls
//
     hCtlALLRGRPS = GetDlgItem(hWndDlg, ADDRUN_ALLRGRPS);
     hCtlALLWITHLABEL = GetDlgItem(hWndDlg, ADDRUN_ALLWITHLABEL);
     hCtlLABELS = GetDlgItem(hWndDlg, ADDRUN_LABELS);
     hCtlORRGRP = GetDlgItem(hWndDlg, ADDRUN_ORRGRP);
     hCtlRGRP = GetDlgItem(hWndDlg, ADDRUN_RGRP);
     hCtlSGRP = GetDlgItem(hWndDlg, ADDRUN_SGRP);
     hCtlNA = GetDlgItem(hWndDlg, ADDRUN_NA);
     hCtlONLYASSIGNED = GetDlgItem(hWndDlg, ADDRUN_ONLYASSIGNED);
     hCtlNODELIST = GetDlgItem(hWndDlg, ADDRUN_NODELIST);
     hCtlLISTBOXTITLE = GetDlgItem(hWndDlg, ADDRUN_LISTBOXTITLE);
     hCtlBLOCKS = GetDlgItem(hWndDlg, ADDRUN_BLOCKS);
     hCtlIDREMOVE = GetDlgItem(hWndDlg, IDREMOVE);
     hCtlIDINTERACTIVE = GetDlgItem(hWndDlg, IDINTERACTIVE);
     hCtlIDVISUAL = GetDlgItem(hWndDlg, IDVISUAL);
//
//  Set up the tab stops for ADDRUN_LISTBOXTITLE and ADDRUN_BLOCKS, and draw the title
//
     DlgWidthUnits = LOWORD(GetDialogBaseUnits()) / 4;
     for(nJ = 0; nJ < TABSET; nJ++)
     {
       adjustedTabPos[nJ] = (DlgWidthUnits * tabPos[nJ] * 2);
     }
     SendMessage(hCtlLISTBOXTITLE, LB_SETTABSTOPS, (WPARAM)TABSET, (LPARAM)adjustedTabPos);
     LoadString(hInst, TEXT_024, tempString, TEMPSTRING_LENGTH);
     SendMessage(hCtlLISTBOXTITLE, LB_ADDSTRING, (WPARAM)0, (LONG)(LPSTR)tempString);
     SendMessage(hCtlBLOCKS, LB_SETTABSTOPS, (WPARAM)TABSET, (LPARAM)adjustedTabPos);
//
//  Display the "destination"
//
     flags = PLACEMENT_SERVICE | PLACEMENT_DIVISION;
     DisplayPlacement(hWndDlg, ADDRUN_DESTINATION, pDI, flags);
//
//  SGRP
//
     if(SetUpServiceList(hWndDlg, ADDRUN_SGRP, pDI->fileInfo.serviceRecordID) == 0)
     {
       SendMessage(hWndDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), (LPARAM)0);
       break;
     }
//
//  Default to All RGRPS and N/A on the subset
//
     SendMessage(hCtlALLRGRPS, BM_SETCHECK, (WPARAM)TRUE, (LPARAM)0);
     SendMessage(hCtlNA, BM_SETCHECK, (WPARAM)TRUE, (LPARAM)0);
//
//  However, set up the combo boxes in case he picks one of them
//
//  Labels
//
     saveCursor = SetCursor(hCursorWait);
     rcode2 = btrieve(B_GETFIRST, TMS_ROUTES, &ROUTES, &ROUTESKey0, 0);
     while(rcode2 == 0)
     {
       if(ROUTES.COMMENTSrecordID != NO_RECORD)
       {
         nJ = (int)SendMessage(hCtlLABELS, CB_GETCOUNT, (WPARAM)0, (LPARAM)0);
         for(bFound = FALSE, nI = 0; nI < nJ; nI++)
         {
           if(SendMessage(hCtlLABELS, CB_GETITEMDATA, (WPARAM)nI, (LPARAM)0) == ROUTES.COMMENTSrecordID)
           {
             bFound = TRUE;
             break;
           }
         }
         if(!bFound)
         {
           COMMENTSKey0.recordID = ROUTES.COMMENTSrecordID;
           btrieve(B_GETEQUAL, TMS_COMMENTS, &COMMENTS, &COMMENTSKey0, 0);
           strncpy(tempString, COMMENTS.code, sizeof(COMMENTS.code));
           trim(tempString, sizeof(COMMENTS.code));
           nI = (int)SendMessage(hCtlLABELS, CB_ADDSTRING, (WPARAM)0, (LONG)(LPSTR)tempString);
           SendMessage(hCtlLABELS, CB_SETITEMDATA, (WPARAM)nI, (LPARAM)ROUTES.COMMENTSrecordID);
         }
       }
       rcode2 = btrieve(B_GETNEXT, TMS_ROUTES, &ROUTES, &ROUTESKey0, 0);
     }
     SendMessage(hCtlLABELS, CB_SETCURSEL, (WPARAM)(-1), (LPARAM)0);
     SetCursor(saveCursor);
//
//  RGRP
//
//
//  Set up the route listbox
//
      SendMessage(hCtlRGRP, LB_RESETCONTENT, (WPARAM)(WPARAM)0, (LPARAM)0);
      rcode2 = btrieve(B_GETFIRST, TMS_ROUTES, &ROUTES, &ROUTESKey1, 1);
      while(rcode2 == 0)
      {
        strncpy(tempString, ROUTES.number, ROUTES_NUMBER_LENGTH);
        trim(tempString, ROUTES_NUMBER_LENGTH);
        strncpy(szarString, ROUTES.name, ROUTES_NAME_LENGTH);
        trim(szarString, ROUTES_NAME_LENGTH);
        strcat(tempString, " - ");
        strcat(tempString, szarString);
        nI = (int)SendMessage(hCtlRGRP, LB_ADDSTRING, (WPARAM)0, (LONG)(LPSTR)tempString);
        SendMessage(hCtlRGRP, LB_SETITEMDATA, (WPARAM)nI, ROUTES.recordID);
        numRoutes++;
        rcode2 = btrieve(B_GETNEXT, TMS_ROUTES, &ROUTES, &ROUTESKey1, 1);
      }
      if(numRoutes == 0)
      {
        TMSError(hWndDlg, MB_ICONSTOP, ERROR_008, (HANDLE)NULL);
        SendMessage(hWndDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL,0), (LPARAM)0);
        break;
      }
//
//  Garages (assigned to)
//
      numGarages = 0;
      NODESKey1.flags = NODES_FLAG_GARAGE;
      memset(NODESKey1.abbrName, 0x00, NODES_ABBRNAME_LENGTH);
      rcode2 = btrieve(B_GETGREATEROREQUAL, TMS_NODES, &NODES, &NODESKey1, 1);
      while(rcode2 == 0 && NODES.flags & NODES_FLAG_GARAGE)
      {
        strncpy(tempString, NODES.abbrName, NODES_ABBRNAME_LENGTH);
        trim(tempString, NODES_ABBRNAME_LENGTH);
        nI = SendMessage(hCtlNODELIST, CB_ADDSTRING, (WPARAM)0, (LONG)(LPSTR)tempString);
        SendMessage(hCtlNODELIST, CB_SETITEMDATA, (WPARAM)nI, (LPARAM)NODES.recordID);
        numGarages++;
        rcode2 = btrieve(B_GETNEXT, TMS_NODES, &NODES, &NODESKey1, 1);
      }
      if(numGarages == 0)
      {
        EnableWindow(hCtlONLYASSIGNED, FALSE);
        EnableWindow(hCtlNODELIST, FALSE);
      }
//
//  Allocate space for m_pPICKEDBLOCKS
//
      m_maxPICKEDBLOCKS = 128;
      m_pPICKEDBLOCKS = (PICKEDBLOCKSDef *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PICKEDBLOCKSDef) * m_maxPICKEDBLOCKS); 
      if(m_pPICKEDBLOCKS == NULL)
      {
        AllocationError(__FILE__, __LINE__, FALSE);
        SendMessage(hWndDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), (LPARAM)0);
        break;
      }
//
//  Zero out the selections
//
      m_numPICKEDBLOCKS = 0;
      break;
//
//  WM_CLOSE
//
   case WM_CLOSE:
     TMSHeapFree(m_pPICKEDBLOCKS);
     EndDialog(hWndDlg, FALSE);
     break;
//
//  WM_COMMAND
//
    case WM_COMMAND:
      wmId = LOWORD(wParam);
      wmEvent = HIWORD(wParam);
     switch(wmId)
     {
//
//  ADDRUN_ALLRGRPS
//
        case ADDRUN_ALLRGRPS:
          if(SendMessage(hCtlALLRGRPS, BM_GETCHECK, (WPARAM)0, (LPARAM)0))
          {
            SendMessage(hCtlLABELS, CB_SETCURSEL, (WPARAM)(-1), (LPARAM)0);
            SendMessage(hCtlRGRP, LB_SETSEL, (WPARAM)(FALSE), (LPARAM)(-1));
          }
          break;
//
//  ADDRUN_ALLWITHLABEL
//
        case ADDRUN_ALLWITHLABEL:
          if(SendMessage(hCtlALLWITHLABEL, BM_GETCHECK, (WPARAM)0, (LPARAM)0))
          {
            SendMessage(hCtlLABELS, CB_SETCURSEL, (WPARAM)(0), (LPARAM)0);
            SendMessage(hCtlRGRP, LB_SETSEL, (WPARAM)(FALSE), (LPARAM)(-1));
          }
          break;
//
//  ADDRUN_LABELS
//
        case ADDRUN_LABELS:
          switch(wmEvent)
          {
            case CBN_SELENDOK:
              if(SendMessage(hCtlALLRGRPS, BM_GETCHECK, (WPARAM)0, (LPARAM)0) ||
                    SendMessage(hCtlORRGRP, BM_GETCHECK, (WPARAM)0, (LPARAM)0))
              {
                SendMessage(hCtlALLRGRPS, BM_SETCHECK, (WPARAM)FALSE, (LPARAM)0);
                SendMessage(hCtlORRGRP, BM_SETCHECK, (WPARAM)FALSE, (LPARAM)0);
                SendMessage(hCtlALLWITHLABEL, BM_SETCHECK, (WPARAM)TRUE, (LPARAM)0);
                SendMessage(hCtlRGRP, LB_SETSEL, (WPARAM)(FALSE), (LPARAM)(-1));
              }
              break;  
          }
          break;
//
//  ADDRUN_ORRGRP
//
        case ADDRUN_ORRGRP:
          if(SendMessage(hCtlORRGRP, BM_GETCHECK, (WPARAM)0, (LPARAM)0))
          {
            SendMessage(hCtlLABELS, CB_SETCURSEL, (WPARAM)(-1), (LPARAM)0);
          }
          break;
//
//  ADDRUN_RGRP
//
        case ADDRUN_RGRP:
          switch(wmEvent)
          {
            case LBN_SELCHANGE:
              if(SendMessage(hCtlALLRGRPS, BM_GETCHECK, (WPARAM)0, (LPARAM)0) ||
                    SendMessage(hCtlALLWITHLABEL, BM_GETCHECK, (WPARAM)0, (LPARAM)0))
              {
                SendMessage(hCtlALLRGRPS, BM_SETCHECK, (WPARAM)FALSE, (LPARAM)0);
                SendMessage(hCtlALLWITHLABEL, BM_SETCHECK, (WPARAM)FALSE, (LPARAM)0);
                SendMessage(hCtlORRGRP, BM_SETCHECK, (WPARAM)TRUE, (LPARAM)0);
              }
              break;
          }
          break;
//
//  ADDRUN_LISTBOXTITLE
//
       case ADDRUN_LISTBOXTITLE:    // Title string
         SendMessage(hCtlLISTBOXTITLE, LB_SETSEL, (WPARAM)FALSE, (LPARAM)(-1));
         break;
//
//  ADDRUN_BLOCKS
//
       case ADDRUN_BLOCKS: // List box
         switch(wmEvent)
         {
           case LBN_SELCHANGE:
             if(SendMessage(hWndDlg, LB_GETCURSEL, (WPARAM)0, (LPARAM)0) == LB_ERR)
               break;
             EnableWindow(hCtlIDREMOVE, TRUE);
             break;
         }
         break;
//
//  "Assigned to Garage" stuff
//
        case ADDRUN_NODELIST:
          switch(wmEvent)
          {
            case CBN_SELENDOK:
              if(SendMessage(hCtlNA, BM_GETCHECK, (WPARAM)0, (LPARAM)0))
              {
                SendMessage(hCtlNA, BM_SETCHECK, (WPARAM)FALSE, (LPARAM)0);
                SendMessage(hCtlONLYASSIGNED, BM_SETCHECK, (WPARAM)TRUE, (LPARAM)0);
              }
              break;  
          }
          break;

        case ADDRUN_NA:
          SendMessage(hCtlNODELIST, CB_SETCURSEL, (WPARAM)(-1), (LPARAM)0);
          break;

        case ADDRUN_ONLYASSIGNED:
          SendMessage(hCtlNODELIST, CB_SETCURSEL, (WPARAM)0, (LPARAM)0);
          break;
//
//  IDADD
//
       case IDADD:
         saveCursor = SetCursor(hCursorWait);
//
//  Highlight the applicable entries in ADDRUN_RGRP
//
//  All routes
//
         if(SendMessage(hCtlALLRGRPS, BM_GETCHECK, (WPARAM)0, (LPARAM)0))
         {
           SendMessage(hCtlRGRP, LB_SETSEL, (WPARAM)TRUE, (LPARAM)(-1));
         }
//
//  All labelled
//
         else if(SendMessage(hCtlALLWITHLABEL, BM_GETCHECK, (WPARAM)0, (LPARAM)0))
         {
           selectedLabel = SendMessage(hCtlLABELS, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
           commentsRecordID = SendMessage(hCtlLABELS,
                 CB_GETITEMDATA, (WPARAM)selectedLabel, (LPARAM)0);
           SendMessage(hCtlRGRP, LB_SETSEL, (WPARAM)FALSE, (LPARAM)(-1));
           numRoutes = SendMessage(hCtlRGRP, LB_GETCOUNT, (WPARAM)0, (LPARAM)0);
           for(nI = 0; nI < numRoutes; nI++)
           {
             ROUTESKey0.recordID = SendMessage(hCtlRGRP, LB_GETITEMDATA, (WPARAM)nI, (LPARAM)0);
             btrieve(B_GETEQUAL, TMS_ROUTES, &ROUTES, &ROUTESKey0, 0);
             if(ROUTES.COMMENTSrecordID == commentsRecordID)
               SendMessage(hCtlRGRP, LB_SETSEL, (WPARAM)TRUE, (LPARAM)nI);
           }
         }
//
//  Get the service
//
         serviceIndex = SendMessage(hCtlSGRP, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
         SendMessage(hCtlSGRP, CB_GETLBTEXT, (WPARAM)serviceIndex, (LONG)(LPSTR)SGRPName);
         SERVICESrecordID = SendMessage(hCtlSGRP,
               CB_GETITEMDATA, (WPARAM)serviceIndex, (LPARAM)0);
//
//  Is there a subset garage?
//
         if(SendMessage(hCtlNA, BM_GETCHECK, (WPARAM)0, (LPARAM)0))
         {
           garageIndex = NO_RECORD;
           LoadString(hInst, TEXT_026, NODEName, sizeof(NODEName));
           NODESrecordID = NO_RECORD;
         }
         else
         {
           garageIndex = SendMessage(hCtlNODELIST, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
           SendMessage(hCtlNODELIST, CB_GETLBTEXT, (WPARAM)garageIndex, (LONG)(LPSTR)NODEName);
           NODESrecordID = SendMessage(hCtlNODELIST,
                 CB_GETITEMDATA, (WPARAM)garageIndex, (LPARAM)0);
         }
//
//  Ok, got all the pertinent data
//
//  Loop through all the selections and all the current
//  entries in ADDRUN_BLOCKS to ensure that the same
//  information isn't added twice.  We'll do this in three
//  passes, the first of which will deselect any duplicate 
//  route from the RGRP box.  The second pass determines if
//  there are actually any blocks in that RGRP/SGRP to add.
//  The last pass is the physical add.
//
          nI = (int)SendMessage(hCtlRGRP, LB_GETSELCOUNT, (WPARAM)0, (LPARAM)0);
          if(nI == 0 || nI == LB_ERR)
          {
            break;
          }
          pSelected = (int *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(int) * nI); 
          if(pSelected == NULL)
          {
            AllocationError(__FILE__, __LINE__, FALSE);
            break;
          }
          numSelected = (int)SendMessage(hCtlRGRP, LB_GETSELITEMS, (WPARAM)nI, (LPARAM)pSelected);
          numBlocks = SendMessage(hCtlBLOCKS, LB_GETCOUNT, (WPARAM)0, (LPARAM)0);
//
//  Pass 1: Loop through and knock out any duplicates
//
          BLOCKSINDEX.service = serviceIndex;
          BLOCKSINDEX.garage = garageIndex;
          for(nI = 0; nI < numSelected; nI++)
          {
            BLOCKSINDEX.route = pSelected[nI];
            memcpy(&position, &BLOCKSINDEX, sizeof(long));
            for(nJ = 0; nJ < numBlocks; nJ++)
            {
              tempLong = SendMessage(hCtlBLOCKS, LB_GETITEMDATA, (WPARAM)nJ, (LPARAM)0);
              if(tempLong == position)
                SendMessage(hCtlRGRP, LB_SETSEL, (WPARAM)FALSE, (LPARAM)pSelected[nI]);
            }
          }
//
//  Pass 2: Loop through an deselect the RGRP if there are no blocks
//
//  Figure out nI, numSelected, and selected again, 
//  in case we deselected anything in step 1.
//
          nI = (int)SendMessage(hCtlRGRP, LB_GETSELCOUNT, (WPARAM)0, (LPARAM)0);
          numSelected = (int)SendMessage(hCtlRGRP, LB_GETSELITEMS,
                (WPARAM)nI, (LPARAM)(int far *)pSelected);
          for(nI = 0; nI < numSelected; nI++)
          {
            for(bFound = FALSE, nJ = 2; nJ <=3; nJ++)
            {
              pTRIPSChunk = nJ == 2 ? &TRIPS.standard : &TRIPS.dropback;
              ROUTESrecordID = SendMessage(hCtlRGRP, LB_GETITEMDATA, (WPARAM)pSelected[nI], (LPARAM)0);
              TRIPSKey2.assignedToNODESrecordID = NODESrecordID;
              TRIPSKey2.RGRPROUTESrecordID = ROUTESrecordID;
              TRIPSKey2.SGRPSERVICESrecordID = SERVICESrecordID;
              TRIPSKey2.blockNumber = NO_RECORD;
              TRIPSKey2.blockSequence = NO_TIME;
              rcode2 = btrieve(B_GETGREATEROREQUAL, TMS_TRIPS, &TRIPS, &TRIPSKey2, nJ);
              if(rcode2 == 0 &&
                    pTRIPSChunk->assignedToNODESrecordID == NODESrecordID &&
                    pTRIPSChunk->RGRPROUTESrecordID == ROUTESrecordID &&
                    pTRIPSChunk->SGRPSERVICESrecordID == SERVICESrecordID &&
                    pTRIPSChunk->blockNumber > 0)
              {
                bFound = TRUE;
                break;
              }
            }
            if(!bFound)
              SendMessage(hCtlRGRP, LB_SETSEL, (WPARAM)FALSE, (LPARAM)pSelected[nI]);
          }
//
//  Pass 3: Add the route/ser/gar to the ADDRUN_BLOCKS box
//
//  Figure out nI, numSelected, and selected again, 
//  in case we deselected anything in steps 1 and 2.
//
          nI = (int)SendMessage(hCtlRGRP, LB_GETSELCOUNT, (WPARAM)0, (LPARAM)0);
          numSelected = (int)SendMessage(hCtlRGRP, LB_GETSELITEMS,
                (WPARAM)nI, (LPARAM)(int far *)pSelected);
          for(nI = 0; nI < numSelected; nI++)
          {
//
//  Get the route name and number
//
            ROUTESKey0.recordID = SendMessage(hCtlRGRP,
                  LB_GETITEMDATA, (WPARAM)pSelected[nI], (LPARAM)0);
            btrieve(B_GETEQUAL, TMS_ROUTES, &ROUTES, &ROUTESKey0, 0);
            strncpy(RGRPNumber, ROUTES.number, ROUTES_NUMBER_LENGTH);
            trim(RGRPNumber, ROUTES_NUMBER_LENGTH);
            strncpy(RGRPName, ROUTES.name, ROUTES_NAME_LENGTH);
            trim(RGRPName, ROUTES_NAME_LENGTH);
//
//  Set up itemdata
//
            BLOCKSINDEX.route = pSelected[nI];
            BLOCKSINDEX.service = serviceIndex;
            BLOCKSINDEX.garage = garageIndex;
            memcpy(&position, &BLOCKSINDEX, sizeof(long));
// 
//  Get the display string ready
//
            strcpy(tempString, RGRPNumber);
            strcat(tempString, " - ");
            strcat(tempString, RGRPName);
            trim(tempString, tabPos[0]);
            strcat(tempString, "\t");
            strcat(tempString, SGRPName);
            strcat(tempString, "\t");
            strcat(tempString, NODEName);
//
//  Add it and set itemdata
//
            nJ = (int)SendMessage(hCtlBLOCKS, LB_ADDSTRING, (WPARAM)0, (LONG)(LPSTR)tempString);
            SendMessage(hCtlBLOCKS, LB_SETITEMDATA, (WPARAM)nJ, (LPARAM)position);
          }
//
//  Enable the VISUAL and INTERACTIVE buttons
//
         bEnable = numSelected > 0;
         EnableWindow(hCtlIDINTERACTIVE, bEnable);
         EnableWindow(hCtlIDVISUAL, bEnable);
//
//  And release the memory and reset the cursor
//
         TMSHeapFree(pSelected);
         SetCursor(saveCursor);
         break;
//
//  IDREMOVE
//
        case IDREMOVE: // Button text: "Remove"
          nI = (int)SendMessage(hCtlBLOCKS, LB_GETSELCOUNT, (WPARAM)0, (LPARAM)0);
          if(nI == 0 || nI == LB_ERR)
          {
            break;
          }
          pSelected = (int *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(int) * nI); 
          if(pSelected == NULL)
          {
            AllocationError(__FILE__, __LINE__, FALSE);
            break;
          }
          numSelected = (int)SendMessage(hCtlBLOCKS, LB_GETSELITEMS, (WPARAM)nI, (LPARAM)pSelected);
//
//  Process the list from the back to the front
//
          for(nI = numSelected - 1; nI >= 0; nI--)
          {
            SendMessage(hCtlBLOCKS, LB_DELETESTRING, (WPARAM)pSelected[nI], (LPARAM)0);
          }
          if(SendMessage(hCtlBLOCKS, LB_GETCOUNT, (WPARAM)0, (LPARAM)0) == 0)
          {
            EnableWindow(hCtlIDINTERACTIVE, FALSE);
          }
          EnableWindow(hCtlIDREMOVE, FALSE);
          TMSHeapFree(pSelected);
          break;
//
//  IDCANCEL
//
       case IDCANCEL:
         TMSHeapFree(m_pPICKEDBLOCKS);
         EndDialog(hWndDlg, FALSE);
         break;
//
//  IDHELP
//
        case IDHELP:
          WinHelp(hWndDlg, szarHelpFile, HELP_CONTEXT, The_Runs_Table);
          break;
//
//  IDINTERACTIVE and IDVISUAL
//
       case IDINTERACTIVE:
       case IDVISUAL:
//
//  Grab the selections
//
         numSelected = SendMessage(hCtlBLOCKS, LB_GETCOUNT, (WPARAM)0, (LPARAM)0);
         m_numPICKEDBLOCKS = 0;
         for(nI = 0; nI < numSelected; nI++)
         {
           if(m_numPICKEDBLOCKS >= m_maxPICKEDBLOCKS)
           {
             m_maxPICKEDBLOCKS += 128;
             m_pPICKEDBLOCKS = (PICKEDBLOCKSDef *)HeapReAlloc(GetProcessHeap(),
                   HEAP_ZERO_MEMORY, m_pPICKEDBLOCKS, sizeof(PICKEDBLOCKSDef) * m_maxPICKEDBLOCKS); 
             if(m_pPICKEDBLOCKS == NULL)
             {
               AllocationError(__FILE__, __LINE__, TRUE);
               break;
             }
           }
           tempLong = SendMessage(hCtlBLOCKS, LB_GETITEMDATA, (WPARAM)nI, (LPARAM)0);
           memcpy(&BLOCKSINDEX, &tempLong, sizeof(long));
           NODESrecordID =
                 SendMessage(hCtlNODELIST, CB_GETITEMDATA, (WPARAM)BLOCKSINDEX.garage, (LPARAM)0);
           ROUTESrecordID =
                 SendMessage(hCtlRGRP, LB_GETITEMDATA, (WPARAM)BLOCKSINDEX.route, (LPARAM)0);
           SERVICESrecordID =
                 SendMessage(hCtlSGRP, CB_GETITEMDATA, (WPARAM)BLOCKSINDEX.service, (LPARAM)0);
//
//  Are these standard or dropback blocks?
//
//  Dropback (key 3) are always selected over standard
//
           for(bFound = FALSE, nJ = 3; nJ >=2; nJ--)
           {
             pTRIPSChunk = nJ == 2 ? &TRIPS.standard : &TRIPS.dropback;
             TRIPSKey2.assignedToNODESrecordID = NODESrecordID;
             TRIPSKey2.RGRPROUTESrecordID = ROUTESrecordID;
             TRIPSKey2.SGRPSERVICESrecordID = SERVICESrecordID;
             TRIPSKey2.blockNumber = NO_RECORD;
             TRIPSKey2.blockSequence = NO_TIME;
             rcode2 = btrieve(B_GETGREATEROREQUAL, TMS_TRIPS, &TRIPS, &TRIPSKey2, nJ);
             if(rcode2 == 0 &&
                   pTRIPSChunk->assignedToNODESrecordID == NODESrecordID &&
                   pTRIPSChunk->RGRPROUTESrecordID == ROUTESrecordID &&
                   pTRIPSChunk->SGRPSERVICESrecordID == SERVICESrecordID &&
                   pTRIPSChunk->blockNumber > 0)
             {
               m_pPICKEDBLOCKS[m_numPICKEDBLOCKS].flags = (nJ == 2 ? PICKEDBLOCKS_FLAG_STANDARD : PICKEDBLOCKS_FLAG_DROPBACK);
               bFound = TRUE;
               break;
             }
           }
           m_pPICKEDBLOCKS[m_numPICKEDBLOCKS].RGRPROUTESrecordID = ROUTESrecordID;
           m_pPICKEDBLOCKS[m_numPICKEDBLOCKS].SGRPSERVICESrecordID = SERVICESrecordID;
           m_pPICKEDBLOCKS[m_numPICKEDBLOCKS].NODESrecordID = NODESrecordID;
           m_numPICKEDBLOCKS++;
         }
//
//  Establish the internal list of node names and record IDs
//
         TMSHeapFree(m_pNodeAbbrs);
         rcode2 = btrieve(B_STAT, TMS_NODES, &BSTAT, dummy, 0);
         m_numNodeAbbrs = BSTAT.numRecords;
         m_pNodeAbbrs = (NODEABBRSDef *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(NODEABBRSDef) * m_numNodeAbbrs); 
         if(m_pNodeAbbrs == NULL)
         {
           AllocationError(__FILE__, __LINE__, FALSE);
           break;
         }
         else
         {
           nI = 0;
           rcode2 = btrieve(B_GETFIRST, TMS_NODES, &NODES, &NODESKey0, 0);
           while(rcode2 == 0)
           {
             m_pNodeAbbrs[nI].recordID = NODES.recordID;
             strncpy(m_pNodeAbbrs[nI].abbrName, NODES.abbrName, NODES_ABBRNAME_LENGTH);
             trim(m_pNodeAbbrs[nI].abbrName, NODES_ABBRNAME_LENGTH);
             rcode2 = btrieve(B_GETNEXT, TMS_NODES, &NODES, &NODESKey0, 0);
             nI++;
           }
//
//  Fire up the manual/automatic runcutter
//
           RUNSAssignToDIVISION = pDI->fileInfo.divisionRecordID;
           if(wmId == IDINTERACTIVE)
           {
             nRc = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_MANCUT),
                   hWndDlg, (DLGPROC)MANCUTMsgProc, (LPARAM)pDI);
           }
//
//  Fire up the visual runcutter
//
           else
           {
             nRc = VisualRuncutter(pDI);
           }
           TMSHeapFree(m_pPICKEDBLOCKS);
           EndDialog(hWndDlg, nRc);
         }
         break;
       }
     break;    //  End of WM_COMMAND

   default:
     return FALSE;
  }
  return TRUE;
} //  End of ADDRUNMsgProc
Ejemplo n.º 17
0
MemoryPool::MemoryPool(size_t size) 
{
    mySize = size;
    myMemory = malloc(size);
	if(myMemory == NULL) throw AllocationError();
}
Ejemplo n.º 18
0
Archivo: Tmsrpt14.c Proyecto: ems/TMS
//
//  Unrostered runs report
//
BOOL FAR TMSRPT14(TMSRPTPassedDataDef *pPassedData)
{
  TMSRPT14RDataDef *pTMSRPT14RData[ROSTER_MAX_DAYS];
  HFILE hfOutputFile;
  BOOL  bKeepGoing = FALSE;
  BOOL  bFound;
  long  numRuns[ROSTER_MAX_DAYS];
  char szOutputString[128];
  char szDay[16];
  char dummy[256];
  long maxRuns;
  int   days[ROSTER_MAX_DAYS] = {TEXT_009, TEXT_010, TEXT_011,
                                 TEXT_012, TEXT_013, TEXT_014, TEXT_015};
  int   nI;
  int   nJ;
  int   nK;
  int   nL;
  int   rcode2;

  pPassedData->nReportNumber = 13;
  pPassedData->numDataFiles = 1;
  for(nI = 0; nI < m_LastReport; nI++)
  {
    if(TMSRPT[nI].originalReportNumber == pPassedData->nReportNumber)
    {
      StatusBarStart(hWndMain, TMSRPT[nI].szReportName);
      break;
    }
  }
//
//  Open the output file
//
  StatusBarText("Opening output file...");
  strcpy(tempString, szReportsTempFolder);
  strcat(tempString, "\\tmsrpt14.txt");
  hfOutputFile = _lcreat(tempString, 0);
  if(hfOutputFile == HFILE_ERROR)
  {
    LoadString(hInst, ERROR_202, szFormatString, sizeof(szFormatString));
    sprintf(szarString, szFormatString, tempString);
    MessageBeep(MB_ICONSTOP);
    MessageBox((HWND)NULL, szarString, TMS, MB_ICONSTOP);
    goto deallocate;
  }
  strcpy(pPassedData->szReportDataFile[0], tempString);
//
//  Initialize the TMSRPT14RData and TMSRPT14RDataData structures
//
  rcode2 = btrieve(B_STAT, TMS_RUNS, &BSTAT, dummy, 0);
  if(rcode2 != 0 || BSTAT.numRecords == 0)
  {
    TMSError((HWND)NULL, MB_ICONSTOP, ERROR_266, (HANDLE)NULL);
    goto deallocate;
  }
  maxRuns = BSTAT.numRecords;
  for(nI = 0; nI < ROSTER_MAX_DAYS; nI++)
  {
    numRuns[nI] = 0;
    pTMSRPT14RData[nI] = (TMSRPT14RDataDef *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TMSRPT14RDataDef) * maxRuns); 
    if(pTMSRPT14RData[nI] == NULL)
    {
      AllocationError(__FILE__, __LINE__, FALSE);
      goto deallocate;
    }
  }
//
//  Read the runs into TMSRPT14RData
//
  for(nI = 0; nI < ROSTER_MAX_DAYS; nI++)
  {
    LoadString(hInst, days[nI], szDay, sizeof(szDay));
    sprintf(tempString, "Reading %s runs...", szDay); 
    StatusBarText(tempString);
    if(StatusBarAbort())
    {
      goto deallocate;
    }
    if(ROSTERPARMS.serviceDays[nI] == NO_RECORD)
    {
      continue;
    }
    RUNSKey1.DIVISIONSrecordID = m_DivisionRecordID;
    RUNSKey1.SERVICESrecordID = ROSTERPARMS.serviceDays[nI];
    RUNSKey1.runNumber = NO_RECORD;
    RUNSKey1.pieceNumber = NO_RECORD;
    rcode2 = btrieve(B_GETGREATER, TMS_RUNS, &RUNS, &RUNSKey1, 1);
    while(rcode2 == 0 && 
          RUNS.DIVISIONSrecordID == m_DivisionRecordID &&
          RUNS.SERVICESrecordID == ROSTERPARMS.serviceDays[nI])
    {
      if(RUNS.pieceNumber == 1)
      {
        pTMSRPT14RData[nI][numRuns[nI]].recordID = RUNS.recordID;
        pTMSRPT14RData[nI][numRuns[nI]].runNumber = RUNS.runNumber;
        pTMSRPT14RData[nI][numRuns[nI]].cutAsRuntype = RUNS.cutAsRuntype;
        numRuns[nI]++;
      }
      rcode2 = btrieve(B_GETNEXT, TMS_RUNS, &RUNS, &RUNSKey1, 1);
    }
  }
//
//  Go through the roster.  Each time a run number shows up, kill it
//  from the list inside TMSRPT14RData.
//
  rcode2 = btrieve(B_GETFIRST, TMS_ROSTER, &ROSTER, &ROSTERKey0, 0);
  while(rcode2 == 0)
  {
    StatusBarText("Cycling through the roster...");
    for(nI = 0; nI < ROSTER_MAX_DAYS; nI++)
    {
      if(StatusBarAbort())
      {
        goto deallocate;
      }
      if(ROSTER.WEEK[m_RosterWeek].RUNSrecordIDs[nI] == NO_RECORD)
      {
        continue;
      }
      for(nJ = 0; nJ < numRuns[nI]; nJ++)
      {
        if(ROSTER.WEEK[m_RosterWeek].RUNSrecordIDs[nI] == pTMSRPT14RData[nI][nJ].recordID)
        {
          pTMSRPT14RData[nI][nJ].recordID = NO_RECORD;
          break;
        }
      }
    }
    rcode2 = btrieve(B_GETNEXT, TMS_ROSTER, &ROSTER, &ROSTERKey0, 0);
  }
//
//  Dump out the remaining runs
//
  for(nI = 0; nI < ROSTER_MAX_DAYS; nI++)
  {
    if(StatusBarAbort())
    {
      goto deallocate;
    }
    LoadString(hInst, days[nI], szDay, sizeof(szDay));
    sprintf(tempString, "Writing output for day %s...", szDay); 
    StatusBarText(tempString);
    for(bFound = FALSE, nJ = 0; nJ < numRuns[nI]; nJ++)
    {
      if(pTMSRPT14RData[nI][nJ].recordID != NO_RECORD)
      {
        bFound = TRUE;
        break;
      }
    }
    if(!bFound)
    {
      sprintf(szOutputString, "%10s\t", szDay);
      strcat(szOutputString, "     0\tNo runs\r\n");
      _lwrite(hfOutputFile, szOutputString, strlen(szOutputString));
    }
    else
    {
      for(; nJ < numRuns[nI]; nJ++)
      {
        sprintf(szOutputString, "%10s\t", szDay);
        if(pTMSRPT14RData[nI][nJ].recordID != NO_RECORD)
        {
          sprintf(tempString, "%6ld\t", pTMSRPT14RData[nI][nJ].runNumber);
          strcat(szOutputString, tempString);
          nK = (short int)LOWORD(pTMSRPT14RData[nI][nJ].cutAsRuntype);
          nL = (short int)HIWORD(pTMSRPT14RData[nI][nJ].cutAsRuntype);
          if(nK >= 0 && nK < NUMRUNTYPES && nL >= 0 && nL < NUMRUNTYPESLOTS)
          {
            strcat(szOutputString, RUNTYPE[nK][nL].localName);
          }
          strcat(szOutputString, "\r\n");
          _lwrite(hfOutputFile, szOutputString, strlen(szOutputString));
        }
      }
    }
  }
  bKeepGoing = TRUE;
//
//  Free allocated memory
//
  deallocate:
    for(nI = 0; nI < ROSTER_MAX_DAYS; nI++)
    {
      TMSHeapFree(pTMSRPT14RData[nI]);
    }
    _lclose(hfOutputFile);
    StatusBarEnd();
    if(!bKeepGoing)
    {
      return(FALSE);
    }
//
//  All done
//
  return(TRUE);
}