#if !defined _RSREQUEST_ #define _REQUEST_ // factors which influence who the post gets sent to // // // PUBLIC: post to all (manu, dealer, owner) // PRIVATE: New Car (manu, dealer) // Old Car (dealer, owner) // // #define INIT_STRING(s) { wcscpy(s, L"\0"); } #define INIT_VALUE(v) { v = 0; } #define READ_STRING(s, str) { fgetws(s, 64, str); s[wcslen(s)-1] = L'\0'; } #define READ_STRING128(s, str) { fgetws(s, 128, str); s[wcslen(s)-1] = L'\0'; } class RSRequest { public: TCHAR m_szMake[64]; // Ford TCHAR m_szModel[64]; // Explorer TCHAR m_szYear[64]; // 1999 int m_iCondition; // 0 = dont care, 1 = old, 2 = new TCHAR m_szColor[64]; // Blue int m_iTransmission; // 0 = dont care, 1 = automatic, 2 = manual int m_iType; // 0 = dont care, 1 = 2 door, 2 = 4 door TCHAR m_szLocation[64]; // Texas TCHAR m_szPriceRange[64]; // Texas int m_iTargetPrice; // 6000 int m_iRequestDuration; // 35 days (1 month 5 days) TCHAR m_szComments[128]; // 'blah blah blah public: int m_iOrderID; RSRequest(); void EraseStep_1(); void SetStep_1(TCHAR* make, TCHAR* model, TCHAR* year); void SetStep_2(int condition, TCHAR* color, int transmission); void SetStep_3(int type, TCHAR* location); void SetStep_4(TCHAR* pricerange, int targetprice, int duration); void SetStep_5(TCHAR* comments); void PostNewRequest(RSUser* user); int GetNewRequestID(); }; #endif int RSRequest::GetNewRequestID() { FILE *stream; int req = 0; // open account file stream = _wfopen(L"orderid.txt", L"a+"); // automatic fail login, no file opened if( stream != NULL ) { while( !feof( stream ) ) { fwscanf(stream, L"%i", &req); } m_iOrderID = req + 1; fwprintf(stream, L"%i\n", m_iOrderID); fclose(stream); } return m_iOrderID; } void RSRequest::PostNewRequest(RSUser* user) { FILE *stream; // open request file stream = _wfopen(L"request.txt", L"a+"); // automatic fail login, no file opened if( stream != NULL ) { GetNewRequestID(); // start post data fwprintf(stream, L"%s\n", L"/P"); // write userid fwprintf(stream, L"%s\n", ((RSBuyer*)user)->GetUserID()); // write orderid fwprintf(stream, L"%i\n", m_iOrderID); fwprintf(stream, L"%s\n", m_szMake); fwprintf(stream, L"%s\n", m_szModel); fwprintf(stream, L"%s\n", m_szYear); fwprintf(stream, L"%i\n", m_iCondition); fwprintf(stream, L"%s\n", m_szColor); fwprintf(stream, L"%i\n", m_iTransmission); fwprintf(stream, L"%i\n", m_iType); fwprintf(stream, L"%s\n", m_szLocation); fwprintf(stream, L"%s\n", m_szPriceRange); fwprintf(stream, L"%i\n", m_iTargetPrice); fwprintf(stream, L"%i\n", m_iRequestDuration); fwprintf(stream, L"%s\n", m_szComments); // start post data fwprintf(stream, L"%s\n", L"\\P"); fclose(stream); } } void RSRequest::EraseStep_1() { wcscpy(m_szMake, L"\0"); wcscpy(m_szModel, L"\0"); wcscpy(m_szYear, L"\0"); } void RSRequest::SetStep_1(TCHAR* make, TCHAR* model, TCHAR* year) { wcscpy(m_szMake, make); wcscpy(m_szModel, model); wcscpy(m_szYear, year); } void RSRequest::SetStep_2(int condition, TCHAR* color, int transmission) { m_iCondition = condition; wcscpy(m_szColor, color); m_iTransmission = transmission; } void RSRequest::SetStep_3(int type, TCHAR* location) { m_iType = type; wcscpy(m_szLocation, location); } void RSRequest::SetStep_4(TCHAR* pricerange, int targetprice, int duration) { wcscpy(m_szPriceRange, pricerange); m_iTargetPrice = targetprice; m_iRequestDuration = duration; } void RSRequest::SetStep_5(TCHAR* comments) { wcscpy(m_szComments, comments); } RSRequest::RSRequest() { wcscpy(m_szMake, L"\0"); wcscpy(m_szModel, L"\0"); wcscpy(m_szYear, L"\0"); m_iCondition = 0; wcscpy(m_szColor, L"\0"); m_iTransmission = 0; m_iType = 0; wcscpy(m_szLocation, L"\0"); wcscpy(m_szPriceRange, L"\0"); m_iTargetPrice = 0; m_iRequestDuration = 0; wcscpy(m_szComments, L"\0"); }