/* * Napi¹te testovací program "enumtest.c", kde ve funkci main - nejdøíve naètìte ze std vstupu jednu hodnotu a vytisknìte - potom vypisujte mìsíce do výstupního souboru dokud nedojde k chybovému ukonèení programu */ int main(void) { /* test - NEMÌNIT! */ char *l = setlocale(LC_ALL,"cs_CZ.iso-8859-2"); if(l==NULL) Error("setlocale: Nelze nastavit èeskou lokalizaci\n"); enum months m; m = ReadMonth(); // ète mìsíc PrintMonthShort(m); // tiskne krátké jméno printf("\n"); PrintMonth(m); // tiskne dlouhé jméno printf("\n\n"); for( m = Leden; m < 15; m++ ) { // úmyslná chyba PrintMonthShort(m); printf("\n"); } return 0; }
DateTime::DateTime( DataRef date ) { // Example: Sun, 11 Mar 1984 00:00:00 +0000 Verify( date.Length() == 31 ); m_dayOfWeek = ReadDayOfWeek( date.Slice( 0, 3 ) ); Verify( date.Slice( 3, 2 ) == DataRef( ", " ) ); m_day = ReadAsciiNumber<uint8_t>( date.Slice( 5, 2 ) ); Verify( date[7] == ' ' ); m_month = ReadMonth( date.Slice( 8, 3 ) ); Verify( date[11] == ' ' ); m_year = ReadAsciiNumber<uint32_t>( date.Slice( 12, 4 ) ); Verify( date[16] == ' ' ); m_hour = ReadAsciiNumber<uint8_t>( date.Slice( 17, 2 ) ); Verify( date[19] == ':' ); m_minute = ReadAsciiNumber<uint8_t>( date.Slice( 20, 2 ) ); Verify( date[22] == ':' ); m_second = ReadAsciiNumber<uint8_t>( date.Slice( 23, 2 ) ); Verify( date[25] == ' ' ); Verify( date.Slice( 25, 6 ) == DataRef( " +0000" ) ); }
bool CGTime::Read( TCHAR * pszVal ) { // Read the full date format. TCHAR * ppCmds[10]; int iQty = Str_ParseCmds( pszVal, ppCmds, COUNTOF(ppCmds), "/,: \t" ); if ( ! iQty ) return( false ); struct tm atm; atm.tm_wday = 0; /* days since Sunday - [0,6] */ atm.tm_yday = 0; /* days since January 1 - [0,365] */ atm.tm_isdst = 0; /* daylight savings time flag */ if ( isdigit( ppCmds[0][0] )) { // new format is "1999/8/1 14:30:18" if ( iQty < 6 ) { return( false ); } atm.tm_year = atoi( ppCmds[0] ) - 1900; atm.tm_mon = atoi( ppCmds[1] ) - 1; atm.tm_mday = atoi( ppCmds[2] ); atm.tm_hour = atoi( ppCmds[3] ); atm.tm_min = atoi( ppCmds[4] ); atm.tm_sec = atoi( ppCmds[5] ); } else { if ( iQty < 7 ) { return( false ); } TCHAR ch = ppCmds[1][0]; if ( isdigit(ch)) { // or http format is : "Tue, 03 Oct 2000 22:44:56 GMT" atm.tm_mday = atoi( ppCmds[1] ); atm.tm_mon = ReadMonth( ppCmds[2] ); atm.tm_year = atoi( ppCmds[3] ) - 1900; atm.tm_hour = atoi( ppCmds[4] ); atm.tm_min = atoi( ppCmds[5] ); atm.tm_sec = atoi( ppCmds[6] ); } else { // old format is "Tue Mar 30 14:30:18 1999" atm.tm_mon = ReadMonth( ppCmds[1] ); atm.tm_mday = atoi( ppCmds[2] ); atm.tm_hour = atoi( ppCmds[3] ); atm.tm_min = atoi( ppCmds[4] ); atm.tm_sec = atoi( ppCmds[5] ); atm.tm_year = atoi( ppCmds[6] ) - 1900; } } m_time = mktime(&atm); if ( toupper( ppCmds[iQty-1][0] ) == 'G' ) { // convert to GMT m_time -= (int)_timezone; } return( true ); }
void __fastcall TForm1::actRedesignClassificationsExecute(TObject *Sender) { lblStatus->Caption = ""; if(!MakeBackup()) { Log->Lines->Add("Не удалось создать резервную копию файла"); lblStatus->Caption = "Ошибка: Не удалось создать резервную копию файла"; return; } m_strRecomendations = ""; lblStatus->Caption = "Открываю файл на чтение..."; Variant app = Variant::CreateObject("Excel.Application"); app.OlePropertySet("Visible", true); Variant excel = app.OlePropertyGet("Workbooks").OleFunction("Open", WideString(m_strFileName.c_str())); Variant vSheets = excel.OlePropertyGet("Worksheets"); Variant vSheet = vSheets.OlePropertyGet("Item",m_nPageClassification); UnicodeString strPageName = vSheet.OlePropertyGet("Name"); if (strPageName.UpperCase() != UnicodeString("классификации").UpperCase()) { app.OleProcedure("Quit"); MessageBox (Handle, UnicodeString(L"Не верное имя страницы").c_str(), L"prompt", MB_OK); lblStatus->Caption = "Ошибка: Не верное имя страницы"; return; }; std::vector<exlClass> classes; ReadClassifications(vSheet, classes); std::vector<exlMonth> months; for (unsigned int i = 0; i < m_vMonth.size(); i++) { int nMonthPage = m_vMonth[i].Number; Variant vSheetMonth = vSheets.OlePropertyGet("Item",nMonthPage); ReadMonth(vSheetMonth, months); } // Log->Lines->Add("Обновляю линки." + IntToStr((int)months.size())); int nAll = classes.size() * months.size(); Log->Lines->Add("Всего записей в месяцах: " + IntToStr((int)months.size())); std::vector<exlClass> newclasses; int nRemovedClasses = 0; ProgressBar1->Max = nAll; ProgressBar1->Min = 0; ProgressBar1->Position = 0; lblStatus->Caption = "Поиск наименований которые отсутвуют в месяцах..."; Log->Lines->Add("Произвожу поиск наименований которые отсутвуют в месяцах..."); for (unsigned int iC = 0; iC < classes.size(); iC++) { exlClass cl = classes[iC]; cl.Monthes = ""; UnicodeString name = classes[iC].Name.UpperCase(); int nCount = 0; for (unsigned int iM = 0; iM < months.size(); iM++) { ProgressBar1->Position++; Application->ProcessMessages(); UnicodeString name2 = months[iM].Name.UpperCase(); if (name == name2) { nCount++; if (cl.Monthes.Pos(months[iM].Month) < 1) { cl.Monthes += months[iM].Month + ";"; } } } if (nCount > 0) { newclasses.push_back(cl); } else { nRemovedClasses++; Log->Lines->Add("\tНаименование '" + cl.Name + "' - нигде не встречается и будет удалено из классификаций"); } } Log->Lines->Add(" ** "); nAll = newclasses.size() * months.size(); ProgressBar1->Max = nAll; ProgressBar1->Min = 0; ProgressBar1->Position = 0; int nAddClasses = 0; lblStatus->Caption = "Поиск наименований которые отсутвуют в списке классификаций..."; Log->Lines->Add("Произвожу поиск наименований которые отсутвуют в списке классификаций..."); for (unsigned int iM = 0; iM < months.size(); iM++) { UnicodeString name = months[iM].Name.UpperCase(); int nCount = 0; for (unsigned int iC = 0; iC < newclasses.size(); iC++) { ProgressBar1->Position++; Application->ProcessMessages(); UnicodeString name2 = newclasses[iC].Name.UpperCase(); if (name == name2) { nCount++; } } if (nCount == 0) { Log->Lines->Add("\tНаименование '" + months[iM].Name + "' - будет добавлено в классификации"); exlClass cl; cl.Name = months[iM].Name; cl.Class = m_sUnknownClass; cl.Monthes += months[iM].Month + ";"; newclasses.push_back(cl); nAddClasses++; nAll = newclasses.size() * months.size(); ProgressBar1->Max = nAll; } } Log->Lines->Add("Будет удалено классификаций: " + IntToStr(nRemovedClasses)); Log->Lines->Add("Будет добавлено классификаций: " + IntToStr(nAddClasses)); Log->Lines->Add("Всего классификаций: " + IntToStr((int)(newclasses.size()))); WriteClassifications(vSheet, newclasses); lblStatus->Caption = "Сохраняю файл..."; Log->Lines->Add("Сохраняю файл..."); try { app.OlePropertySet("DisplayAlerts",false); excel.OleProcedure("SaveAs", WideString(m_strFileName.c_str())); Log->Lines->Add("Данные сохранены!"); } catch (...) { lblStatus->Caption = "Ошибка: Пожалуйста закройте все открытые копии файла и повторите операцию"; Log->Lines->Add("Ошибка: Пожалуйста закройте все открытые копии файла и повторите операцию"); } ProgressBar1->Position = 0; app.OleProcedure("Quit"); lblStatus->Caption = ""; }
void __fastcall TForm1::actCalcClassificationExecute(TObject *Sender) { if(!MakeBackup()) { Log->Lines->Add("Не удалось создать резервную копию файла"); return; } Variant app = Variant::CreateObject("Excel.Application"); app.OlePropertySet("Visible", true); Variant excel = app.OlePropertyGet("Workbooks").OleFunction("Open", WideString(m_strFileName.c_str())); Variant vSheets = excel.OlePropertyGet("Worksheets"); Variant vSheet = vSheets.OlePropertyGet("Item",m_nPageClassification); UnicodeString strPageName = vSheet.OlePropertyGet("Name"); if (strPageName.UpperCase() != UnicodeString("классификации").UpperCase()) { app.OleProcedure("Quit"); MessageBox (Handle, UnicodeString(L"Не верное имя страницы").c_str(), L"prompt", MB_OK); return; }; std::vector<exlClass> classes; ReadClassifications(vSheet, classes); std::vector<exlMonth> months; Variant vSheetMonth; double fSumSum = 0; for (unsigned int i = 0; i < m_vMonth.size(); i++) { if (cmbMonth->Text == m_vMonth[i].Name) { int nMonthPage = m_vMonth[i].Number; vSheetMonth = vSheets.OlePropertyGet("Item", nMonthPage); ReadMonth(vSheetMonth, months); ReadMonthSum(vSheetMonth, fSumSum); } } Log->Lines->Add("Произвожу расчет..."); ProgressBar1->Max = months.size(); ProgressBar1->Min = 0; double nSumHand = 0; std::vector<exlSumClass> vSumClasses; for (unsigned int i = 0; i < months.size(); i++) { ProgressBar1->Position = i; int nFound = 0; nSumHand += months[i].Price; for (unsigned int iC = 0; iC < classes.size(); iC++) { if (nFound == 0 && classes[iC].Name.UpperCase() == months[i].Name.UpperCase()) { months[i].Class = classes[iC].Class; months[i].LinkToClassification = createHyperLinkToClassification(classes, iC); nFound++; } } if (nFound == 0) { months[i].Class = m_sUnknownClass; } nFound = 0; for (unsigned int iC = 0; iC < vSumClasses.size(); iC++) { if (vSumClasses[iC].Name.UpperCase() == months[i].Class.UpperCase()) { vSumClasses[iC].Sum += months[i].Price; nFound++; } } if (nFound == 0) { exlSumClass sm; sm.Name = months[i].Class; sm.Sum = months[i].Price; vSumClasses.push_back(sm); } } /*for (unsigned int i = 0; i < vSumClasses.size(); i++) { Log->Lines->Add(vSumClasses[i].Name + " = " + FloatToStr(vSumClasses[i].Sum)); }*/ Log->Lines->Add("Готово."); Log->Lines->Add("Сортирую классификации..."); ProgressBar1->Max = 100; ProgressBar1->Min = 0; { int nPermutation = 1; while (nPermutation > 0) { nPermutation = 0; for (unsigned int iC = 0; iC < vSumClasses.size()-1; iC++) { ProgressBar1->Position = (ProgressBar1->Position+1) % ProgressBar1->Max; Application->ProcessMessages(); if (vSumClasses[iC].Name.UpperCase() > vSumClasses[iC+1].Name.UpperCase()) { exlSumClass buf = vSumClasses[iC]; vSumClasses[iC] = vSumClasses[iC+1]; vSumClasses[iC+1] = buf; nPermutation++; } } } ProgressBar1->Position = 0; } Log->Lines->Add("Готово."); Log->Lines->Add("Очистка старых данных"); ProgressBar1->Max = 100; ProgressBar1->Min = 0; // clear sum classes, 11,12 { bool b = true; int nRow = 1; while (b) { b = false; nRow++; ProgressBar1->Position = (ProgressBar1->Position+1) % ProgressBar1->Max; Application->ProcessMessages(); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,11).OleProcedure("ClearFormats"); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OleProcedure("ClearFormats"); UnicodeString sValue11 = vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,11).OlePropertyGet("Value"); UnicodeString sValue12 = vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertyGet("Value"); clearCell(vSheetMonth, nRow, 11); clearCell(vSheetMonth, nRow, 12); if (sValue12.Trim().Length() > 0 || sValue11.Trim().Length() > 0) { b = true; } } ProgressBar1->Position = 0; } // clear 14,15,16,17 { bool b = true; int nRow = 1; while (b) { b = false; nRow++; ProgressBar1->Position = (ProgressBar1->Position+1) % ProgressBar1->Max; Application->ProcessMessages(); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,14).OleProcedure("ClearFormats"); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,15).OleProcedure("ClearFormats"); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,16).OleProcedure("ClearFormats"); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,17).OleProcedure("ClearFormats"); UnicodeString sValue14 = vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,14).OlePropertyGet("Value"); UnicodeString sValue15 = vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,15).OlePropertyGet("Value"); UnicodeString sValue16 = vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,16).OlePropertyGet("Value"); UnicodeString sValue17 = vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,17).OlePropertyGet("Value"); clearCell(vSheetMonth, nRow, 14); clearCell(vSheetMonth, nRow, 15); clearCell(vSheetMonth, nRow, 16); clearCell(vSheetMonth, nRow, 17); if ( sValue14.Trim().Length() > 0 || sValue15.Trim().Length() > 0 || sValue16.Trim().Length() > 0 || sValue17.Trim().Length() > 0 ) { b = true; } } ProgressBar1->Position = 0; } Log->Lines->Add("Запись новых данных"); { double nSum = 0; int nRow = 2; vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,11).OlePropertySet("Value", WideString("Класс")); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertySet("Value", WideString("Сумма")); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,11).OlePropertyGet("Font").OlePropertySet("Bold", true); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertyGet("Font").OlePropertySet("Bold", true); vSheetMonth.OlePropertyGet("Columns", WideString("K")).OlePropertySet("ColumnWidth", 20); vSheetMonth.OlePropertyGet("Columns", WideString("L")).OlePropertySet("ColumnWidth", 15); setBorders(vSheetMonth, nRow, 11); setBorders(vSheetMonth, nRow, 12); setColor(vSheetMonth, nRow, 11, RGBToInt(240, 230, 140)); setColor(vSheetMonth, nRow, 12, RGBToInt(240, 230, 140)); ProgressBar1->Max = vSumClasses.size(); ProgressBar1->Min = 0; for (unsigned int i = 0; i < vSumClasses.size(); i++) { nRow++; ProgressBar1->Position = i; nSum += vSumClasses[i].Sum; vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,11).OlePropertySet("Value", WideString(vSumClasses[i].Name)); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertySet("Value", WideString(vSumClasses[i].Sum)); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertySet("NumberFormat", WideString(m_strNumberFormat)); setBorders(vSheetMonth, nRow, 11); setBorders(vSheetMonth, nRow, 12); } nRow++; ProgressBar1->Position = 0; vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,11).OlePropertySet("Value", WideString("Итого:")); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertySet("Value", WideString(nSum)); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertySet("NumberFormat", WideString(m_strNumberFormat)); nRow++; vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,11).OlePropertySet("Value", WideString("Сумма сумм по дням:")); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertySet("Value", WideString(fSumSum)); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,12).OlePropertySet("NumberFormat", WideString(m_strNumberFormat)); } { double nSum = 0; int nRow = 2; vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,14).OlePropertySet("Value", WideString("Класс")); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,15).OlePropertySet("Value", WideString("Наименование")); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,16).OlePropertySet("Value", WideString("Цена")); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,17).OlePropertySet("Value", WideString("Ссылка")); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,14).OlePropertyGet("Font").OlePropertySet("Bold", true); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,15).OlePropertyGet("Font").OlePropertySet("Bold", true); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,16).OlePropertyGet("Font").OlePropertySet("Bold", true); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,17).OlePropertyGet("Font").OlePropertySet("Bold", true); vSheetMonth.OlePropertyGet("Columns", WideString("N")).OlePropertySet("ColumnWidth", 20); vSheetMonth.OlePropertyGet("Columns", WideString("O")).OlePropertySet("ColumnWidth", 50); vSheetMonth.OlePropertyGet("Columns", WideString("P")).OlePropertySet("ColumnWidth", 15); vSheetMonth.OlePropertyGet("Columns", WideString("Q")).OlePropertySet("ColumnWidth", 50); setBorders(vSheetMonth, nRow, 14); setBorders(vSheetMonth, nRow, 15); setBorders(vSheetMonth, nRow, 16); setBorders(vSheetMonth, nRow, 17); setColor(vSheetMonth, nRow, 14, RGBToInt(240, 230, 140)); setColor(vSheetMonth, nRow, 15, RGBToInt(240, 230, 140)); setColor(vSheetMonth, nRow, 16, RGBToInt(240, 230, 140)); setColor(vSheetMonth, nRow, 17, RGBToInt(240, 230, 140)); ProgressBar1->Max = months.size(); ProgressBar1->Min = 0; for (unsigned int i = 0; i < months.size(); i++) { nRow++; ProgressBar1->Position = i; nSum += months[i].Price; vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,14).OlePropertySet("Value", WideString(months[i].Class)); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,15).OlePropertySet("Value", WideString(months[i].Name)); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,16).OlePropertySet("Value", WideString(months[i].Price)); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,16).OlePropertySet("NumberFormat", WideString(m_strNumberFormat)); if (months[i].Price < 0) { setColor(vSheetMonth, nRow, 16, RGBToInt(240, 230, 140)); } // TODO: check linkt to classification // vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,17).OlePropertySet("Value", WideString(months[i].LinkToClassification.c_str())); setBorders(vSheetMonth, nRow, 14); setBorders(vSheetMonth, nRow, 15); setBorders(vSheetMonth, nRow, 16); setBorders(vSheetMonth, nRow, 17); } nRow++; ProgressBar1->Position = 0; vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,14).OlePropertySet("Value", WideString("Итого:")); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,16).OlePropertySet("Value", WideString(nSum)); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,16).OlePropertySet("NumberFormat", WideString(m_strNumberFormat)); vSheetMonth.OlePropertyGet("Cells").OlePropertyGet("Item",nRow,17).OlePropertySet("NumberFormat", WideString(m_strNumberFormat)); } Log->Lines->Add("Сохраняю файл..."); try { app.OlePropertySet("DisplayAlerts",false); excel.OleProcedure("SaveAs", WideString(m_strFileName.c_str())); Log->Lines->Add("Данные сохранены!"); } catch (...) { Log->Lines->Add("Ошибка: Пожалуйста закройте все открытые копии файла и повторите операцию"); } ProgressBar1->Position = 0; app.OleProcedure("Quit"); }
int main() { struct tm tm; char *ptr = strptime("17410105012000", "%H%M%S%d%m%Y", &tm); printf( "%s: %s, %d/%d/%d %d:%d:%d", (ptr != NULL && *ptr == '\0') ? "OK" : "ERR", tm.tm_wday == 0 ? "Sun" : (tm.tm_wday == 1 ? "Mon" : (tm.tm_wday == 2 ? "Tue" : (tm.tm_wday == 3 ? "Wed" : (tm.tm_wday == 4 ? "Thu" : (tm.tm_wday == 5 ? "Fri" : (tm.tm_wday == 6 ? "Sat" : "ERR")))))), tm.tm_mon + 1, tm.tm_mday, tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec); printf("\n"); ReadMonth("jan"); ReadMonth("january"); ReadMonth("feb"); ReadMonth("february"); ReadMonth("march"); ReadMonth("mar"); ReadMonth("april"); ReadMonth("may"); ReadMonth("may"); ReadMonth("june"); ReadMonth("jul"); ReadMonth("august"); ReadMonth("september"); ReadMonth("oct"); ReadMonth("nov"); ReadMonth("november"); ReadMonth("december"); return 0; }