void DSN_Set_Database(SQLHANDLE Connection)
{
  MADB_Stmt *Stmt= NULL;
  SQLRETURN ret= SQL_ERROR;
  char Database[65];
  MADB_Dsn *Dsn= (MADB_Dsn *)GetWindowLongPtr(GetParent(hwndTab[0]), DWLP_USER);
  

  if (DBFilled)
    return;

  GetDialogFields();
  
  if (SQLAllocHandle(SQL_HANDLE_STMT, Connection, (SQLHANDLE *)&Stmt) != SQL_SUCCESS)
    goto end;

  if (SQLExecDirect((SQLHSTMT)Stmt, (SQLCHAR *)"SHOW DATABASES", SQL_NTS) != SQL_SUCCESS)
    goto end;

  SQLBindCol(Stmt, 1, SQL_C_CHAR, Database, 65, 0);
  ComboBox_ResetContent(GetDlgItem(hwndTab[1], cbDatabase));
  while (SQLFetch(Stmt) == SQL_SUCCESS)
    ComboBox_InsertString(GetDlgItem(hwndTab[1], cbDatabase), -1, Database);
  if (Dsn->Catalog)
  {
    int Idx= ComboBox_FindString(GetDlgItem(hwndTab[2], cbDatabase), 0, Dsn->Catalog);
    ComboBox_SetCurSel(GetDlgItem(hwndTab[2], cbDatabase), Idx);
  }
  ComboBox_SetMinVisible(GetDlgItem(hwndTab[1], cbDatabase),5);
  DBFilled= TRUE;

end:
  if (Stmt)
	  SQLFreeHandle(SQL_HANDLE_STMT, (SQLHANDLE)Stmt);
}
void DSN_Set_CharacterSets(SQLHANDLE Connection)
{
  MADB_Stmt *Stmt= NULL;
  SQLRETURN ret= SQL_ERROR;
  char Charset[65];
  MADB_Dsn *Dsn= (MADB_Dsn *)GetWindowLongPtr(GetParent(hwndTab[0]), DWLP_USER);

  if (CSFilled)
    return;

  GetDialogFields();
  
  if (SQLAllocHandle(SQL_HANDLE_STMT, Connection, (SQLHANDLE *)&Stmt) != SQL_SUCCESS)
    goto end;

  if (SQLExecDirect((SQLHSTMT)Stmt, 
                    (SQLCHAR *)"select character_set_name from information_schema.collations "
                               "WHERE character_set_name NOT LIKE 'utf16%' AND "
                               "character_set_name NOT LIKE 'utf32%' AND "
                               "character_set_name NOT LIKE 'ucs2' "
                               "group by character_set_name order by character_set_name"
                               , SQL_NTS) != SQL_SUCCESS)
    goto end;

  SQLBindCol(Stmt, 1, SQL_C_CHAR, Charset, 65, 0);
  ComboBox_ResetContent(GetDlgItem(hwndTab[2], cbCharset));
  
  while (SQLFetch(Stmt) == SQL_SUCCESS)
    ComboBox_InsertString(GetDlgItem(hwndTab[2], cbCharset), -1, Charset);
  if (Dsn->CharacterSet)
  {
    int Idx= ComboBox_FindString(GetDlgItem(hwndTab[2], cbCharset), 0, Dsn->CharacterSet);
    ComboBox_SetCurSel(GetDlgItem(hwndTab[2], cbCharset), Idx);
  }
  ComboBox_SetMinVisible(GetDlgItem(hwndTab[2], cbCharset),5);
  CSFilled= TRUE;

end:
  if (Stmt)
	  SQLFreeHandle(SQL_HANDLE_STMT, (SQLHANDLE)Stmt);
}
示例#3
0
LRESULT CALLBACK Candify::DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	Candify *pApp;

	pApp = (Candify*)GetWindowLong(hWnd, GWL_USERDATA);

	switch (message) {
	case WM_INITDIALOG: 
		{
			HWND hUsernameEdit, hPasswordEdit, hConnectButton, hExitButton;
			HWND hPlaylistCombo, hPlayButton;
			
			hUsernameEdit = GetDlgItem(hWnd, IDC_USERNAMEEDIT);
			hPasswordEdit = GetDlgItem(hWnd, IDC_PASSWORDEDIT);
			hConnectButton = GetDlgItem(hWnd, IDC_CONNECTBUTTON);
			hExitButton = GetDlgItem(hWnd, IDC_EXITBUTTON);
			hPlaylistCombo = GetDlgItem(hWnd, IDC_PLAYLISTCOMBO);
			hPlayButton = GetDlgItem(hWnd, IDC_PLAYBUTTON);

			pApp->SubclassControl(hUsernameEdit);
			pApp->SubclassControl(hPasswordEdit);
			pApp->SubclassControl(hConnectButton);
			pApp->SubclassControl(hExitButton);
			pApp->SubclassControl(hPlaylistCombo);
			pApp->SubclassControl(hPlayButton);

			ComboBox_SetMinVisible(hPlaylistCombo, 5);

			SetFocus(hUsernameEdit);
		}
		break;
	case WM_DLGLOGGEDIN:
		{
			HWND hUsernameEdit, hPasswordEdit, hConnectButton;
			hUsernameEdit = GetDlgItem(hWnd, IDC_USERNAMEEDIT);
			hPasswordEdit = GetDlgItem(hWnd, IDC_PASSWORDEDIT);
			hConnectButton = GetDlgItem(hWnd, IDC_CONNECTBUTTON);

			Edit_Enable(hUsernameEdit, FALSE);
			Edit_Enable(hPasswordEdit, FALSE);
			Button_Enable(hConnectButton, FALSE);
		}
		break;
	case WM_DLGUPDATEPLAYLISTS:
		{
			HWND hPlaylistCombo, hPlayButton;
			LPCSTR *playlists;
			int nPlaylists;

			hPlaylistCombo = GetDlgItem(hWnd, IDC_PLAYLISTCOMBO);
			hPlayButton = GetDlgItem(hWnd, IDC_PLAYBUTTON);

			ComboBox_Enable(hPlaylistCombo, TRUE);
			Button_Enable(hPlayButton, TRUE);

			ComboBox_ResetContent(hPlaylistCombo);

			nPlaylists = pApp->m_lpSpotify->getPlaylists(&playlists);
			for (int i = 0; i < nPlaylists; i++) {
				ComboBox_AddString(hPlaylistCombo, playlists[i]);
				free((LPVOID)playlists[i]);
			}
			delete[] playlists;
		}
		break;
	case WM_DLGLOGINFAILED:
		{
			HWND hConnectButton;

			MessageBox(hWnd, "Login failed!", "Candify", MB_ICONINFORMATION);

			hConnectButton = GetDlgItem(hWnd, IDC_CONNECTBUTTON);
			Button_Enable(hConnectButton, true);
		}
		break;
	case WM_COMMAND:
		{
			switch (LOWORD(wParam)) {
			case IDC_EXITBUTTON:
				{
					PostQuitMessage(0);
				}
				break;
			case IDC_CONNECTBUTTON:
				{
					HWND hConnectButton;
					CHAR szUsername[100], szPassword[100];

					hConnectButton = GetDlgItem(hWnd, IDC_CONNECTBUTTON);
					Button_Enable(hConnectButton, false);

					GetDlgItemText(hWnd, IDC_USERNAMEEDIT, szUsername, 
						sizeof(szUsername)/sizeof(*szUsername));
					GetDlgItemText(hWnd, IDC_PASSWORDEDIT, szPassword, 
						sizeof(szPassword)/sizeof(*szPassword));
					pApp->Connect(szUsername, szPassword);
				}
				break;
			case IDC_PLAYBUTTON:
				{
					CHAR szPlaylist[100];
					GetDlgItemText(hWnd, IDC_PLAYLISTCOMBO, 
						szPlaylist, sizeof(szPlaylist)/sizeof(*szPlaylist));
					pApp->m_lpSpotify->setPlaylist(szPlaylist);
					ShowWindow(pApp->m_hWnd, SW_SHOW);
					EndDialog(hWnd, 0);
				}
				break;
			}
		}
		break;
	}

	return FALSE;
}