BOOL SearchAgain(WORD Flags) /*Flags: 1=Reverse (search in opposite direction) * 2=pop up dialog if not searched before */ { BOOL Return; ULONG OldLength; HideEditCaret(); if (Flags & 2 && !MatchValid) { SearchDialog(); return (TRUE); } OldLength = SelectCount; if (OldLength) { InvalidateArea(&SelectStart, SelectCount, 1); SelectCount = 0; UpdateWindow(hwndMain); } SelectStart = CurrPos; Return = SearchAndStatus(&SelectStart, (WORD)((Flags & 1) | 2)); if (Return) { if ((OldLength==0 && Mode!=InsertMode) || ComparePos(&SelectStart, &CurrPos) == 0) { if (CountBytes(&EndMatch) - CountBytes(&StartPos) == OldLength) { SelectStart = CurrPos; Return = SearchAndStatus(&SelectStart, (WORD)(Flags & 1)); } } if (Return) { NewPosition(&SelectStart); UpdateWindow(hwndMain); SelectStart = StartPos; SelectBytePos = CountBytes(&StartPos); SelectCount = CountBytes(&EndMatch) - SelectBytePos; InvalidateArea(&SelectStart, SelectCount, 0); UpdateWindow(hwndMain); } } CheckClipboard(); ShowEditCaret(); GetXPos(&CurrCol); return (Return); }
void CUpgradeDialog::OnOrderbymodem() { CString csReason; // Update the product items with the selection flags from the list box. m_ProductList.UpdateProductItems(); if (GetApp()->Offer()->CountProductFlags(PRODUCT_ITEM_Selected) == 0) { AfxMessageBox(IDS_NO_ITEMS_SELECTED_MODEM); return; } // Build an CInstallInfo structure for us to use. CInstallInfo Info; // Perform the modem search. CSearchingDialog SearchDialog(this); switch (SearchDialog.DoModal()) { case IDOK: { // User wants to send their order over the modem. int nPort = SearchDialog.m_nPort; long lSpeed = SearchDialog.m_lSpeed; BOOL fRetryRegister; int nPaymentMethod = 0; CString csCardNumber; CString csExpirationDate; do { fRetryRegister = FALSE; // Ask the user for some information. CRegistrationInformationDialog Dialog((UINT)-1, this); TRY { Dialog.m_fModemOrder = TRUE; Dialog.m_nPaymentMethod = nPaymentMethod; Dialog.m_csCardNumber = csCardNumber; Dialog.m_csExpirationDate = csExpirationDate; } END_TRY // We need to compute the various order totals so we can reflect them // in the order information dialog. long lTotal = 0; long lSubTotal = 0; TotalItems(&m_ProductList, lTotal); lSubTotal = lTotal; long lTax = m_TaxList.CurrentTax(lTotal); lTotal += lTax; long lShipping = lSubTotal > 0 ? Info.m_pOffer->ProcessingFee() : 0; lTotal += lShipping; // Fill in values used by RegInfo dialog. Dialog.m_lSubTotal = lSubTotal; Dialog.m_lTax = lTax; Dialog.m_lShipping = lShipping; Dialog.m_pOrderForm = this; if (Dialog.DoModal() == IDOK) { CMsregPacketHeader* pPacketHeader = NULL; CMsregPacketCatalogOrderRequest* pCatalogOrderData = NULL; CString csFileName; CFile cfFile; CString csWindowsDir; char* pTempName = NULL; BOOL fSuccess = FALSE; TRY { // Tax status may have changed, recompute some stuff. lTotal = lSubTotal; lTax = m_TaxList.CurrentTax(lTotal); lTotal += lTax; lShipping = lSubTotal > 0 ? Info.m_pOffer->ProcessingFee() : 0; lTotal += lShipping; nPaymentMethod = Dialog.m_nPaymentMethod; csCardNumber = Dialog.m_csCardNumber; csExpirationDate = Dialog.m_csExpirationDate; // Package the user's order into a packet. pCatalogOrderData = new CMsregPacketCatalogOrderRequest; // Product name. pCatalogOrderData->ProductName() = GetApp()->ApplicationName(); // Product version. pCatalogOrderData->AddField("Version", GetApp()->MsRegIniFile().GetString(MSREGINI_Section_Configuration, MSREGINI_Configuration_Version)); // Part Number. pCatalogOrderData->AddField("ParentPartNumber", GetApp()->MsRegIniFile().GetString(MSREGINI_Section_Configuration, MSREGINI_Configuration_ParentPartNumber)); // User information. pCatalogOrderData->AddField("FirstName", Dialog.m_csFirstName); pCatalogOrderData->AddField("LastName", Dialog.m_csLastName); pCatalogOrderData->AddField("Company", Dialog.m_csCompany); pCatalogOrderData->AddField("Title", ""); pCatalogOrderData->AddField("Address1", Dialog.m_csAddress1); pCatalogOrderData->AddField("Address2", Dialog.m_csAddress2); pCatalogOrderData->AddField("City", Dialog.m_csCity); pCatalogOrderData->AddField("State", Dialog.m_csState); pCatalogOrderData->AddField("Country", Dialog.m_csCountry); pCatalogOrderData->AddField("Zip", Dialog.m_csZip); pCatalogOrderData->AddField("Phone", Dialog.m_csPhone); pCatalogOrderData->AddField("Email", Dialog.m_csEmail); static char* PaymentMethodStrings[] = { "VSA", // Visa "MC", // MasterCard "AMX", // American Express "DIS" // Discover }; ASSERT((Dialog.m_nPaymentMethod >= 0) && (Dialog.m_nPaymentMethod < (sizeof(PaymentMethodStrings)/sizeof(PaymentMethodStrings[0])))); if ((Dialog.m_nPaymentMethod >= 0) && (Dialog.m_nPaymentMethod < (sizeof(PaymentMethodStrings)/sizeof(PaymentMethodStrings[0])))) { pCatalogOrderData->AddField("PaymentMethod", PaymentMethodStrings[Dialog.m_nPaymentMethod]); } pCatalogOrderData->AddField("CardNumber", Dialog.m_csCardNumber); pCatalogOrderData->AddField("ExpirationDate", Dialog.m_csExpirationDate); // Tax, shipping, and total. pCatalogOrderData->Tax() = (DWORD)lTax; pCatalogOrderData->Shipping() = (DWORD)lShipping; pCatalogOrderData->Total() = (DWORD)lTotal; // Offer codes. pCatalogOrderData->OfferCode() = Info.m_pOffer->OfferCode(); // Result codes. Info.GetLRCFromProducts(pCatalogOrderData->RequestCode()); // Line Items. AddCatalogOrderLineItems(pCatalogOrderData, Info.m_pOffer); // Build packet header. pPacketHeader = new CMsregPacketHeader; // Customer ID. pPacketHeader->CustomerId() = GetApp()->UserIniFile().GetString(MSREGUSRINI_Section_CustomerInfo, MSREGUSRINI_CustomerInfo_CustomerNumber); // Packet. pPacketHeader->AddPacket(pCatalogOrderData); pCatalogOrderData = NULL; // Get the Windows directory in case we need to create a // temporary file there. if (GetWindowsDirectory(csWindowsDir.GetBuffer(_MAX_PATH), _MAX_PATH) == 0) { csWindowsDir.Empty(); } else { csWindowsDir.ReleaseBuffer(); } // Create a temporary file name. pTempName = _tempnam((LPSTR)(LPCSTR)csWindowsDir, "REG"); if (pTempName != NULL) { // Delete the file csFileName = pTempName; free(pTempName); pTempName = NULL; if (cfFile.Open(csFileName, CFile::modeCreate|CFile::modeWrite|CFile::shareExclusive)) { // Write out the packet to the temp file. pPacketHeader->WriteToFile(cfFile); fSuccess = TRUE; } } } END_TRY // Clean up (fSuccess indicates whether we actually had success.) delete pPacketHeader; pPacketHeader = NULL; delete pCatalogOrderData; pCatalogOrderData = NULL; cfFile.Close(); if (pTempName != NULL) { free(pTempName); pTempName = NULL; } // If we were not successful, then it was because of some internal problem // such as running out of memory or not being able to create the file. // Put up a message and let the user try again if they want. if (!fSuccess) { AfxMessageBox(IDS_COULD_NOT_SAVE_INFORMATION); fRetryRegister = TRUE; } else { // Attempt to send the file to the receiver. CSendingDialog SendingDialog(nPort, lSpeed, csFileName, this); switch (SendingDialog.DoModal()) { case IDOK: { // The request was successfully transmitted, we should have // a response. Check if the order was successfully processed. DWORD dwResult = CMsregPacketCatalogOrderResponse::CATALOGORDERRESULT_Error; TRY { // Attempt to open the response file. if (!cfFile.Open(csFileName, CFile::modeRead|CFile::shareExclusive)) { AfxThrowUserException(); } // Read the response packet. pPacketHeader = new CMsregPacketHeader; pPacketHeader->ReadFromFile(cfFile); // Validate the response. CMsregPacketCatalogOrderResponse* pResponse; if ((pPacketHeader->Type() != CMsregPacket::BLOCK_PacketHeader) || (pPacketHeader->Version() != CMsregPacket::VERSION_PacketHeader) || (pPacketHeader->PacketCount() != 1) || ((pResponse = (CMsregPacketCatalogOrderResponse*)(pPacketHeader->GetPacket(0))) == NULL) || (pResponse->Type() != CMsregPacket::BLOCK_CatalogOrderResponse) || (pResponse->Version() != CMsregPacket::VERSION_CatalogOrderResponse)) { AfxThrowUserException(); } // Get the result. dwResult = pResponse->Result(); // Got a response, see if the order was successful. if (dwResult != CMsregPacketCatalogOrderResponse::CATALOGORDERRESULT_Ok) { AfxThrowUserException(); } // Remember their customer ID. GetApp()->UserIniFile().WriteString(MSREGUSRINI_Section_CustomerInfo, MSREGUSRINI_CustomerInfo_CustomerNumber, pPacketHeader->CustomerId()); // Remember that they're registered. GetApp()->UserIniFile().WriteInteger(GetApp()->ApplicationName(), MSREGUSRINI_Application_Registered, 1); // "Bonus Enable" them. GetApp()->UserIniFile().WriteString(GetApp()->ApplicationName(), MSREGUSRINI_Application_RegistrationCode, MODEM_REGISTRATION_CODE); // License the products (without confirming LAC). Info.LicenseSelectedProducts(); // Update the dialog to reflect the new state of the licensed products. CheckDlgButton(IDC_TAX_CHECK, GetApp()->UserNeedsTax()); m_ProductList.DisableLicensedItems(); UpdateDialog(); // Let the user play with their new toys. OnInstall(); } CATCH_ALL(e) { csReason.Empty(); // Some sort of error occurred, report it. switch (dwResult) { case CMsregPacketCatalogOrderResponse::CATALOGORDERRESULT_InvalidCreditCardNumber: { Util::SafeLoadString(IDS_INVALID_CREDIT_CARD_NUMBER, csReason); break; } case CMsregPacketCatalogOrderResponse::CATALOGORDERRESULT_CreditCardExpired: { Util::SafeLoadString(IDS_EXPIRED_CREDIT_CARD, csReason); break; } case CMsregPacketCatalogOrderResponse::CATALOGORDERRESULT_IncompleteCustomerInformation: { Util::SafeLoadString(IDS_INCOMPLETE_CUSTOMER_INFORMATION, csReason); break; } default: { Util::SafeLoadString(IDS_COULD_NOT_PROCESS, csReason); break; } } if (!csReason.IsEmpty()) { COrderFailedDialog Dialog(csReason, this); Dialog.DoModal(); } // Let the user try again. fRetryRegister = TRUE; } END_CATCH_ALL // Clean up. delete pPacketHeader; pPacketHeader = NULL; cfFile.Close(); break; } case IDCANCEL: { // They want to go back. Just go back to the register dialog. fRetryRegister = TRUE; break; } case IDABORT: { // Some sort of modem error occurred, report it. CCallFailedDialog Dialog(this); Dialog.DoModal(); fRetryRegister = TRUE; break; } default: { ASSERT(FALSE); break; } } } // Make sure we delete temporary file. TRY { CFile::Remove(csFileName); } END_TRY } } while (fRetryRegister); break; } case IDABORT: { // No modem was found, report this fact. CNoModemDialog Dialog(this); Dialog.DoModal(); break; } } // Make sure the dialog is up to date. UpdateDialog(); }