📄 filemanage.cpp
字号:
// FileManage.cpp : implementation file
//
#include "stdafx.h"
#include "Server.h"
#include "FileManage.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFileManage dialog
CFileManage::CFileManage(CWnd* pParent /*=NULL*/)
: CDialog(CFileManage::IDD, pParent)
{
m_pServerDlg = (CServerDlg*)pParent;
m_bPersonal = false;
//{{AFX_DATA_INIT(CFileManage)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CFileManage::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFileManage)
DDX_Control(pDX, IDC_LISTILE, m_lstFileShare);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFileManage, CDialog)
//{{AFX_MSG_MAP(CFileManage)
ON_BN_CLICKED(IDC_BTN_DEL, OnBtnDel)
ON_BN_CLICKED(IDC_BTN_UPDATE, OnBtnUpdate)
ON_BN_CLICKED(IDC_BTN_PERSONAL, OnBtnPersonal)
ON_BN_CLICKED(IDC_BTN_SHARE, OnBtnShare)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileManage message handlers
void CFileManage::OnOK()
{
OnBtnDel();
}
void CFileManage::OnCancel()
{
// TODO: Add extra cleanup here
m_pServerDlg->m_FileManageHwnd = NULL;
delete this;
}
BOOL CFileManage::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
/////////////////////////////////////////////////////////////////////////
//初始化列表控件
m_lstFileShare.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
m_lstFileShare.SetBkColor(RGB(223, 223, 223));
m_lstFileShare.SetTextBkColor(RGB(223, 223, 223));
m_lstFileShare.SetTextColor(RGB(255, 15, 14));
m_lstFileShare.InsertColumn(0, "文件ID", LVCFMT_LEFT, 50, 0);
m_lstFileShare.InsertColumn(1, "文件名", LVCFMT_LEFT, 130, 1);
m_lstFileShare.InsertColumn(2, "文件大小", LVCFMT_LEFT, 62, 2);
m_lstFileShare.InsertColumn(3, "拥有者", LVCFMT_LEFT, 67, 3);
m_lstFileShare.InsertColumn(4, "上传时间", LVCFMT_LEFT, 126, 4);
// TODO: Add extra initialization here
OnBtnUpdate();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/**********************删除共享文件*********************/
void CFileManage::OnBtnDel()
{
CConn& Cn = m_pServerDlg->GetSvrSock().GetCn();
// TODO: Add your control notification handler code here
POSITION pos = m_lstFileShare.GetFirstSelectedItemPosition();
int nIndex = m_lstFileShare.GetNextSelectedItem(pos);
if(-1 == nIndex)
{
CString msg = "没有选择目标文件";
AfxMessageBox(msg);
return;
}
CString strFileId;
CRecs rs;
if(MessageBox("确定删除此文件?","提示",MB_YESNO|MB_ICONQUESTION) == IDNO)
return;
strFileId = m_lstFileShare.GetItemText(nIndex, 0);
////////////////////////////////////////////////////////////////////////
//获取该文件的存放路径 [modify] dong 12-19
CString strsql = "select * from FileShare where FileID = " + strFileId ;
if(rs.Open((Cn.GetActiveConn()), (_variant_t)strsql))
{
_variant_t pathvalue = rs.GetRs()->GetCollect((_variant_t)6L);
CString strFilePath = (char*)(_bstr_t)pathvalue;
/////////////////////////////////////////////////////////////////
//从数据库中删除
strsql = " delete * from FileShare where FileID = " + strFileId;
if(Cn.ExecuteSql((_bstr_t)strsql))
{
//////////////////////////////////
//从列表中删除
m_lstFileShare.DeleteItem(nIndex);
/////////////////////////////////
//从文件夹中删除
CFile file;
CFileStatus fs;
if(file.GetStatus(strFilePath, fs))
{
file.Remove(strFilePath);
}
}
else
{
AfxMessageBox("删除失败!");
}
}
}
void CFileManage::OnClose()
{
// TODO: Add your message handler code here and/or call default
m_pServerDlg->m_FileManageHwnd = NULL;
delete this;
}
///////////////////////////////
//更新
void CFileManage::OnBtnUpdate()
{
m_lstFileShare.DeleteAllItems();
/********************查询数据库**********************************/
CConn& Cn = m_pServerDlg->GetSvrSock().GetCn();
CRecs rs;
CString strsql;
if(m_bPersonal)
{
strsql = "select * from FileShare where IsPersonal = 1";
}
else
{
strsql = "select * from FileShare where IsPersonal = 0";
}
if(rs.Open((Cn.GetActiveConn()),(_variant_t)strsql))
{
if(!rs.GetRs()->adoEOF)
{
while(!rs.GetRs()->adoEOF)
{
int nIndex = m_lstFileShare.GetItemCount();
m_lstFileShare.InsertItem(nIndex, "");
for(long i = 0; i<5; i++)
{
_variant_t value = rs.GetRs()->GetCollect((_variant_t)i);
CString va = (char*)(_bstr_t)value;
m_lstFileShare.SetItemText(nIndex, i, va);
}
rs.GetRs()->MoveNext();
}
int nCount = m_lstFileShare.GetItemCount();
CString strCount;
if(!m_bPersonal)
{
strCount.Format("共 %d 条共享记录", nCount);
}
else
{
strCount.Format("共 %d 条个人存储记录", nCount);
}
GetDlgItem(IDC_STC_MSG)->SetWindowText(strCount);
}
else
{
if(!m_bPersonal)
{
GetDlgItem(IDC_STC_MSG)->SetWindowText("无共享记录");
}
else
{
GetDlgItem(IDC_STC_MSG)->SetWindowText("无个人存储记录");
}
}
}
}
////////////////////
//个人存储查看
void CFileManage::OnBtnPersonal()
{
if(m_bPersonal) return;
m_bPersonal = true;
m_lstFileShare.DeleteAllItems();
OnBtnUpdate();
}
///////////////////
//共享文件查看
void CFileManage::OnBtnShare()
{
if(!m_bPersonal) return;
m_bPersonal = false;
m_lstFileShare.DeleteAllItems();
OnBtnUpdate();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -