Advertisement
Guest User

Первая без комментов

a guest
Jan 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 38.01 KB | None | 0 0
  1. #include <windows.h>
  2. #include <tchar.h>  
  3. #include <string>
  4. #include <vector>
  5. #include <iostream>
  6. #include <fstream>
  7. #include <iomanip>
  8. #include <algorithm>
  9. #include "commctrl.h"
  10. #include <ctime>
  11.  
  12. static TCHAR szWindowClass[] = _T("win32app");
  13.  
  14. static TCHAR szTitle[] = _T("Библиотека");
  15.  
  16. HINSTANCE hInst;
  17. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  18.  
  19. HWND hWnd;
  20.  
  21. HMENU hMenuBar;
  22.  
  23. HMENU hSubMenu1;
  24. HMENU hSubMenu2;
  25. HMENU hSubMenu3;
  26. HMENU hSubMenu4;
  27.  
  28. HWND hEdit;
  29. HWND hEdit2;
  30. HWND hEdit3;
  31. HWND hEdit4;
  32. HWND hEdit5;
  33. HWND hEdit6;
  34.  
  35. HWND label1;
  36. HWND label2;
  37. HWND label3;
  38. HWND label4;
  39. HWND label5;
  40. HWND label6;
  41.  
  42. HWND hButton1;
  43. HWND hButton2;
  44. HWND hWndList;
  45.  
  46. HWND hEdit7; HWND hEdit8; HWND hEdit9; HWND hEdit10; HWND hEdit11; HWND hEdit12;  HWND hEdit13;
  47. HWND label7; HWND label8; HWND label9; HWND label10; HWND label11; HWND label12;  HWND label13;
  48.  
  49. int CALLBACK WinMain(
  50.     _In_ HINSTANCE hInstance,
  51.     _In_ HINSTANCE hPrevInstance,
  52.     _In_ LPSTR     lpCmdLine,
  53.     _In_ int       nCmdShow
  54. )
  55. {
  56.     WNDCLASSEX wcex;
  57.  
  58.     wcex.cbSize = sizeof(WNDCLASSEX);
  59.     wcex.style = CS_HREDRAW | CS_VREDRAW;
  60.     wcex.lpfnWndProc = WndProc;
  61.     wcex.cbClsExtra = 0;
  62.     wcex.cbWndExtra = 0;
  63.     wcex.hInstance = hInstance;
  64.     wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
  65.     wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  66.     wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  67.     wcex.lpszMenuName = NULL;
  68.     wcex.lpszClassName = szWindowClass;
  69.     wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
  70.  
  71.     if (!RegisterClassEx(&wcex))
  72.     {
  73.         MessageBox(NULL,
  74.             _T("Call to RegisterClassEx failed!"),
  75.             _T("Win32 Guided Tour"),
  76.             NULL);
  77.  
  78.         return 1;
  79.     }
  80.  
  81.     hInst = hInstance;
  82.     hMenuBar = CreateMenu();
  83.     hSubMenu3 = CreateMenu();
  84.     AppendMenu(hMenuBar, MF_STRING, 6, "Библиотека");
  85.     hSubMenu1 = CreateMenu();
  86.     AppendMenu(hMenuBar, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu1, "Книга");
  87.     AppendMenu(hSubMenu1, MF_STRING, 10, "Добавить");
  88.     AppendMenu(hSubMenu1, MF_STRING, 2, "Удалить");
  89.     AppendMenu(hSubMenu1, MF_STRING, 7, "Поменять местами");
  90.     AppendMenu(hSubMenu1, MF_STRING, 3, "Найти");
  91.     hSubMenu2 = CreateMenu();
  92.     AppendMenu(hSubMenu2, MF_STRING, 4, "По стоимости");
  93.     AppendMenu(hSubMenu2, MF_STRING, 5, "По жанру");
  94.     AppendMenu(hSubMenu2, MF_STRING, 8, "Размешать");
  95.     AppendMenu(hMenuBar, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu2, "Сортировка");
  96.     hSubMenu4 = CreateMenu();
  97.     AppendMenu(hMenuBar, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu4, "Особый поиск");
  98.     AppendMenu(hSubMenu4, MF_STRING, 9, "5 самых старых книг по всем жанрам");
  99.  
  100.     hWnd = CreateWindow(
  101.         szWindowClass,
  102.         szTitle,
  103.         WS_OVERLAPPEDWINDOW,
  104.         CW_USEDEFAULT, CW_USEDEFAULT,
  105.         500, 475,
  106.         NULL,
  107.         hMenuBar,
  108.         hInstance,
  109.         NULL
  110.     );
  111.  
  112.     SetMenu(hWnd, hMenuBar);
  113.     if (!hWnd)
  114.     {
  115.         MessageBox(NULL,
  116.             _T("Call to CreateWindow failed!"),
  117.             _T("Win32 Guided Tour"),
  118.             NULL);
  119.  
  120.         return 1;
  121.     }
  122.  
  123.     ShowWindow(hWnd,
  124.         nCmdShow);
  125.     UpdateWindow(hWnd);
  126.  
  127.     MSG msg;
  128.     while (GetMessage(&msg, NULL, 0, 0))
  129.     {
  130.         TranslateMessage(&msg);
  131.         DispatchMessage(&msg);
  132.     }
  133.  
  134.     return (int)msg.wParam;
  135. }
  136.  
  137.  
  138. int wmId;
  139. int wmEvent;
  140.  
  141. bool isSetPanel = false;
  142. enum mode
  143. {
  144.     ADD, DEL, FIND, SWAP, FFIVE, BASE
  145. };
  146. void setPanel(bool tie)
  147. {
  148.     if (!isSetPanel)
  149.     {
  150.         hEdit = CreateWindow(
  151.             "Edit",
  152.             NULL,
  153.             WS_CHILD |
  154.             ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER,
  155.             150,
  156.             75,
  157.             200,
  158.             20,
  159.             hWnd,
  160.             NULL,
  161.             hInst,
  162.             0);
  163.         label1 = CreateWindow("static", "ST_U",
  164.             WS_CHILD | WS_TABSTOP,
  165.             225, 50, 200, 20,
  166.             hWnd, (HMENU)(501),
  167.             (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  168.         SetWindowText(label1, "Автор");
  169.  
  170.         hEdit2 = CreateWindow(
  171.             "Edit",
  172.             NULL,
  173.             WS_CHILD |
  174.             ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER,
  175.             150,
  176.             125,
  177.             200,
  178.             20,
  179.             hWnd,
  180.             NULL,
  181.             hInst,
  182.             0);
  183.         label2 = CreateWindow("static", "ST_U",
  184.             WS_CHILD | WS_TABSTOP,
  185.             215, 100, 200, 20,
  186.             hWnd, (HMENU)(502),
  187.             (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  188.         SetWindowText(label2, "Название");
  189.         if (!tie)
  190.         {
  191.             hEdit3 = CreateWindow(
  192.                 "Edit",
  193.                 NULL,
  194.                 WS_CHILD |
  195.                 ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER,
  196.                 150,
  197.                 175,
  198.                 200,
  199.                 20,
  200.                 hWnd,
  201.                 NULL,
  202.                 hInst,
  203.                 0);
  204.             label3 = CreateWindow("static", "ST_U",
  205.                 WS_CHILD | WS_TABSTOP,
  206.                 200, 150, 200, 20,
  207.                 hWnd, (HMENU)(503),
  208.                 (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  209.             SetWindowText(label3, "Издательство");
  210.  
  211.             hEdit4 = CreateWindow(
  212.                 "Edit",
  213.                 NULL,
  214.                 WS_CHILD |
  215.                 ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER,
  216.                 150,
  217.                 225,
  218.                 200,
  219.                 20,
  220.                 hWnd,
  221.                 NULL,
  222.                 hInst,
  223.                 0);
  224.             label4 = CreateWindow("static", "ST_U",
  225.                 WS_CHILD | WS_TABSTOP,
  226.                 228, 200, 200, 20,
  227.                 hWnd, (HMENU)(504),
  228.                 (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  229.             SetWindowText(label4, "Жанр");
  230.  
  231.             hEdit5 = CreateWindow(
  232.                 "Edit",
  233.                 NULL,
  234.                 WS_CHILD |
  235.                 ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER,
  236.                 150,
  237.                 275,
  238.                 200,
  239.                 20,
  240.                 hWnd,
  241.                 NULL,
  242.                 hInst,
  243.                 0);
  244.             label5 = CreateWindow("static", "ST_U",
  245.                 WS_CHILD | WS_TABSTOP,
  246.                 185, 250, 200, 20,
  247.                 hWnd, (HMENU)(505),
  248.                 (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  249.             SetWindowText(label5, "Дата поступления");
  250.  
  251.             hEdit6 = CreateWindow(
  252.                 "Edit",
  253.                 NULL,
  254.                 WS_CHILD |
  255.                 ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER,
  256.                 150,
  257.                 325,
  258.                 200,
  259.                 20,
  260.                 hWnd,
  261.                 NULL,
  262.                 hInst,
  263.                 0);
  264.             label6 = CreateWindow("static", "ST_U",
  265.                 WS_CHILD | WS_TABSTOP,
  266.                 215, 300, 200, 20,
  267.                 hWnd, (HMENU)(506),
  268.                 (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  269.             SetWindowText(label6, "Стоимость");
  270.         }
  271.         int y = 350;
  272.         if (tie) y = 150;
  273.         hButton1 = CreateWindow("BUTTON", "Выполнить", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  274.             50, y, 400, 50, hWnd, (HMENU)200, hInst, NULL);
  275.     }
  276.     isSetPanel = true;
  277.     ShowWindow(hEdit, 1);
  278.     ShowWindow(label1, 1);
  279.     ShowWindow(hEdit2, 1);
  280.     ShowWindow(label2, 1);
  281.     if (!tie)
  282.     {
  283.         ShowWindow(hEdit3, 1);
  284.         ShowWindow(label3, 1);
  285.         ShowWindow(hEdit4, 1);
  286.         ShowWindow(label4, 1);
  287.         ShowWindow(hEdit5, 1);
  288.         ShowWindow(label5, 1);
  289.         ShowWindow(hEdit6, 1);
  290.         ShowWindow(label6, 1);
  291.     }
  292. }
  293.  
  294. void clearPanel()
  295. {
  296.     if (hEdit != NULL) DestroyWindow(hEdit);
  297.     if (hEdit2 != NULL) DestroyWindow(hEdit2);
  298.     if (hEdit3 != NULL) DestroyWindow(hEdit3);
  299.     if (hEdit4 != NULL) DestroyWindow(hEdit4);
  300.     if (hEdit5 != NULL) DestroyWindow(hEdit5);
  301.     if (hEdit6 != NULL) DestroyWindow(hEdit6);
  302.     if (label1 != NULL) DestroyWindow(label1);
  303.     if (label2 != NULL) DestroyWindow(label2);
  304.     if (label3 != NULL) DestroyWindow(label3);
  305.     if (label4 != NULL) DestroyWindow(label4);
  306.     if (label5 != NULL) DestroyWindow(label5);
  307.     if (label6 != NULL) DestroyWindow(label6);
  308.     if (hButton1 != NULL) DestroyWindow(hButton1);
  309.     isSetPanel = false;
  310. }
  311.  
  312. void addBook(std::string msg1, std::string msg2, std::string msg3, std::string msg4, std::string msg5, std::string msg6)
  313. {
  314.     std::ofstream File;
  315.     try
  316.     {
  317.         File.open("library.txt", std::ios::app);
  318.         File << msg1 << ";" << msg2 << ";" << msg3 << ";" << msg4 << ";" << msg5 << ";" << msg6 << ";" << std::endl;
  319.     }
  320.     catch (int a)
  321.     {
  322.         std::cout << "Не удалось открыть файл!" << std::endl;
  323.     }
  324.     File.close();
  325.  
  326. }
  327.  
  328. void delBook(std::string msg1, std::string msg2)
  329. {
  330.     std::ifstream File;
  331.     std::string text;
  332.     std::vector<std::string> books;
  333.     try
  334.     {
  335.         File.open("library.txt");
  336.         while (std::getline(File, text))
  337.         {
  338.             books.push_back(text);
  339.         }
  340.     }
  341.     catch (int a)
  342.     {
  343.         std::cout << "Не удалось открыть файл!" << std::endl;
  344.     }
  345.     File.close();
  346.     int number = -1;
  347.     for (int i = 0; i < books.size(); i++)
  348.     {
  349.         int count = 0;
  350.         std::string temp1 = "";
  351.         std::string temp2 = "";
  352.         for (int j = 0; j < books[i].size() && count < 2; j++)
  353.         {
  354.             if (books[i][j] == ';') count++;
  355.             if (count == 0) temp1 += books[i][j];
  356.             if (count == 1 && books[i][j] != ';') temp2 += books[i][j];
  357.         }
  358.         if (temp1 == msg1 && temp2 == msg2)
  359.         {
  360.             temp1 = "";
  361.             temp2 = "";
  362.             number = i;
  363.         }
  364.         temp1 = "";
  365.         temp2 = "";
  366.     }
  367.     std::ofstream File2;
  368.     try
  369.     {
  370.         File2.open("library.txt");
  371.         for (int i = 0; i < books.size(); i++)
  372.         {
  373.             if (i != number) File2 << books[i] + "\n";
  374.         }
  375.     }
  376.     catch (int a)
  377.     {
  378.         std::cout << "Не удалось открыть файл!" << std::endl;
  379.     }
  380.     File2.close();
  381. }
  382.  
  383. void findBook(std::string msg1, std::string msg2)
  384. {
  385.     std::ifstream File;
  386.     std::string text;
  387.     std::vector<std::string> books;
  388.     try
  389.     {
  390.         File.open("library.txt", std::ios::app);
  391.         while (std::getline(File, text))
  392.         {
  393.             books.push_back(text);
  394.         }
  395.     }
  396.     catch (int a)
  397.     {
  398.         std::cout << "Не удалось открыть файл!" << std::endl;
  399.     }
  400.     File.close();
  401.     int number = -1;
  402.     for (int i = 0; i < books.size(); i++)
  403.     {
  404.         int count = 0;
  405.         std::string temp1 = "";
  406.         std::string temp2 = "";
  407.         std::string temp3 = "";
  408.         std::string temp4 = "";
  409.         std::string temp5 = "";
  410.         std::string temp6 = "";
  411.         for (int j = 0; j < books[i].size(); j++)
  412.         {
  413.             if (books[i][j] == ';') count++;
  414.             if (count == 0) temp1 += books[i][j];
  415.             if (count == 1 && books[i][j] != ';') temp2 += books[i][j];
  416.             if (count == 2 && books[i][j] != ';') temp3 += books[i][j];
  417.             if (count == 3 && books[i][j] != ';') temp4 += books[i][j];
  418.             if (count == 4 && books[i][j] != ';') temp5 += books[i][j];
  419.             if (count == 5 && books[i][j] != ';') temp6 += books[i][j];
  420.         }
  421.         if (temp1 == msg1 && temp2 == msg2)
  422.         {
  423.             number = i;
  424.             std::string tempstr = "Книга найдена!\nАвтор:" + temp1
  425.                 + " \nНазвание: " + temp2
  426.                 + " \nИздательство: " + temp3
  427.                 + " \nЖанр: " + temp4
  428.                 + " \nДата поступления: " + temp5
  429.                 + " \nСтоимость: " + temp6;
  430.             MessageBox(NULL, tempstr.c_str(), "Поиск", MB_OK | MB_ICONASTERISK);
  431.         }
  432.         temp1 = "";
  433.         temp2 = "";
  434.         temp3 = "";
  435.         temp4 = "";
  436.         temp5 = "";
  437.         temp6 = "";
  438.     }
  439. }
  440.  
  441. std::string getTextBoxValue(HWND control)
  442. {
  443.     int length = SendMessage(control, WM_GETTEXTLENGTH, 0, 0);
  444.     wchar_t *str;
  445.     str = new wchar_t[length + 1];
  446.     SendMessage(control, WM_GETTEXT, length + 1, LPARAM(str));
  447.     LPCSTR temp = LPCSTR(str);
  448.     return ((std::string)temp);
  449. }
  450.  
  451. mode modeStatus = BASE;
  452. HANDLE handle;
  453.  
  454. void clearEdits()
  455. {
  456.     SendMessageA(hEdit, WM_SETTEXT, WPARAM(0), LPARAM(""));
  457.     SendMessageA(hEdit2, WM_SETTEXT, WPARAM(0), LPARAM(""));
  458.     SendMessageA(hEdit3, WM_SETTEXT, WPARAM(0), LPARAM(""));
  459.     SendMessageA(hEdit4, WM_SETTEXT, WPARAM(0), LPARAM(""));
  460.     SendMessageA(hEdit5, WM_SETTEXT, WPARAM(0), LPARAM(""));
  461.     SendMessageA(hEdit6, WM_SETTEXT, WPARAM(0), LPARAM(""));
  462. }
  463.  
  464. bool ishWndListCreated = false;
  465.  
  466. int CreateColumn(HWND hwndLV, int iCol, LPSTR text, int width)
  467. {
  468.     LVCOLUMN lvc;
  469.  
  470.     lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  471.     lvc.fmt = LVCFMT_LEFT;
  472.     lvc.cx = width;
  473.     lvc.pszText = text;
  474.     lvc.iSubItem = iCol;
  475.     return ListView_InsertColumn(hwndLV, iCol, &lvc);
  476. }
  477.  
  478. int CreateItems(HWND hwndList, LPSTR Text0, LPSTR Text1, LPSTR Text2, LPSTR Text3, LPSTR Text4, LPSTR Text5, LPSTR Text6)
  479. {
  480.     LVITEMW lvi = { 0 };
  481.     int Ret;
  482.     lvi.mask = LVIF_TEXT;
  483.     lvi.pszText = (LPWSTR)Text0;
  484.     Ret = ListView_InsertItem(hwndList, &lvi);
  485.     if (Ret >= 0)
  486.     {
  487.         ListView_SetItemText(hwndList, Ret, 1, Text1);
  488.         ListView_SetItemText(hwndList, Ret, 2, Text2);
  489.         ListView_SetItemText(hwndList, Ret, 3, Text3);
  490.         ListView_SetItemText(hwndList, Ret, 4, Text4);
  491.         ListView_SetItemText(hwndList, Ret, 5, Text5);
  492.         ListView_SetItemText(hwndList, Ret, 6, Text6);
  493.     }
  494.     return Ret;
  495. }
  496.  
  497. void sort1(bool tie)
  498. {
  499.     std::ifstream File;
  500.     std::string text;
  501.     std::vector<std::string> books;
  502.     try
  503.     {
  504.         File.open("library.txt");
  505.         while (std::getline(File, text))
  506.         {
  507.             books.push_back(text);
  508.         }
  509.     }
  510.     catch (int a)
  511.     {
  512.         std::cout << "Не удалось открыть файл!" << std::endl;
  513.     }
  514.     File.close();
  515.     std::string *books_s;
  516.     books_s = new std::string[books.size()];
  517.     for (int i = 0; i < books.size(); i++)
  518.     {
  519.         books_s[i] = books[i];
  520.     }
  521.     if (!tie)
  522.     {
  523.         for (int i = 0; i < books.size(); i++)
  524.         {
  525.             for (int k = i; k < books.size(); k++)
  526.             {
  527.                 int counter = 0;
  528.                 std::string tempik1 = "";
  529.                 for (int j = 0; j < books_s[i].size() - 1 && counter < 6; j++)
  530.                 {
  531.                     if (books_s[i][j] == ';') counter++;
  532.                     if (counter == 5 && books_s[i][j] != ';') tempik1 += books_s[i][j];
  533.                 }
  534.                 int counter2 = 0;
  535.                 std::string tempik2 = "";
  536.                 for (int j = 0; j < books_s[k].size() && counter2 < 6; j++)
  537.                 {
  538.                     if (books_s[k][j] == ';') counter2++;
  539.                     if (counter2 == 5 && books_s[k][j] != ';') tempik2 += books_s[k][j];
  540.                 }
  541.                 int cost1 = atoi(tempik1.c_str());
  542.                 int cost2 = atoi(tempik2.c_str());
  543.                 if (cost1 > cost2)
  544.                 {
  545.                     std::string temp = books_s[i];
  546.                     books_s[i] = books_s[k];
  547.                     books_s[k] = temp;
  548.                 }
  549.             }
  550.         }
  551.     }
  552.     else if (tie)
  553.     {
  554.         for (int i = 0; i < books.size(); i++)
  555.         {
  556.             for (int k = i; k < books.size(); k++)
  557.             {
  558.                 int counter = 0;
  559.                 std::string tempik1 = "";
  560.                 for (int j = 0; j < books_s[i].size() - 1 && counter < 4; j++)
  561.                 {
  562.                     if (books_s[i][j] == ';') counter++;
  563.                     if (counter == 3 && books_s[i][j] != ';') tempik1 += books_s[i][j];
  564.                 }
  565.                 int counter2 = 0;
  566.                 std::string tempik2 = "";
  567.                 for (int j = 0; j < books_s[k].size() && counter2 < 4; j++)
  568.                 {
  569.                     if (books_s[k][j] == ';') counter2++;
  570.                     if (counter2 == 3 && books_s[k][j] != ';') tempik2 += books_s[k][j];
  571.                 }
  572.                 bool isMany = false;
  573.                 if (tempik1.size() > tempik2.size())
  574.                 {
  575.                     for (int p = 0; p < tempik2.size() && !isMany; p++)
  576.                     {
  577.                         if ((int)tempik1[p] >= (int)tempik2[p]) isMany = true;
  578.                         else break;
  579.                     }
  580.                 }
  581.                 else {
  582.                     for (int p = 0; p < tempik1.size() && !isMany; p++)
  583.                     {
  584.                         if ((int)tempik1[p] >= (int)tempik2[p]) isMany = true;
  585.                         else break;
  586.                     }
  587.                 }
  588.                 if (isMany)
  589.                 {
  590.                     std::string temp = books_s[i];
  591.                     books_s[i] = books_s[k];
  592.                     books_s[k] = temp;
  593.                 }
  594.             }
  595.         }
  596.     }
  597.     std::ofstream File2;
  598.     try
  599.     {
  600.         File2.open("library.txt");
  601.         for (int i = 0; i < books.size(); i++)
  602.         {
  603.             File2 << books_s[i] + "\n";
  604.         }
  605.     }
  606.     catch (int a)
  607.     {
  608.         std::cout << "Не удалось открыть файл!" << std::endl;
  609.     }
  610.     File2.close();
  611. }
  612.  
  613. bool isSetChangeBookPanel = false;
  614.  
  615. void setChangeBookPanel()
  616. {
  617.     if (!isSetChangeBookPanel)
  618.     {
  619.         hEdit7 = CreateWindow(
  620.             "Edit",
  621.             NULL,
  622.             WS_CHILD |
  623.             ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER,
  624.             75,
  625.             255,
  626.             100,
  627.             20,
  628.             hWnd,
  629.             NULL,
  630.             hInst,
  631.             0);
  632.         label7 = CreateWindow("static", "ST_U",
  633.             WS_CHILD | WS_TABSTOP,
  634.             105, 232, 100, 20,
  635.             hWnd, (HMENU)(507),
  636.             (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  637.         SetWindowText(label7, "Автор");
  638.  
  639.         hEdit8 = CreateWindow(
  640.             "Edit",
  641.             NULL,
  642.             WS_CHILD |
  643.             ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER,
  644.             200,
  645.             255,
  646.             100,
  647.             20,
  648.             hWnd,
  649.             NULL,
  650.             hInst,
  651.             0);
  652.         label8 = CreateWindow("static", "ST_U",
  653.             WS_CHILD | WS_TABSTOP,
  654.             215, 232, 100, 20,
  655.             hWnd, (HMENU)(508),
  656.             (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  657.         SetWindowText(label8, "Название");
  658.         hEdit9 = CreateWindow(
  659.             "Edit",
  660.             NULL,
  661.             WS_CHILD |
  662.             ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER,
  663.             325,
  664.             255,
  665.             100,
  666.             20,
  667.             hWnd,
  668.             NULL,
  669.             hInst,
  670.             0);
  671.         label9 = CreateWindow("static", "ST_U",
  672.             WS_CHILD | WS_TABSTOP,
  673.             330, 232, 100, 20,
  674.             hWnd, (HMENU)(509),
  675.             (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  676.         SetWindowText(label9, "Издательство");
  677.  
  678.         hEdit10 = CreateWindow(
  679.             "Edit",
  680.             NULL,
  681.             WS_CHILD |
  682.             ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER,
  683.             75,
  684.             300,
  685.             100,
  686.             20,
  687.             hWnd,
  688.             NULL,
  689.             hInst,
  690.             0);
  691.         label10 = CreateWindow("static", "ST_U",
  692.             WS_CHILD | WS_TABSTOP,
  693.             105, 280, 100, 20,
  694.             hWnd, (HMENU)(510),
  695.             (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  696.         SetWindowText(label10, "Жанр");
  697.  
  698.         hEdit11 = CreateWindow(
  699.             "Edit",
  700.             NULL,
  701.             WS_CHILD |
  702.             ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER,
  703.             200,
  704.             300,
  705.             100,
  706.             20,
  707.             hWnd,
  708.             NULL,
  709.             hInst,
  710.             0);
  711.         label11 = CreateWindow("static", "ST_U",
  712.             WS_CHILD | WS_TABSTOP,
  713.             190, 280, 200, 20,
  714.             hWnd, (HMENU)(511),
  715.             (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  716.         SetWindowText(label11, "Дата поступления");
  717.  
  718.         hEdit12 = CreateWindow(
  719.             "Edit",
  720.             NULL,
  721.             WS_CHILD |
  722.             ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER,
  723.             325,
  724.             300,
  725.             100,
  726.             20,
  727.             hWnd,
  728.             NULL,
  729.             hInst,
  730.             0);
  731.         label12 = CreateWindow("static", "ST_U",
  732.             WS_CHILD | WS_TABSTOP,
  733.             340, 280, 200, 20,
  734.             hWnd, (HMENU)(512),
  735.             (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  736.         SetWindowText(label12, "Стоимость");
  737.         hEdit13 = CreateWindow(
  738.             "Edit",
  739.             NULL,
  740.             WS_CHILD |
  741.             ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER,
  742.             10,
  743.             275,
  744.             50,
  745.             25,
  746.             hWnd,
  747.             NULL,
  748.             hInst,
  749.             0);
  750.         label13 = CreateWindow("static", "ST_U",
  751.             WS_CHILD | WS_TABSTOP,
  752.             28, 255, 20, 20,
  753.             hWnd, (HMENU)(513),
  754.             (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  755.         SetWindowText(label13, "№");
  756.         hButton2 = CreateWindow("BUTTON", "Изменить", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  757.             50, 325, 400, 75, hWnd, (HMENU)230, hInst, NULL);
  758.         ShowWindow(hEdit7, 1);
  759.         ShowWindow(hEdit8, 1);
  760.         ShowWindow(hEdit9, 1);
  761.         ShowWindow(hEdit10, 1);
  762.         ShowWindow(hEdit11, 1);
  763.         ShowWindow(hEdit12, 1);
  764.         ShowWindow(hEdit13, 1);
  765.  
  766.         ShowWindow(label7, 1);
  767.         ShowWindow(label8, 1);
  768.         ShowWindow(label9, 1);
  769.         ShowWindow(label10, 1);
  770.         ShowWindow(label11, 1);
  771.         ShowWindow(label12, 1);
  772.         ShowWindow(label13, 1);
  773.         isSetChangeBookPanel = true;
  774.     }
  775. }
  776.  
  777. void DestroySetChangeBookPanel()
  778. {
  779.     if (isSetChangeBookPanel)
  780.     {
  781.         DestroyWindow(hEdit7);
  782.         DestroyWindow(hEdit8);
  783.         DestroyWindow(hEdit9);
  784.         DestroyWindow(hEdit10);
  785.         DestroyWindow(hEdit11);
  786.         DestroyWindow(hEdit12);
  787.         DestroyWindow(hEdit13);
  788.         DestroyWindow(label7);
  789.         DestroyWindow(label8);
  790.         DestroyWindow(label9);
  791.         DestroyWindow(label10);
  792.         DestroyWindow(label11);
  793.         DestroyWindow(label12);
  794.         DestroyWindow(label13);
  795.         DestroyWindow(hButton2);
  796.         isSetChangeBookPanel = false;
  797.     }
  798. }
  799.  
  800. void changeBook(int number)
  801. {
  802.     std::ifstream File;
  803.     std::string text;
  804.     std::vector<std::string> books;
  805.     try
  806.     {
  807.         File.open("library.txt");
  808.         while (std::getline(File, text))
  809.         {
  810.             books.push_back(text);
  811.         }
  812.     }
  813.     catch (int a)
  814.     {
  815.         std::cout << "Не удалось открыть файл!" << std::endl;
  816.     }
  817.     File.close();
  818.     std::string *books_s;
  819.     books_s = new std::string[books.size()];
  820.     for (int i = 0; i < books.size(); i++)
  821.     {
  822.         books_s[i] = books[i];
  823.     }
  824.     books_s[number] = "";
  825.     books_s[number] = getTextBoxValue(hEdit7) + ";"
  826.         + getTextBoxValue(hEdit8) + ";"
  827.         + getTextBoxValue(hEdit9) + ";"
  828.         + getTextBoxValue(hEdit10) + ";"
  829.         + getTextBoxValue(hEdit11) + ";"
  830.         + getTextBoxValue(hEdit12) + ";"
  831.         ;
  832.  
  833.  
  834.     std::ofstream File2;
  835.     try
  836.     {
  837.         File2.open("library.txt");
  838.         for (int i = 0; i < books.size(); i++)
  839.         {
  840.             File2 << books_s[i] + "\n";
  841.         }
  842.     }
  843.     catch (int a)
  844.     {
  845.         std::cout << "Не удалось открыть файл!" << std::endl;
  846.     }
  847.     File2.close();
  848. }
  849.  
  850. bool ishEdit13_Focused = false;
  851.  
  852. void swapBook(int number1, int number2)
  853. {
  854.     std::ifstream File;
  855.     std::string text;
  856.     std::vector<std::string> books;
  857.     try
  858.     {
  859.         File.open("library.txt");
  860.         while (std::getline(File, text))
  861.         {
  862.             books.push_back(text);
  863.         }
  864.     }
  865.     catch (int a)
  866.     {
  867.         std::cout << "Не удалось открыть файл!" << std::endl;
  868.     }
  869.     File.close();
  870.     std::string *books_s;
  871.     books_s = new std::string[books.size()];
  872.     for (int i = 0; i < books.size(); i++)
  873.     {
  874.         books_s[i] = books[i];
  875.     }
  876.     std::string temp = books_s[number1];
  877.     books_s[number1] = books_s[number2];
  878.     books_s[number2] = temp;
  879.     std::ofstream File2;
  880.     try
  881.     {
  882.         File2.open("library.txt");
  883.         for (int i = 0; i < books.size(); i++)
  884.         {
  885.             File2 << books_s[i] + "\n";
  886.         }
  887.     }
  888.     catch (int a)
  889.     {
  890.         std::cout << "Не удалось открыть файл!" << std::endl;
  891.     }
  892.     File2.close();
  893. }
  894.  
  895. void deSort()
  896. {
  897.     std::ifstream File;
  898.     std::string text;
  899.     std::vector<std::string> books;
  900.     try
  901.     {
  902.         File.open("library.txt");
  903.         while (std::getline(File, text))
  904.         {
  905.             books.push_back(text);
  906.         }
  907.     }
  908.     catch (int a)
  909.     {
  910.         std::cout << "Не удалось открыть файл!" << std::endl;
  911.     }
  912.     File.close();
  913.     std::string *books_s;
  914.     books_s = new std::string[books.size()];
  915.     for (int i = 0; i < books.size(); i++)
  916.     {
  917.         books_s[i] = books[i];
  918.     }
  919.     srand(time(0));
  920.     for (int i = 0; i < books.size(); i++)
  921.     {
  922.         for (int j = 0; j < books.size(); j++)
  923.         {
  924.             std::string temp = books_s[i];
  925.             int a = rand() % 2;
  926.             if (a == 1)
  927.             {
  928.                 books_s[i] = books_s[j];
  929.                 books_s[j] = temp;
  930.             }
  931.         }
  932.     }
  933.  
  934.     std::ofstream File2;
  935.     try
  936.     {
  937.         File2.open("library.txt");
  938.         for (int i = 0; i < books.size(); i++)
  939.         {
  940.             File2 << books_s[i] + "\n";
  941.         }
  942.     }
  943.     catch (int a)
  944.     {
  945.         std::cout << "Не удалось открыть файл!" << std::endl;
  946.     }
  947.     File2.close();
  948. }
  949.  
  950.  
  951. HWND hEdit14;
  952. HWND label14;
  953.  
  954. HWND hEdit15;
  955. HWND label15;
  956.  
  957. HWND hButton3;
  958.  
  959. bool isSetSwapPanel = false;
  960.  
  961. void setSwapPanel()
  962. {
  963.     if (!isSetSwapPanel)
  964.     {
  965.         hEdit14 = CreateWindow(
  966.             "Edit",
  967.             NULL,
  968.             WS_CHILD |
  969.             ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER,
  970.             35,
  971.             65,
  972.             125,
  973.             25,
  974.             hWnd,
  975.             NULL,
  976.             hInst,
  977.             0);
  978.         label14 = CreateWindow("static", "ST_U",
  979.             WS_CHILD | WS_TABSTOP,
  980.             45, 40, 125, 20,
  981.             hWnd, (HMENU)(513),
  982.             (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  983.         SetWindowText(label14, "№ первой книги");
  984.  
  985.         hEdit15 = CreateWindow(
  986.             "Edit",
  987.             NULL,
  988.             WS_CHILD |
  989.             ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER,
  990.             325,
  991.             65,
  992.             125,
  993.             25,
  994.             hWnd,
  995.             NULL,
  996.             hInst,
  997.             0);
  998.         label15 = CreateWindow("static", "ST_U",
  999.             WS_CHILD | WS_TABSTOP,
  1000.             335, 40, 125, 20,
  1001.             hWnd, (HMENU)(513),
  1002.             (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  1003.         SetWindowText(label15, "№ второй книги");
  1004.         hButton3 = CreateWindow("BUTTON", "Поменять местами", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  1005.             50, 100, 400, 75, hWnd, (HMENU)234, hInst, NULL);
  1006.         ShowWindow(hEdit15, 1);
  1007.         ShowWindow(hEdit14, 1);
  1008.         ShowWindow(label14, 1);
  1009.         ShowWindow(label15, 1);
  1010.         isSetSwapPanel = true;
  1011.     }
  1012. }
  1013.  
  1014. void DestroySwapPanel()
  1015. {
  1016.     if (isSetSwapPanel)
  1017.     {
  1018.         DestroyWindow(label14);
  1019.         DestroyWindow(label15);
  1020.         DestroyWindow(hEdit14);
  1021.         DestroyWindow(hEdit15);
  1022.         DestroyWindow(hButton3);
  1023.         isSetSwapPanel = false;
  1024.     }
  1025. }
  1026.  
  1027. HWND hWndList2;
  1028.  
  1029. bool ishWndList2Created = false;
  1030.  
  1031. void setFindFiveBooksPanel()
  1032. {
  1033.     if (!ishWndList2Created)
  1034.     {
  1035.         hWndList2 = CreateWindow(WC_LISTVIEW, "",
  1036.             WS_VISIBLE | WS_BORDER | WS_CHILD | LVS_REPORT | LVS_EDITLABELS,
  1037.             50, 50, 400, 350,
  1038.             hWnd, (HMENU)101, hInst, 0);
  1039.         CreateColumn(hWndList2, 0, (LPSTR)"Стоимость", 100);
  1040.         CreateColumn(hWndList2, 0, (LPSTR)"Дата поступления", 100);
  1041.         CreateColumn(hWndList2, 0, (LPSTR)"Жанр", 100);
  1042.         CreateColumn(hWndList2, 0, (LPSTR)"Издательство", 100);
  1043.         CreateColumn(hWndList2, 0, (LPSTR)"Название", 100);
  1044.         CreateColumn(hWndList2, 0, (LPSTR)"Автор", 100);
  1045.         CreateColumn(hWndList2, 0, (LPSTR)"ID", 30);
  1046.         ishWndList2Created = true;
  1047.     }
  1048. }
  1049.  
  1050. void destroyFindFiveBooksPanel()
  1051. {
  1052.     if (ishWndList2Created)
  1053.     {
  1054.         DestroyWindow(hWndList2);
  1055.         ishWndList2Created = false;
  1056.     }
  1057. }
  1058.  
  1059. bool isBookLate(std::string data1, std::string data2)
  1060. {
  1061.     std::string days1;
  1062.     days1 += data1[0];
  1063.     days1 += data1[1];
  1064.  
  1065.     std::string days2;
  1066.     days2 += data2[0];
  1067.     days2 += data2[1];
  1068.  
  1069.  
  1070.     std::string mounths1;
  1071.     mounths1 += data1[3];
  1072.     mounths1 += data1[4];
  1073.  
  1074.     std::string mounths2;
  1075.     mounths2 += data2[3];
  1076.     mounths2 += data2[4];
  1077.  
  1078.     std::string years1;
  1079.     years1 += data1[6];
  1080.     years1 += data1[7];
  1081.     years1 += data1[8];
  1082.     years1 += data1[9];
  1083.  
  1084.     std::string years2;
  1085.     years2 += data2[6];
  1086.     years2 += data2[7];
  1087.     years2 += data2[8];
  1088.     years2 += data2[9];
  1089.  
  1090.  
  1091.     int day1 = atoi(days1.c_str());
  1092.     int day2 = atoi(days2.c_str());
  1093.  
  1094.     int mounth1 = atoi(mounths1.c_str());
  1095.     int mounth2 = atoi(mounths2.c_str());
  1096.  
  1097.     int year1 = atoi(years1.c_str());
  1098.     int year2 = atoi(years2.c_str());
  1099.  
  1100.     if (year1 > year2) return true;
  1101.     else
  1102.     {
  1103.         if (mounth1 > mounth2 && year1 >= year2) return true;
  1104.         else
  1105.         {
  1106.             if (day1 > day2 && mounth1 >= mounth2 && year1 >= year2) return true;
  1107.             else
  1108.             {
  1109.                 return false;
  1110.             }
  1111.         }
  1112.     }
  1113. }
  1114.  
  1115. void findFiveBooks()
  1116. {
  1117.     std::ifstream File;
  1118.     std::string text;
  1119.     std::vector<std::string> books;
  1120.     try
  1121.     {
  1122.         File.open("library.txt");
  1123.         while (std::getline(File, text))
  1124.         {
  1125.             books.push_back(text);
  1126.         }
  1127.     }
  1128.     catch (int a)
  1129.     {
  1130.         std::cout << "Не удалось открыть файл!" << std::endl;
  1131.     }
  1132.     File.close();
  1133.     std::string *books_s;
  1134.     books_s = new std::string[books.size()];
  1135.     for (int i = 0; i < books.size(); i++)
  1136.     {
  1137.         books_s[i] = books[i];
  1138.     }
  1139.     for (int i = 0; i < books.size(); i++)
  1140.     {
  1141.         for (int k = i; k < books.size(); k++)
  1142.         {
  1143.             int counter = 0;
  1144.             std::string tempik1 = "";
  1145.             for (int j = 0; j < books_s[i].size() - 1 && counter < 4; j++)
  1146.             {
  1147.                 if (books_s[i][j] == ';') counter++;
  1148.                 if (counter == 3 && books_s[i][j] != ';') tempik1 += books_s[i][j];
  1149.             }
  1150.             int counter2 = 0;
  1151.             std::string tempik2 = "";
  1152.             for (int j = 0; j < books_s[k].size() && counter2 < 4; j++)
  1153.             {
  1154.                 if (books_s[k][j] == ';') counter2++;
  1155.                 if (counter2 == 3 && books_s[k][j] != ';') tempik2 += books_s[k][j];
  1156.             }
  1157.             bool isMany = false;
  1158.             if (tempik1.size() > tempik2.size())
  1159.             {
  1160.                 for (int p = 0; p < tempik2.size() && !isMany; p++)
  1161.                 {
  1162.                     if ((int)tempik1[p] >= (int)tempik2[p]) isMany = true;
  1163.                     else break;
  1164.                 }
  1165.             }
  1166.             else {
  1167.                 for (int p = 0; p < tempik1.size() && !isMany; p++)
  1168.                 {
  1169.                     if ((int)tempik1[p] >= (int)tempik2[p]) isMany = true;
  1170.                     else break;
  1171.                 }
  1172.             }
  1173.             if (isMany)
  1174.             {
  1175.                 std::string temp = books_s[i];
  1176.                 books_s[i] = books_s[k];
  1177.                 books_s[k] = temp;
  1178.             }
  1179.         }
  1180.     }
  1181.     std::vector <std::string> zhanr;
  1182.     bool current = false;
  1183.     for (int i = 0; i < books.size(); i++)
  1184.     {
  1185.         for (int k = i; k < books.size(); k++)
  1186.         {
  1187.             int counter = 0;
  1188.             std::string tempik1 = "";
  1189.             for (int j = 0; j < books_s[i].size() - 1 && counter < 5; j++)
  1190.             {
  1191.                 if (books_s[i][j] == ';') counter++;
  1192.                 if (counter == 4 && books_s[i][j] != ';') tempik1 += books_s[i][j];
  1193.             }
  1194.             int counter2 = 0;
  1195.             std::string tempik2 = "";
  1196.             for (int j = 0; j < books_s[k].size() && counter2 < 5; j++)
  1197.             {
  1198.                 if (books_s[k][j] == ';') counter2++;
  1199.                 if (counter2 == 4 && books_s[k][j] != ';') tempik2 += books_s[k][j];
  1200.             }
  1201.             if (isBookLate(tempik1, tempik2)) {
  1202.                 std::string temp = books_s[i];
  1203.                 books_s[i] = books_s[k];
  1204.                 books_s[k] = temp;
  1205.             }
  1206.         }
  1207.     }
  1208.  
  1209.     std::vector<std::string> finded_Books;
  1210.     for (int i = 0; i < books.size(); i++)
  1211.     {
  1212.         int counter = 0;
  1213.         std::string tempik1 = "";
  1214.         for (int j = 0; j < books_s[i].size() - 1 && counter < 5; j++)
  1215.         {
  1216.             if (books_s[i][j] == ';') counter++;
  1217.             if (counter == 3 && books_s[i][j] != ';') tempik1 += books_s[i][j];
  1218.         }
  1219.         int counterZhanr = 0;
  1220.         for (int j = 0; j < zhanr.size(); j++)
  1221.         {
  1222.             if (zhanr[j] == tempik1) counterZhanr++;
  1223.         }
  1224.         if (counterZhanr < 5)
  1225.         {
  1226.             zhanr.push_back(tempik1);
  1227.             finded_Books.push_back(books_s[i]);
  1228.         }
  1229.     }
  1230.  
  1231.     std::string *booksDone = new std::string[finded_Books.size()];
  1232.     for (int i = 0; i < finded_Books.size(); i++)
  1233.     {
  1234.         booksDone[i] = finded_Books[i];
  1235.     }
  1236.  
  1237.  
  1238.     for (int i = 0; i < finded_Books.size(); i++)
  1239.     {
  1240.         for (int k = i; k < finded_Books.size(); k++)
  1241.         {
  1242.             int counter = 0;
  1243.             std::string tempik1 = "";
  1244.             for (int j = 0; j < booksDone[i].size() - 1 && counter < 4; j++)
  1245.             {
  1246.                 if (booksDone[i][j] == ';') counter++;
  1247.                 if (counter == 3 && booksDone[i][j] != ';') tempik1 += booksDone[i][j];
  1248.             }
  1249.             int counter2 = 0;
  1250.             std::string tempik2 = "";
  1251.             for (int j = 0; j < booksDone[k].size() && counter2 < 4; j++)
  1252.             {
  1253.                 if (booksDone[k][j] == ';') counter2++;
  1254.                 if (counter2 == 3 && booksDone[k][j] != ';') tempik2 += booksDone[k][j];
  1255.             }
  1256.             bool isMany = false;
  1257.             if (tempik1.size() > tempik2.size())
  1258.             {
  1259.                 for (int p = 0; p < tempik2.size() && !isMany; p++)
  1260.                 {
  1261.                     if ((int)tempik1[p] >= (int)tempik2[p]) isMany = true;
  1262.                     else break;
  1263.                 }
  1264.             }
  1265.             else {
  1266.                 for (int p = 0; p < tempik1.size() && !isMany; p++)
  1267.                 {
  1268.                     if ((int)tempik1[p] >= (int)tempik2[p]) isMany = true;
  1269.                     else break;
  1270.                 }
  1271.             }
  1272.             if (isMany)
  1273.             {
  1274.                 std::string temp = booksDone[i];
  1275.                 booksDone[i] = booksDone[k];
  1276.                 booksDone[k] = temp;
  1277.             }
  1278.         }
  1279.     }
  1280.     for (int i = 0; i < finded_Books.size(); i++)
  1281.     {
  1282.         int counter = 0;
  1283.         std::string tempik1 = "";
  1284.         for (int j = 0; j < booksDone[i].size() - 1 && counter < 5; j++)
  1285.         {
  1286.             if (booksDone[i][j] == ';') counter++;
  1287.             if (counter == 3 && booksDone[i][j] != ';') tempik1 += booksDone[i][j];
  1288.         }
  1289.         int counter1 = 0;
  1290.         std::string tempik2 = "";
  1291.         for (int j = 0; j < booksDone[i].size() - 1 && counter1 < 1; j++)
  1292.         {
  1293.             if (booksDone[i][j] == ';') counter1++;
  1294.             if (counter1 == 0 && booksDone[i][j] != ';') tempik2 += booksDone[i][j];
  1295.         }
  1296.         int counter2 = 0;
  1297.         std::string tempik3 = "";
  1298.         for (int j = 0; j < booksDone[i].size() - 1 && counter2 < 2; j++)
  1299.         {
  1300.             if (booksDone[i][j] == ';') counter2++;
  1301.             if (counter2 == 1 && booksDone[i][j] != ';') tempik3 += booksDone[i][j];
  1302.         }
  1303.         int counter3 = 0;
  1304.         std::string tempik4 = "";
  1305.         for (int j = 0; j < booksDone[i].size() - 1 && counter3 < 3; j++)
  1306.         {
  1307.             if (booksDone[i][j] == ';') counter3++;
  1308.             if (counter3 == 2 && booksDone[i][j] != ';') tempik4 += booksDone[i][j];
  1309.         }
  1310.         int counter4 = 0;
  1311.         std::string tempik5 = "";
  1312.         for (int j = 0; j < booksDone[i].size() - 1 && counter4 < 5; j++)
  1313.         {
  1314.             if (booksDone[i][j] == ';') counter4++;
  1315.             if (counter4 == 4 && booksDone[i][j] != ';') tempik5 += booksDone[i][j];
  1316.         }
  1317.         int counter5 = 0;
  1318.         std::string tempik6 = "";
  1319.         for (int j = 0; j < booksDone[i].size() - 1 && counter5 < 6; j++)
  1320.         {
  1321.             if (booksDone[i][j] == ';') counter5++;
  1322.             if (counter5 == 5 && booksDone[i][j] != ';') tempik6 += booksDone[i][j];
  1323.         }
  1324.         CreateItems(hWndList2, (LPTSTR)std::to_string(finded_Books.size() - i).c_str(), (LPSTR)tempik2.c_str(), (LPSTR)tempik3.c_str(), (LPSTR)tempik4.c_str(), (LPSTR)tempik1.c_str(), (LPSTR)tempik5.c_str(), (LPSTR)tempik6.c_str());
  1325.     }
  1326. }
  1327.  
  1328. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  1329. {
  1330.     PAINTSTRUCT ps;
  1331.     HDC hdc;
  1332.  
  1333.  
  1334.     switch (message)
  1335.     {
  1336.     case WM_PAINT:
  1337.         hdc = BeginPaint(hWnd, &ps);
  1338.  
  1339.         if (modeStatus == ADD)
  1340.         {
  1341.             TextOut(hdc, 150, 15, "Библиотека - добавление книги", _tcslen("Библиотека - добавление книги"));
  1342.             if (ishWndListCreated)
  1343.             {
  1344.                 DestroyWindow(hWndList);
  1345.                 ishWndListCreated = false;
  1346.             }
  1347.         }
  1348.         else if (modeStatus == DEL)
  1349.         {
  1350.             TextOut(hdc, 150, 15, "Библиотека - удаление книги", _tcslen("Библиотека - удаление книги"));
  1351.             if (ishWndListCreated)
  1352.             {
  1353.                 DestroyWindow(hWndList);
  1354.                 ishWndListCreated = false;
  1355.             }
  1356.         }
  1357.         else if (modeStatus == FIND)
  1358.         {
  1359.             TextOut(hdc, 170, 15, "Библиотека - поиск книги", _tcslen("Библиотека - поиск книги"));
  1360.             if (ishWndListCreated)
  1361.             {
  1362.                 DestroyWindow(hWndList);
  1363.                 ishWndListCreated = false;
  1364.             }
  1365.         }
  1366.         else if (modeStatus == SWAP)
  1367.         {
  1368.             TextOut(hdc, 170, 15, "Библиотека - замена книг", _tcslen("Библиотека - замена книг"));
  1369.             if (ishWndListCreated)
  1370.             {
  1371.                 DestroyWindow(hWndList);
  1372.                 ishWndListCreated = false;
  1373.             }
  1374.         }
  1375.         else if (modeStatus == FFIVE)
  1376.         {
  1377.  
  1378.             TextOut(hdc, 170, 15, "Библиотека - особый поиск", _tcslen("Библиотека - особый поиск"));
  1379.             if (ishWndListCreated)
  1380.             {
  1381.                 DestroyWindow(hWndList);
  1382.                 ishWndListCreated = false;
  1383.             }
  1384.         }
  1385.         else if (modeStatus == BASE)
  1386.         {
  1387.             TextOut(hdc, 210, 15, "Библиотека", _tcslen("Библиотека"));
  1388.             if (!ishWndListCreated)
  1389.             {
  1390.                 std::ifstream File;
  1391.                 std::string text;
  1392.                 std::vector<std::string> books;
  1393.                 try
  1394.                 {
  1395.                     File.open("library.txt");
  1396.                     while (std::getline(File, text))
  1397.                     {
  1398.                         books.push_back(text);
  1399.                     }
  1400.                 }
  1401.                 catch (int a)
  1402.                 {
  1403.                     std::cout << "Не удалось открыть файл!" << std::endl;
  1404.                 }
  1405.                 File.close();
  1406.                 hWndList = CreateWindow(WC_LISTVIEW, "",
  1407.                     WS_VISIBLE | WS_BORDER | WS_CHILD | LVS_REPORT | LVS_EDITLABELS,
  1408.                     50, 50, 400, 180,
  1409.                     hWnd, (HMENU)100, hInst, 0);
  1410.  
  1411.                 CreateColumn(hWndList, 0, (LPSTR)"Стоимость", 100);
  1412.                 CreateColumn(hWndList, 0, (LPSTR)"Дата поступления", 100);
  1413.                 CreateColumn(hWndList, 0, (LPSTR)"Жанр", 100);
  1414.                 CreateColumn(hWndList, 0, (LPSTR)"Издательство", 100);
  1415.                 CreateColumn(hWndList, 0, (LPSTR)"Название", 100);
  1416.                 CreateColumn(hWndList, 0, (LPSTR)"Автор", 100);
  1417.                 CreateColumn(hWndList, 0, (LPSTR)"ID", 30);
  1418.                 std::reverse(books.begin(), books.end());
  1419.                 for (int i = 0; i < books.size(); i++)
  1420.                 {
  1421.                     int counter = 0;
  1422.                     std::string tempik1 = "";
  1423.                     std::string tempik2 = "";
  1424.                     std::string tempik3 = "";
  1425.                     std::string tempik4 = "";
  1426.                     std::string tempik5 = "";
  1427.                     std::string tempik6 = "";
  1428.                     for (int j = 0; j < books[i].size() && counter < 6; j++)
  1429.                     {
  1430.                         if (books[i][j] == ';') counter++;
  1431.                         if (counter == 0) tempik1 += books[i][j];
  1432.                         if (counter == 1 && books[i][j] != ';') tempik2 += books[i][j];
  1433.                         if (counter == 2 && books[i][j] != ';') tempik3 += books[i][j];
  1434.                         if (counter == 3 && books[i][j] != ';') tempik4 += books[i][j];
  1435.                         if (counter == 4 && books[i][j] != ';') tempik5 += books[i][j];
  1436.                         if (counter == 5 && books[i][j] != ';') tempik6 += books[i][j];
  1437.                     }
  1438.                     CreateItems(hWndList, (LPTSTR)std::to_string(books.size() - i).c_str(), (LPTSTR)(tempik1.c_str()), (LPSTR)tempik2.c_str(), (LPSTR)tempik3.c_str(), (LPSTR)tempik4.c_str(), (LPSTR)tempik5.c_str(), (LPSTR)tempik6.c_str());
  1439.  
  1440.  
  1441.                 }
  1442.                 books.clear();
  1443.                 ishWndListCreated = true;
  1444.             }
  1445.             if (!isSetChangeBookPanel)  setChangeBookPanel();
  1446.         }
  1447.         EndPaint(hWnd, &ps);
  1448.         break;
  1449.     case WM_CTLCOLORSTATIC:
  1450.     {
  1451.         SetBkMode((HDC)wParam, TRANSPARENT);
  1452.         return (LRESULT)CreateSolidBrush(RGB(255, 255, 255));
  1453.     }
  1454.     break;
  1455.     case WM_COMMAND:
  1456.         wmId = LOWORD(wParam);
  1457.         wmEvent = HIWORD(wParam);
  1458.         switch (wmId)
  1459.         {
  1460.         case 10:
  1461.             destroyFindFiveBooksPanel();
  1462.             DestroySetChangeBookPanel();
  1463.             DestroySwapPanel();
  1464.             InvalidateRect(hWnd, NULL, TRUE);
  1465.             modeStatus = ADD;
  1466.             clearPanel();
  1467.             setPanel(false);
  1468.             break;
  1469.         case 2:
  1470.             destroyFindFiveBooksPanel();
  1471.             DestroySetChangeBookPanel();
  1472.             DestroySwapPanel();
  1473.             InvalidateRect(hWnd, NULL, TRUE);
  1474.             modeStatus = DEL;
  1475.             clearPanel();
  1476.             setPanel(true);
  1477.             break;
  1478.         case 3:
  1479.             destroyFindFiveBooksPanel();
  1480.             DestroySwapPanel();
  1481.             DestroySetChangeBookPanel();
  1482.             InvalidateRect(hWnd, NULL, TRUE);
  1483.             modeStatus = FIND;
  1484.             clearPanel();
  1485.             setPanel(true);
  1486.             break;
  1487.         case 4:
  1488.             destroyFindFiveBooksPanel();
  1489.             DestroySwapPanel();
  1490.             if (ishWndListCreated) {
  1491.                 DestroyWindow(hWndList);
  1492.                 ishWndListCreated = false;
  1493.             }
  1494.             clearPanel();
  1495.             sort1(false);
  1496.             modeStatus = BASE;
  1497.             InvalidateRect(hWnd, NULL, TRUE);
  1498.             break;
  1499.         case 5:
  1500.             destroyFindFiveBooksPanel();
  1501.             DestroySwapPanel();
  1502.             if (ishWndListCreated) {
  1503.                 DestroyWindow(hWndList);
  1504.                 ishWndListCreated = false;
  1505.             }
  1506.             clearPanel();
  1507.             sort1(true);
  1508.             modeStatus = BASE;
  1509.             InvalidateRect(hWnd, NULL, TRUE);
  1510.             break;
  1511.         case 6:
  1512.             destroyFindFiveBooksPanel();
  1513.             DestroySwapPanel();
  1514.             if (ishWndListCreated) {
  1515.                 DestroyWindow(hWndList);
  1516.                 ishWndListCreated = false;
  1517.             }
  1518.             clearPanel();
  1519.             InvalidateRect(hWnd, NULL, TRUE);
  1520.             modeStatus = BASE;
  1521.             break;
  1522.         case 7:
  1523.             destroyFindFiveBooksPanel();
  1524.             if (ishWndListCreated) {
  1525.                 DestroyWindow(hWndList);
  1526.                 ishWndListCreated = false;
  1527.             }
  1528.             DestroySetChangeBookPanel();
  1529.             setSwapPanel();
  1530.             clearPanel();
  1531.             modeStatus = SWAP;
  1532.             InvalidateRect(hWnd, NULL, TRUE);
  1533.             break;
  1534.         case 8:
  1535.             destroyFindFiveBooksPanel();
  1536.             DestroySwapPanel();
  1537.             if (ishWndListCreated) {
  1538.                 DestroyWindow(hWndList);
  1539.                 ishWndListCreated = false;
  1540.             }
  1541.             clearPanel();
  1542.             deSort();
  1543.             modeStatus = BASE;
  1544.             InvalidateRect(hWnd, NULL, TRUE);
  1545.             break;
  1546.         case 9:
  1547.             setFindFiveBooksPanel();
  1548.             findFiveBooks();
  1549.             DestroySetChangeBookPanel();
  1550.             DestroySwapPanel();
  1551.             if (ishWndListCreated) {
  1552.                 DestroyWindow(hWndList);
  1553.                 ishWndListCreated = false;
  1554.             }
  1555.             clearPanel();
  1556.             modeStatus = FFIVE;
  1557.             InvalidateRect(hWnd, NULL, TRUE);
  1558.             break;
  1559.         case 200:
  1560.             if (modeStatus == ADD) addBook(
  1561.                 getTextBoxValue(hEdit),
  1562.                 getTextBoxValue(hEdit2),
  1563.                 getTextBoxValue(hEdit3),
  1564.                 getTextBoxValue(hEdit4),
  1565.                 getTextBoxValue(hEdit5),
  1566.                 getTextBoxValue(hEdit6)
  1567.             );
  1568.             else if (modeStatus == DEL) delBook(
  1569.                 getTextBoxValue(hEdit),
  1570.                 getTextBoxValue(hEdit2)
  1571.             );
  1572.             else if (modeStatus == FIND) findBook(
  1573.                 getTextBoxValue(hEdit),
  1574.                 getTextBoxValue(hEdit2)
  1575.             );
  1576.             clearEdits();
  1577.             break;
  1578.         case 230:
  1579.             if (ishWndListCreated) {
  1580.                 DestroyWindow(hWndList);
  1581.                 ishWndListCreated = false;
  1582.             }
  1583.             clearPanel();
  1584.             InvalidateRect(hWnd, NULL, TRUE);
  1585.             modeStatus = BASE;
  1586.             changeBook(atoi(getTextBoxValue(hEdit13).c_str()) - 1);
  1587.             break;
  1588.         case 234:
  1589.             swapBook(atoi((getTextBoxValue(hEdit14).c_str())) - 1, atoi((getTextBoxValue(hEdit15).c_str())) - 1);
  1590.             break;
  1591.         default:
  1592.             return DefWindowProc(hWnd, message, wParam, lParam);
  1593.         }
  1594.         break;
  1595.     case WM_DESTROY:
  1596.         PostQuitMessage(0);
  1597.         break;
  1598.     default:
  1599.         return DefWindowProc(hWnd, message, wParam, lParam);
  1600.         break;
  1601.     }
  1602.     return 0;
  1603. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement