⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 useraccountsdlg.cpp

📁 It can also accept a number of ftp connection (multithreaded), and with most of the commercial ftp s
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			if (i != nSelIndex)
			{
				CString strName;
				strName = m_UsersList.GetItemText(i, 0);
				if (strName.CompareNoCase(dlg.m_strName) == 0)
				{
					AfxMessageBox("Sorry, this user already exists!");
					return;
				}
			}
		}

		m_UserArray[nUserIndex].m_strName = dlg.m_strName;

		m_UsersList.DeleteItem(nSelIndex);
		nSelIndex = m_UsersList.InsertItem(0, dlg.m_strName, 2);

		m_UsersList.SetItemData(nSelIndex, nUserIndex);
		m_UsersList.SetItemState(nSelIndex, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED); 
		m_nPreviousIndex = nSelIndex;

		OnSelchangeUserlist();
	} 
}


/********************************************************************/
/*																	*/
/* Function name : OnDelUser										*/
/* Description   : Delete user account.								*/
/*																	*/
/********************************************************************/
void CUserAccountsDlg::OnDelUser() 
{
	int nSelIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); 
    if(nSelIndex == -1)
        return;

	int nUserIndex = m_UsersList.GetItemData(nSelIndex);
	// remove user from listcontrol
	m_UsersList.DeleteItem(nSelIndex);
	// remove user from array
	m_UserArray.RemoveAt(nUserIndex);

	m_nPreviousIndex = -1;
	// update item data values
	for (int i=0; i<m_UsersList.GetItemCount(); i++)
	{
		int nItemData = m_UsersList.GetItemData(i);
		if (nItemData > nSelIndex)
			m_UsersList.SetItemData(i, nItemData-1);
	}
	OnSelchangeUserlist();	
}



/********************************************************************/
/*																	*/
/* Function name : OnAddDir											*/
/* Description   : Add directory entry to user account.				*/
/*																	*/
/********************************************************************/
void CUserAccountsDlg::OnAddDir() 
{
	int nSelIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); 
    if(nSelIndex == -1)
        return;

	CDirectoryDlg dlg;

	dlg.m_bIsHomeDir = m_DirectoryList.GetItemCount() ? FALSE : TRUE;

	if (dlg.DoModal() == IDOK)
	{
		int nUserIndex = m_UsersList.GetItemData(nSelIndex);
		
		CDirectory dir;
		dir.m_bAllowCreateDirectory = dlg.m_bAllowCreateDirectory;
		dir.m_bAllowDelete = dlg.m_bAllowDelete;
		dir.m_bAllowDownload = dlg.m_bAllowDownload;
		dir.m_bAllowRename = dlg.m_bAllowRename;
		dir.m_bAllowUpload = dlg.m_bAllowUpload;
		dir.m_bIsHomeDir = FALSE;
		dir.m_strDir = dlg.m_strPath;
		dir.m_strAlias = dlg.m_strAlias;

		dir.m_bIsHomeDir = m_DirectoryList.GetItemCount() ? FALSE : TRUE;

		int nIndex = m_UserArray[nUserIndex].m_DirectoryArray.Add(dir);

		int nItem = m_DirectoryList.InsertItem(LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE, 0, dlg.m_strPath, 0, 0, dir.m_bIsHomeDir?1:0, nIndex);
		m_DirectoryList.SetItemText(nItem, 1, dir.m_strAlias);
		m_DirectoryList.SetItemText(nItem, 2, dir.m_bAllowDownload ? "Y" : "N");
		m_DirectoryList.SetItemText(nItem, 3, dir.m_bAllowUpload ? "Y" : "N");
		m_DirectoryList.SetItemText(nItem, 4, dir.m_bAllowRename ? "Y" : "N");
		m_DirectoryList.SetItemText(nItem, 5, dir.m_bAllowDelete ? "Y" : "N");
		m_DirectoryList.SetItemText(nItem, 6, dir.m_bAllowCreateDirectory ? "Y" : "N");

		m_DirectoryList.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
	}
}


/********************************************************************/
/*																	*/
/* Function name : OnEditDir										*/
/* Description   : Edit directory entry properties.					*/
/*																	*/
/********************************************************************/
void CUserAccountsDlg::OnEditDir() 
{
	// get selected user
	int nSelIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); 
    if(nSelIndex == -1)
        return;

	int nUserIndex = m_UsersList.GetItemData(nSelIndex);

    // get index of selected directory item
	nSelIndex = m_DirectoryList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); 
    
    if(nSelIndex == -1)
        return;

	int nDirIndex = m_DirectoryList.GetItemData(nSelIndex);
	
	CDirectoryDlg dlg;

	dlg.m_strTitle = "Edit Directory";

	dlg.m_bAllowCreateDirectory = m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowCreateDirectory;
	dlg.m_bAllowDelete = m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowDelete;
	dlg.m_bAllowDownload = m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowDownload;
	dlg.m_bAllowRename = m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowRename;
	dlg.m_bAllowUpload = m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowUpload;
	dlg.m_strPath = m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_strDir;
	dlg.m_strAlias = m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_strAlias;
	dlg.m_bIsHomeDir = m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bIsHomeDir;

	if (!dlg.m_strAlias.IsEmpty())
		dlg.m_bVirtualDir = TRUE;

	if (dlg.DoModal() == IDOK)
	{
		m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowCreateDirectory = dlg.m_bAllowCreateDirectory;
		m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowDelete = dlg.m_bAllowDelete;
		m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowDownload = dlg.m_bAllowDownload;
		m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowRename = dlg.m_bAllowRename;
		m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowUpload = dlg.m_bAllowUpload;
		m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_strDir = dlg.m_strPath;
		if (dlg.m_bVirtualDir)
			m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_strAlias = dlg.m_strAlias;
		else
			m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_strAlias = "";

		m_DirectoryList.SetItemText(nDirIndex, 0, dlg.m_strPath);
		m_DirectoryList.SetItemText(nDirIndex, 1, dlg.m_strAlias);
		m_DirectoryList.SetItemText(nDirIndex, 2, dlg.m_bAllowDownload ? "Y" : "N");
		m_DirectoryList.SetItemText(nDirIndex, 3, dlg.m_bAllowUpload ? "Y" : "N");
		m_DirectoryList.SetItemText(nDirIndex, 4, dlg.m_bAllowRename ? "Y" : "N");
		m_DirectoryList.SetItemText(nDirIndex, 5, dlg.m_bAllowDelete ? "Y" : "N");
		m_DirectoryList.SetItemText(nDirIndex, 6, dlg.m_bAllowCreateDirectory ? "Y" : "N");

		OnSelchangeUserlist();
	}
}


/********************************************************************/
/*																	*/
/* Function name : OnDelDir											*/
/* Description   : Delete directory entry from user account.		*/
/*																	*/
/********************************************************************/
void CUserAccountsDlg::OnDelDir() 
{
	int nSelIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); 
    if(nSelIndex == -1)
        return;

    // get index of selected user item
	int nUserIndex = m_UsersList.GetItemData(nSelIndex);
	
    // get index of selected directory item
	nSelIndex = m_DirectoryList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); 
    
    if(nSelIndex == -1)
        return;

	int nDirIndex = m_DirectoryList.GetItemData(nSelIndex);
	
	// delete item from list
	m_DirectoryList.DeleteItem(nSelIndex);

	m_UserArray[nUserIndex].m_DirectoryArray.RemoveAt(nDirIndex);

	for (int i=0; i < m_DirectoryList.GetItemCount(); i++)
	{
		int nItemData = m_DirectoryList.GetItemData(i);
		if (nItemData > nDirIndex)
		{
			m_DirectoryList.SetItemData(i, nItemData-1);
		}
	}
	UpdateDialogControls(this, FALSE);
}


/********************************************************************/
/*																	*/
/* Function name : OnSetHome										*/
/* Description   : Make selected directory the home directory.		*/
/*																	*/
/********************************************************************/
void CUserAccountsDlg::OnSetHome() 
{
	int nSelIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); 
    if(nSelIndex == -1)
        return;

	int nUserIndex = m_UsersList.GetItemData(nSelIndex);

    // get index of selected directory item
	POSITION pos;
	pos = m_DirectoryList.GetFirstSelectedItemPosition();
	if (!pos)
		return;
	
	int nDirIndex = m_DirectoryList.GetNextSelectedItem(pos);
	
	for (int i=0; i<m_UserArray[nUserIndex].m_DirectoryArray.GetSize(); i++)
	{
		LVITEM lvi;
		ZeroMemory(&lvi, sizeof (LV_ITEM));
		lvi.mask = LVIF_IMAGE|LVIF_PARAM;
		lvi.iItem = i;
		m_DirectoryList.GetItem(&lvi);
		if (i == nDirIndex)
		{
			// set bIsHome flag for selected directory
			lvi.iImage = 1;
			m_UserArray[nUserIndex].m_DirectoryArray[lvi.lParam].m_bIsHomeDir = TRUE;
		}
		else
		{
			// clear old bIsHomeDir flag	
			lvi.iImage = 0;
			m_UserArray[nUserIndex].m_DirectoryArray[lvi.lParam].m_bIsHomeDir = FALSE;
		}
		m_DirectoryList.SetItem(&lvi);
	}
}


void CUserAccountsDlg::OnUpdateControls(CCmdUI* pCmdUI) 
{
	int nSelIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); 
	
	pCmdUI->Enable(nSelIndex != -1 && !IsDlgButtonChecked(IDC_DISABLE_ACCOUNT));
}

void CUserAccountsDlg::OnUpdateDisableAccount(CCmdUI* pCmdUI) 
{
	int nSelIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); 
	pCmdUI->Enable(nSelIndex != -1);
}



CString CUserAccountsDlg::GetAttributes(CDirectory &dir)
{
	CString strResult;

	strResult.Format("%c%c%c%c%c", dir.m_bAllowDownload ? 'Y':'-',
								 dir.m_bAllowUpload ? 'Y':'-',
								 dir.m_bAllowRename ? 'Y':'-',
								 dir.m_bAllowDelete ? 'Y':'-',
								 dir.m_bAllowCreateDirectory ? 'Y':'-');
	return strResult;
}


/********************************************************************/
/*																	*/
/* Function name : AutoSizeColumns									*/
/* Description   : Make all columns fit nicely.						*/
/*																	*/
/********************************************************************/
void CUserAccountsDlg::AutoSizeColumns() 
{
	// Call this after your the control is filled
	m_DirectoryList.SetRedraw(FALSE);
	int mincol = 0;
    int maxcol = m_DirectoryList.GetHeaderCtrl()->GetItemCount()-1;
	int col;
    for (col = mincol; col <= maxcol; col++) 
	{
		m_DirectoryList.SetColumnWidth(col,LVSCW_AUTOSIZE);
        int wc1 = m_DirectoryList.GetColumnWidth(col);
        m_DirectoryList.SetColumnWidth(col,LVSCW_AUTOSIZE_USEHEADER);
        int wc2 = m_DirectoryList.GetColumnWidth(col);
        // 10 is minumim column width
		int wc = max(10, max(wc1,wc2));
        m_DirectoryList.SetColumnWidth(col,wc);
     }
     m_DirectoryList.SetRedraw(TRUE);
}


/********************************************************************/
/*																	*/
/* Function name : OnDisableAccount									*/
/* Description   : Disable account has been clicked					*/
/*																	*/
/********************************************************************/
void CUserAccountsDlg::OnDisableAccount() 
{
	UpdateDialogControls(this, FALSE);
}


/********************************************************************/
/*																	*/
/* Function name : OnWizard											*/
/* Description   : Launch New Account Wizard						*/
/*																	*/
/********************************************************************/
void CUserAccountsDlg::OnWizard() 
{
	CBitmap bmpHeader, bmpWatermark;

	VERIFY(bmpHeader.LoadBitmap(IDB_BANNER));
	VERIFY(bmpWatermark.LoadBitmap(IDB_WATERMARK));
	
	// show windows 2000-like wizard
	CWizardSheet wizSheet("New Account Wizard", this, 0, bmpWatermark, NULL, bmpHeader);
	wizSheet.m_psh.hInstance = ::GetModuleHandle(NULL);
	if (wizSheet.DoModal() == ID_WIZFINISH)
	{
		int nIndex = -1;
		int nItem = -1;
		
		// existing account ?
		for (int i=0; i<m_UsersList.GetItemCount(); i++)
		{
			CString strName;
			strName = m_UsersList.GetItemText(i, 0);
			if (strName.CompareNoCase(wizSheet.m_Page1.m_strAccountName) == 0)
			{
				nItem = i;
				nIndex = m_UsersList.GetItemData(i);
				break;
			}
		}

		// add new account
		if (nIndex == -1)
		{
			CUser user;

			int nItem = m_UsersList.InsertItem(0, wizSheet.m_Page1.m_strAccountName, 2);
			nIndex = m_UserArray.Add(user);
			m_UsersList.SetItemData(nItem, nIndex);
		}		
		else
		{
			// clear old bIsHomeDir flag	
			for (int i=0; i<m_UserArray[nIndex].m_DirectoryArray.GetSize(); i++)
			{
				m_UserArray[nIndex].m_DirectoryArray[i].m_bIsHomeDir = FALSE;
			}
		}

		m_UserArray[nIndex].m_bAccountDisabled = FALSE;
		m_UserArray[nIndex].m_strName = wizSheet.m_Page1.m_strAccountName;
		m_UserArray[nIndex].m_strPassword = wizSheet.m_Page2.m_strPassword;
		
		// add home directory
		CDirectory directory;
		
		directory.m_strDir = wizSheet.m_Page3.m_strHomeDirectory;
		directory.m_strAlias = "";
		directory.m_bIsHomeDir = TRUE;
		directory.m_bAllowCreateDirectory = wizSheet.m_Page4.m_bAllowCreateDirectory;
		directory.m_bAllowDelete = wizSheet.m_Page4.m_bAllowDelete;
		directory.m_bAllowDownload = wizSheet.m_Page4.m_bAllowDownload;
		directory.m_bAllowRename = wizSheet.m_Page4.m_bAllowRename;
		directory.m_bAllowUpload = wizSheet.m_Page4.m_bAllowUpload;
		directory.m_strAlias = "";

		m_UserArray[nIndex].m_DirectoryArray.Add(directory);
		
		if (m_nPreviousIndex == nItem)
			m_nPreviousIndex = -1;

		// select updated account
		m_UsersList.SetItemState(nItem, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED); 
		OnSelchangeUserlist();	
	}	
}
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -