Разработка информационно-поисковой системы, страница 14

            hResultsWnd = 0;

      default:

            return DefMDIChildProc(hWnd, message, wParam, lParam);

      }

      return 0;  

}

Файл gui\search_wnd.c :

#include "..\CORE\main.h"

/* Обработчик сообщений окна "Поиск по составным критериям" */

LRESULT CALLBACK SearchWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

{

      static HWND hCombo,hEdit[4];

      static int check[5];

      static bool fNoData;

      switch (message)

      {

      case WM_INITDIALOG:

      {    

            ZeroMemory(&check, sizeof(check));

            hEdit[0] = GetDlgItem(hWnd, IDC_EDIT_NAME);

            hEdit[1] = GetDlgItem(hWnd, IDC_EDIT_POWER);

            hEdit[2] = GetDlgItem(hWnd, IDC_EDIT_T);

            hEdit[3] = GetDlgItem(hWnd, IDC_EDIT_4);

            hCombo = GetDlgItem(hWnd, IDC_COMBO_1);

            LVWnd_t wnd = {table[0][5].name, 0, 0, 5, 0, 0};

            load_combobox(&wnd, hCombo);

        return TRUE;

      }

      case WM_COMMAND:

            switch (LOWORD(wParam))

            {

                  case IDOK:

                  {

                        char cmd[1024];

                        char tmp[128];

                        fNoData = true;

                        for (int i = 0; i < ASIZE(check) - 1; i++)

                              if (check[i])

                              {    

                                   fNoData = false;

                                   break;

                              }

                        if (fNoData)

                        {

                              MessageBox(hWnd, "Выберите критерии поиска !", "Ошибка", MB_ICONHAND);

                              return FALSE;

                        }

                        /* начало SQL-команды */

                        lstrcpy((LPSTR)cmd, "SELECT ID");

                        for (int i = 1; i < 5; i++)

                        {

                              strcat(cmd, ",\"");

                              strcat(cmd, table[0][i].name);

                              strcat(cmd, "\"");

                        }

                        strcat(cmd, " FROM table_01_data WHERE ");

                        for (int i = 0; i < 4; i++)

                              /* добавление параметров поиска при наличии выделенного пункта */

                              if (check[i])

                              {

                                   GetWindowText(hEdit[i], (LPSTR)tmp, sizeof(tmp));

                                   if (tmp[0] == '\0')

                                   {

                                         error_msg("Введите значение !");

                                         return TRUE;

                                   }

                                   strcat(cmd, "\"");

                                   strcat(cmd, table[0][i+1].name);

                                   strcat(cmd, "\" = \"");

                                   strcat(cmd, tmp);

                                   strcat(cmd, "\" AND ");

                              }

                        if (check[4])

                        {

                              int i = (int)SendMessage(hCombo, CB_GETCURSEL, 0, 0);

                              int f_id = (int)SendMessage(hCombo, CB_GETITEMDATA, i, 0);

                              if (f_id == -1)

                              {

                                   error_msg("Выберите размещение !");

                                   break;

                              }

                              wsprintf(tmp, "\"%s\" = %d", table[0][5].name, f_id);

                              strcat(cmd, tmp);

                              strcat(cmd, " AND ");                         

                        }

                        int len = lstrlen(cmd);

                        cmd[len-4] = '\0';

                        /* открытие окна "Результаты поиска" */