📄 mod_tpcc.c
字号:
*
* ARGUMENTS: request_rec *req pointer to the structure that
* is passed in the internet
* int w_id warehouse id
* int ld_id login district id
*
* RETURNS: None
*
* COMMENTS: None
*
*/
void SendNewOrderForm( request_rec *req, int w_id, int ld_id )
{
char *newOrderForm;
RESERVE_FORM( NEW_ORDER_FORM, newOrderForm );
PutNumeric(WDID(w_id,ld_id),
newOrderFormIndexes[NO_WDID].iLen,
&newOrderForm[newOrderFormIndexes[NO_WDID].iStartIndex]);
PutNumeric(w_id,newOrderFormIndexes[NO_WID].iLen,
&newOrderForm[newOrderFormIndexes[NO_WID].iStartIndex]);
SendResponse(req, newOrderForm, giFormLen[NEW_ORDER_FORM]);
UNRESERVE_FORM( NEW_ORDER_FORM, newOrderForm );
}
/* FUNCTION: void SendPaymentForm(request_rec *req,
* int w_id, int ld_id,DBContext *pdb)
*
* PURPOSE: This function puts the data into the input form and then
* returns the form to the browser.
*
* ARGUMENTS:
* request_rec *req pointer to structure passed in
* the internet
* int w_id warehouse id
* int ld_id login district id
*
* RETURNS: None
*
* COMMENTS: None
*
*/
void SendPaymentForm( request_rec *req, int w_id, int ld_id )
{
char *paymentForm;
RESERVE_FORM( PAYMENT_FORM, paymentForm );
PutNumeric(WDID(w_id,ld_id),paymentFormIndexes[PT_WDID_INPUT].iLen,
&paymentForm[paymentFormIndexes[PT_WDID_INPUT].iStartIndex]);
/* the date field is before wid for the response so use 2 here */
PutNumeric(w_id,paymentFormIndexes[PT_WID_INPUT].iLen,
&paymentForm[paymentFormIndexes[PT_WID_INPUT].iStartIndex]);
SendResponse(req, paymentForm, giFormLen[PAYMENT_FORM]);
UNRESERVE_FORM( PAYMENT_FORM, paymentForm );
}
/* FUNCTION: void SendOrderStatusForm(request_rec *req,
* int w_id, int ld_id, DBContext *pdb)
*
* PURPOSE: This function fills in data and then sends the order status
* input form back to the browser.
*
* ARGUMENTS: request_rec *req ptr to structure passed in the
* internet.
* int w_id warehouse id
* int ld_id login district id
*
* RETURNS: None
*
* COMMENTS: None
*
*/
void SendOrderStatusForm( request_rec *req, int w_id, int ld_id )
{
char *orderStatusForm;
RESERVE_FORM( ORDER_STATUS_FORM, orderStatusForm );
PutNumeric(WDID(w_id,ld_id),orderStatusFormIndexes[OS_WDID].iLen,
&orderStatusForm[orderStatusFormIndexes[OS_WDID].iStartIndex]);
PutNumeric(w_id,orderStatusFormIndexes[OS_WID].iLen,
&orderStatusForm[orderStatusFormIndexes[OS_WID].iStartIndex]);
SendResponse(req, orderStatusForm, giFormLen[ORDER_STATUS_FORM]);
UNRESERVE_FORM( ORDER_STATUS_FORM, orderStatusForm );
}
/* FUNCTION: void SendStockLevelForm(request_rec *req,
* int w_id, int d_id, DBContext *pdb)
*
* PURPOSE: This function puts the data into the input form and then
* returns the form to the browser.
*
* ARGUMENTS: request_rec *req structure pointer to passed
* in internet service information
* int w_id warehouse id
* int d_id district id
* DBContext *pdb pointer to database context.
*
* RETURNS: None
*
* COMMENTS: None
*
*/
void SendStockLevelForm( request_rec *req, int w_id, int d_id )
{
char *stockLevelForm;
RESERVE_FORM( STOCK_LEVEL_FORM, stockLevelForm );
PutNumeric(WDID(w_id,d_id),stockLevelFormIndexes[SL_WDID].iLen,
&stockLevelForm[stockLevelFormIndexes[SL_WDID].iStartIndex]);
PutNumeric(w_id,stockLevelFormIndexes[SL_WID].iLen,
&stockLevelForm[stockLevelFormIndexes[SL_WID].iStartIndex]);
PutNumeric(d_id,stockLevelFormIndexes[SL_DID].iLen,
&stockLevelForm[stockLevelFormIndexes[SL_DID].iStartIndex]);
SendResponse(req, stockLevelForm, giFormLen[STOCK_LEVEL_FORM]);
UNRESERVE_FORM( STOCK_LEVEL_FORM, stockLevelForm );
}
/* FUNCTION: void SendMainMenuForm(request_rec *req,
* int w_id, int ld_id, char *szStatus)
*
* PURPOSE: This function sends the main menu form to the browser.
*
* ARGUMENTS: request_rec *req IIS context structure pointer
* unique to this connection.
*
* int w_id warehouse id
* int ld_id login district id
* char *szStatus String to report previous
* operation status.
*
* RETURNS: None
*
* COMMENTS:
*/
void SendMainMenuForm( request_rec *req,int w_id, int ld_id, char *szStatus )
{
char *szForm;
int iStrLen;
static char *szNoStatus = "";
char *pszStatus;
pszStatus = ( NULL == szStatus ) ? szNoStatus : szStatus;
#if (DEBUG == 1)
fprintf(MyLogFile, "Before RESERVE_PANIC_FORM\n");
fflush(MyLogFile);
#endif
RESERVE_PANIC_FORM( szForm );
#if (DEBUG == 1)
fprintf(MyLogFile, "Before SendMainMenuForm\n");
fflush(MyLogFile);
#endif
iStrLen = sprintf( szForm, szMainMenuFormTemplate,req->uri, WDID(w_id,ld_id), pszStatus );
SendResponse(req, szForm, iStrLen);
UNRESERVE_PANIC_FORM( szForm );
}
/* FUNCTION: void SendWelcomeForm(request_rec *req)
*
* PURPOSE: This function sends the welcome form to the browser.
*
* ARGUMENTS: None
*
* RETURNS: None
*
* COMMENTS: The welcome form is generated on initialization.
*/
void SendWelcomeForm(request_rec *req)
{
char *mod_name;
#if (DEBUG == 1)
fprintf(MyLogFile, "SendWelcomeForm 1\n");
fflush(MyLogFile);
#endif
mod_name = strrchr( req->uri, '/' );
if( NULL != mod_name )
mod_name++;
else
{
fprintf(MyLogFile, "SendWelcomeForm: Null mod_name\n");
return;
}
iWelcomeFormLen = sprintf(szWelcomeForm, szWelcomeFormTemplate,mod_name);
#if (DEBUG == 1)
fprintf(MyLogFile, "SendWelcomeForm 2\n");
fflush(MyLogFile);
#endif
SendResponse( req, szWelcomeForm, iWelcomeFormLen );
}
/* FUNCTION: int ProcessQueryString(request_rec *req)
*
* PURPOSE: This function extracts the relevent information out
* of the http command passed in from the browser.
*
* ARGUMENTS: request_rec *req IIS context structure pointer
* unique to this connection.
*
* RETURNS: int server connection status code
*
* COMMENTS: If this is the initial connection i.e. client is at
* welcome screen then there will not be a terminal id or
* current form id if this is the case then the pTermid and
* pFormid return values are undefined.
*/
int ProcessQueryString(request_rec *req)
{
static char *beginptr = "Begin";
char *ptr;
char *cmdptr;
int cFormID;
int w_id;
int ld_id;
int status;
int retcode;
w_id = 0;
ld_id = 0;
#if (DEBUG == 1)
fprintf(MyLogFile, "Starting QueryString 1\n");
fprintf(MyLogFile, "&ptr=%x\n", &ptr);
fflush(MyLogFile);
#endif
if ( GetCharKeyValuePtr( req->args, '3', &ptr ))
{
cFormID = *ptr++;
if( !GetWDID( ptr, &w_id, &ld_id, &ptr ))
{
#if (DEBUG == 1)
fprintf(MyLogFile, "Calling SendErrorResponse\n");
fflush(MyLogFile);
#endif
SendErrorResponse( req, ERR_W_ID_INVALID, ERR_TYPE_WEBDLL, NULL,
w_id, ld_id, NULL );
return TRUE;
}
}
else
cFormID = '\0';
/* now figure out what command we have and execute it */
if ( !GetCharKeyValuePtr( ptr, '0', &cmdptr ))
{
if( req->args == NULL )
{
cmdptr = beginptr;
}
else
{
SendErrorResponse( req, ERR_COMMAND_UNDEFINED,ERR_TYPE_WEBDLL,
NULL, w_id, ld_id, NULL );
return TRUE;
}
}
if( '\0' == cFormID && !MATCHES_BEGIN( cmdptr ))
{
SendErrorResponse( req, ERR_INVALID_FORM_AND_CMD_NOT_BEGIN,
ERR_TYPE_WEBDLL, NULL, w_id, ld_id, NULL);
return TRUE;
}
status = TRUE;
if( MATCHES_PROCESS( cmdptr ))
{
#if (DEBUG == 1)
fprintf(MyLogFile, "Matches Process\n");
fflush(MyLogFile);
#endif
if( 'N' == cFormID )
retcode = ProcessNewOrderQuery( req, ptr, w_id, ld_id );
else if( 'P' == cFormID )
retcode = ProcessPaymentQuery( req, ptr, w_id, ld_id );
else if( 'D' == cFormID )
retcode = ProcessDeliveryQuery( req, ptr, w_id, ld_id );
else if( 'O' == cFormID )
retcode = ProcessOrderStatusQuery( req, ptr, w_id, ld_id );
else if( 'S' == cFormID )
retcode = ProcessStockLevelQuery( req, ptr, w_id, ld_id );
else
{
SendErrorResponse( req, ERR_INVALID_FORM, ERR_TYPE_WEBDLL,
NULL,w_id, ld_id, NULL );
return TRUE;
}
if( ERR_DB_PENDING == retcode )
status = TRUE;
else if( ERR_DB_SUCCESS != retcode )
{
#if (DEBUG == 1)
fprintf(MyLogFile, "Here We Are Again!!!\n");
fflush(MyLogFile);
#endif
if (!apr_table_get(req->headers_out, "PRTE PAD"))
{
SendErrorResponse( req, retcode, ERR_TYPE_WEBDLL, NULL,
w_id, ld_id, NULL );
}
return TRUE;
}
}
else if( MATCHES_BEGIN( cmdptr ))
BeginCmd( req );
else if( MATCHES_NEWORDER( cmdptr ))
SendNewOrderForm( req, w_id, ld_id );
else if( MATCHES_PAYMENT( cmdptr ))
SendPaymentForm( req, w_id, ld_id );
else if( MATCHES_ORDERSTATUS( cmdptr ))
SendOrderStatusForm( req, w_id, ld_id );
else if( MATCHES_STOCKLEVEL( cmdptr ))
SendStockLevelForm( req, w_id, ld_id );
else if( MATCHES_DELIVERY( cmdptr ))
SendDeliveryForm( req, w_id, ld_id );
else if( MATCHES_SUBMIT( cmdptr ))
SubmitCmd( req, &w_id, &ld_id );
else if( MATCHES_MENU( cmdptr ))
MenuCmd( req, w_id, ld_id );
else if( MATCHES_EXIT( cmdptr ))
ExitCmd( req );
else if( MATCHES_CLEAR( cmdptr ))
ClearCmd( req );
else
SendErrorResponse( req, ERR_COMMAND_UNDEFINED, ERR_TYPE_WEBDLL,
NULL, w_id, ld_id, NULL );
return status;
}
/* FUNCTION: PutFloat2(double dVal, int iFieldSize, char *pChar )
*
* PURPOSE: This function converts a double into a char string
* in the format of xx.xx
*
* ARGUMENTS: double dVal the value to convert to char
* int iFieldSize max size of char string
* char pChar string where to put value
*
* RETURNS: void
*
* COMMENTS: If the double exceeds the max field size entered,
* the char string will be filled with iFieldSize *'s
* to signal an error
*/
void PutFloat2( double dVal, int iFieldSize, char *pChar )
{
int iInt;
int iDecimal;
BOOL bSignFlag = TRUE;
int iSaveSize = iFieldSize;
char *pSaveStart = pChar;
char pAsterisk[] = "********************";
double dtmp;
pChar += (iFieldSize - 1);
dtmp=(dVal*100.0);
if(0 > dVal)
{
bSignFlag = FALSE;
iInt = abs((int)( dtmp ));
}
else
{
iInt = (int)( dtmp );
}
iDecimal = 2;
do
{
*pChar-- = ( iInt % 10 ) + '0';
iInt /= 10;
iFieldSize--;
} while( --iDecimal );
*pChar-- = '.';
iFieldSize--;
do
{
*pChar-- = ( iInt % 10 ) + '0';
iInt /= 10;
iFieldSize--;
} while( iFieldSize && iInt != 0 );
if( !iFieldSize && iInt != 0 )
{
/* put in string of ** to signal error */
memcpy(pSaveStart, pAsterisk, iSaveSize);
return;
}
if(!bSignFlag)
{
iFieldSize--;
if( 0 >= iFieldSize )
{
/* put in string of ** to signal error */
memcpy(pSaveStart, pAsterisk, iSaveSize);
return;
}
*pChar-- = '-';
}
/* Fill in the remaining spaces in the field with blanks. */
while( iFieldSize-- )
*pChar-- = ' ';
}
/* FUNCTION: void PutHTMLStrings( pPutStrStruct pStruct,
* char *szInput,
int iInputSize,
* char **szOutput,
int *iOutputSize )
*
* PURPOSE: This routine takes a template output string and a data structure
* containing strings, positions, and field widths of strings to be
* compied into the template. The routine scans all input strings to
* determine if any contain special charaters that need to be quoted
* in the output string. If none exist, the template is filled with
* the desired strings. If at least one special character exists in
* the output strings, a more expensive routine is called to build a
* new output string template containing the quoted strings.
*
* ARGUMENTS: pPutStrStruct pStruct pointer to structure containing the
* strings, positions and field lengths.
* char *szInput pointer to input form
* int iInputSize length of the input form
* char **szOutput pointer to the new input form
* it may or may not be different
* than the input form.
* int iOutputSize length of the new input form.
*
* RETURNS: none
*
* COMMENTS: none
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -