home *** CD-ROM | disk | FTP | other *** search
- // wbmfcssa.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "winreg.h"
- #include "resource.h"
- #include "wbmfc.h"
- #include "wbmfcssa.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- BOOL WBSelSrvrAppl(const char *UserName, const char *Password, const char *Appl, char *SelSrvr, char *SelAppl)
- {
- CSelSrvrApplDlg Dlg(UserName, Password, Appl, SelSrvr, SelAppl);
- return(Dlg.DoModal() == IDOK);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CSelSrvrApplDlg dialog
-
-
- CSelSrvrApplDlg::CSelSrvrApplDlg(const char *UserName, const char *Password, const char *Appl, char *SelSrvr, char *SelAppl, CWnd* pParent /*=NULL*/)
- : CDialog(CSelSrvrApplDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CSelSrvrApplDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_SelServer = NULL;
- m_UserName = UserName;
- m_Password = Password;
- m_Appl = Appl;
- m_NoAppl = UserName == WBAPPI_NOLOGIN || Appl != NULL;
- m_SelSrvr = SelSrvr;
- if (SelSrvr)
- *SelSrvr = 0;
- m_SelAppl = SelAppl;
- if (SelAppl)
- *SelAppl = 0;
- }
-
-
- BEGIN_MESSAGE_MAP(CSelSrvrApplDlg, CDialog)
- //{{AFX_MSG_MAP(CSelSrvrApplDlg)
- ON_NOTIFY(TVN_SELCHANGED, IDC_SRVRTREE, OnSelchanged)
- ON_NOTIFY(NM_SETFOCUS, IDC_SRVRTREE, OnSelchanged)
- ON_NOTIFY(TVN_ITEMEXPANDING, IDC_SRVRTREE, OnItemexpanding)
- ON_NOTIFY(NM_DBLCLK, IDC_SRVRTREE, OnDblclk)
- ON_EN_CHANGE(IDC_APPLEDIT, OnChangeEdit)
- ON_EN_CHANGE(IDC_SRVREDIT, OnChangeEdit)
- ON_WM_DESTROY()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CSelSrvrApplDlg message handlers
-
- BOOL CSelSrvrApplDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- m_SrvrTree = (CTreeCtrl *)GetDlgItem(IDC_SRVRTREE);
- GetDlgItem(IDOK)->EnableWindow(FALSE);
- if (!m_SrvrTree)
- return FALSE;
- FillSrvrTree();
- if (m_NoAppl)
- {
- CWnd *hEdit = GetDlgItem(IDC_APPLEDIT);
- hEdit->EnableWindow(FALSE);
- hEdit->ShowWindow(SW_HIDE);
- GetDlgItem(IDC_APPLSTATIC)->ShowWindow(FALSE);
- CRect Rect;
- GetDlgItem(IDC_SRVREDIT)->GetWindowRect(&Rect);
- int NewyExt = Rect.bottom + 20;
- GetWindowRect(&Rect);
- Rect.bottom = NewyExt;
- MoveWindow(&Rect, FALSE);
- SetWindowLong(*m_SrvrTree, GWL_STYLE, GetWindowLong(*m_SrvrTree, GWL_STYLE) & ~TVS_HASBUTTONS);
- }
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
-
- #define IND_APPL 0
- #define IND_SRVLOCAL 1
- #define IND_SRVREMNR 2
- #define IND_SRVRAS 3
-
- BOOL CSelSrvrApplDlg::FillSrvrTree()
- {
- HKEY hKey, hSubKey;
- char Path[MAX_PATH];
- int ind = 0;
- tobjname Server;
-
- LONG Err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Software602\\WinBase602\\Database", 0, KEY_READ, &hKey);
- if (Err != ERROR_SUCCESS)
- return(FALSE);
-
- CBitmap bm;
- bm.LoadBitmap(IDR_SRVRAPPL);
- CImageList *il = new CImageList;
- il->Create(16, 16, ILC_COLOR | ILC_MASK, 4, 0);
- il->Add(&bm, RGB(0, 128, 128));
- m_SrvrTree->SetImageList(il, TVSIL_NORMAL);
- bm.DeleteObject();
-
- do
- {
- DWORD KeyLen = sizeof(Server);
- if (RegEnumKey(hKey, ind++, Server, KeyLen) != ERROR_SUCCESS)
- break;
- // get server info from the registry:
- BOOL local = FALSE, verok = FALSE, ras = FALSE;
- if (RegOpenKeyEx(hKey, Server, 0, KEY_READ, &hSubKey) == ERROR_SUCCESS)
- {
- KeyLen = MAX_PATH;
- *Path = 0;
- RegQueryValueEx(hSubKey, "Path", NULL, NULL, (BYTE *)Path, &KeyLen);
- local = *Path != 0;
- KeyLen = MAX_PATH;
- *Path = 0;
- RegQueryValueEx(hSubKey, "Version", NULL, NULL, (BYTE *)Path, &KeyLen);
- verok = !lstrcmp(Path, "5");
- KeyLen = MAX_PATH;
- *Path = 0;
- RegQueryValueEx(hSubKey, "ConnectionName", NULL, NULL, (BYTE *)Path, &KeyLen);
- if (*Path)
- ras = TRUE;
- KeyLen = MAX_PATH;
- *(BOOL *)Path = FALSE;
- RegQueryValueEx(hSubKey, "Through Firewall", NULL, NULL, (BYTE *)Path, &KeyLen);
- if (*(BOOL *)Path)
- ras = TRUE;
- RegCloseKey(hSubKey);
- }
- if (!verok)
- continue;
- // select the proper image:
- int iImage;
- if (local)
- iImage = IND_SRVLOCAL;
- else
- iImage = ras ? IND_SRVRAS : IND_SRVREMNR;
- HTREEITEM it = m_SrvrTree->InsertItem
- (
- TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM,
- Server,
- iImage,
- iImage,
- 0, 0,
- 0,
- TVI_ROOT,
- TVI_LAST
- );
- m_SrvrTree->InsertItem
- (
- TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM,
- NULL,
- IND_APPL,
- IND_APPL,
- 0, 0,
- 1,
- it,
- TVI_LAST
- );
- // fictive branch, used to expand the item:
- //is.hParent= anItem;
- //TreeView_InsertItem(hTree, &is);
- }
- while (TRUE);
- RegCloseKey(hKey);
- return(TRUE);
- }
-
- void CSelSrvrApplDlg::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- *pResult = 0;
- HTREEITEM hItem = m_SrvrTree->GetSelectedItem();
- if (!hItem)
- return;
-
- if (IsAppl(hItem))
- {
- SetDlgItemText(IDC_APPLEDIT, m_SrvrTree->GetItemText(hItem));
- }
- else
- {
- TV_ITEM ti;
- ti.mask = TVIF_TEXT;
- ti.hItem = hItem;
- ti.pszText = m_SelServerName;
- ti.cchTextMax = sizeof(m_SelServerName);
- m_SrvrTree->GetItem(&ti);
- SetDlgItemText(IDC_SRVREDIT, m_SelServerName);
- }
- }
-
- void CSelSrvrApplDlg::OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- // TODO: Add your control notification handler code here
- *pResult = 0;
- if (m_NoAppl)
- {
- *pResult = 1;
- return;
- }
- if (pNMTreeView->action == TVE_EXPAND)
- {
- //m_SrvrTree->SetRedraw(FALSE);
- CWBApp *WBApp = (CWBApp *)AfxGetApp();
- if (m_SelServer)
- {
- WBApp->Logout();
- m_SrvrTree->Expand(m_SelServer, TVE_COLLAPSE);
- m_SelServer = NULL;
- }
- HTREEITEM hItem = pNMTreeView->itemNew.hItem;
- m_SrvrTree->SelectItem(hItem);
- CString Server = m_SrvrTree->GetItemText(hItem);
- if (!WBApp->WBAppInit(NULL, m_UserName, m_Password, Server))
- {
- *pResult = TRUE;
- return;
- }
- HTREEITEM delItem;
- while ((delItem = m_SrvrTree->GetChildItem(hItem)))
- m_SrvrTree->DeleteItem(delItem);
- m_SelServer = hItem;
- cdp_t cdp = WBApp->GetCdp();
- tcursnum Curs;
- if (cd_Open_cursor_direct(cdp, "SELECT OBJ_NAME FROM OBJTAB WHERE CATEGORY=Chr(7)", &Curs))
- {
- Signalize();
- return;
- }
- tobjname Appl;
- trecnum Pos = 0;
- while (!cd_Read_ind(cdp, Curs, Pos++, 1, NOINDEX, Appl))
- {
- small_string(Appl, TRUE);
- m_SrvrTree->InsertItem
- (
- TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM,
- Appl,
- IND_APPL,
- IND_APPL,
- 0, 0,
- 1,
- hItem,
- TVI_LAST
- );
- }
- if (cd_Sz_error(cdp) != OUT_OF_TABLE)
- Signalize();
- Close_cursor(Curs);
- //redraw:
- //m_SrvrTree->SetRedraw(TRUE);
- }
- else if (pNMTreeView->action == TVE_COLLAPSE)
- {
- ((CWBApp *)AfxGetApp())->Logout();
- m_SelServer = NULL;
- }
- }
-
- void CSelSrvrApplDlg::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- *pResult = 0;
- if (m_NoAppl || IsAppl())
- OnOK();
- }
-
- void CSelSrvrApplDlg::OnChangeEdit()
- {
- // TODO: Add your control notification handler code here
- tobjname ServerName;
- CWnd *Edit = GetDlgItem(IDC_SRVREDIT);
- int sz = Edit->GetWindowText(ServerName, sizeof(ServerName));
- if (lstrcmp(ServerName, m_SelServerName))
- {
- if (m_SelServer)
- {
- m_SrvrTree->Expand(m_SelServer, TVE_COLLAPSE);
- m_SelServer = NULL;
- }
- ((CWBApp *)AfxGetApp())->Logout();
- }
- Edit = GetDlgItem(IDC_APPLEDIT);
- GetDlgItem(IDOK)->EnableWindow(sz && (m_NoAppl || Edit->GetWindowTextLength()));
- }
-
- void CSelSrvrApplDlg::OnOK()
- {
- // TODO: Add extra validation here
- tobjname SrvrAppl;
- CWBApp *WBApp = (CWBApp *)AfxGetApp();
- if (!WBApp->Linked())
- {
- if (!GetDlgItemText(IDC_SRVREDIT, SrvrAppl, sizeof(SrvrAppl)))
- return;
- if (!WBApp->WBAppInit(NULL, m_UserName, m_Password, SrvrAppl))
- return;
- }
- if (m_SelSrvr)
- lstrcpy(m_SelSrvr, SrvrAppl);
- if (!m_NoAppl)
- {
- if (!m_Appl)
- {
- if (!GetDlgItemText(IDC_APPLEDIT, SrvrAppl, sizeof(SrvrAppl)))
- return;
- m_Appl = SrvrAppl;
- }
- if (!WBApp->SetApplication(m_Appl))
- return;
- }
- if (m_SelAppl && m_Appl)
- lstrcpy(m_SelAppl, m_Appl);
- CDialog::OnOK();
- }
-
- BOOL CSelSrvrApplDlg::IsAppl(HTREEITEM hItem)
- {
- TV_ITEM ti;
- ti.mask = TVIF_PARAM;
- ti.hItem = hItem;
- if (!hItem)
- ti.hItem = m_SrvrTree->GetSelectedItem();
- m_SrvrTree->GetItem(&ti);
- return ti.lParam;
- }
-
- void CSelSrvrApplDlg::OnDestroy()
- {
- CDialog::OnDestroy();
-
- // TODO: Add your message handler code here
- CImageList *il = m_SrvrTree->GetImageList(TVSIL_NORMAL);
- delete il;
- }
-
-