📄 dlgmain.cpp
字号:
// DlgMain.cpp : implementation file
//
#include "stdafx.h"
#include "NClient.h"
#include "DlgMain.h"
#include "DlgReqMgt.h"
#include "DlgInfoMod.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgMain dialog
CDlgMain::CDlgMain(CWnd* pParent /*=NULL*/)
: CDialog(CDlgMain::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgMain)
m_bStartReqFile = false;
m_StoreFileName = "";
m_bStartGetFile = false;
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDlgMain::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgMain)
DDX_Control(pDX, IDC_LIST_MAIN, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgMain, CDialog)
//{{AFX_MSG_MAP(CDlgMain)
ON_BN_CLICKED(IDC_BTN_MAINEXIT, OnBtnMainexit)
ON_BN_CLICKED(IDC_BTN_SEND, OnBtnSend)
ON_BN_CLICKED(IDC_BTN_REQ, OnBtnReq)
ON_BN_CLICKED(IDC_BTN_MAINMODIFY, OnBtnMainmodify)
ON_BN_CLICKED(IDC_BTN_LOCAT, OnBtnLocat)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BTN_DELETE, OnBtnDelete)
ON_BN_CLICKED(IDC_BTN_GET, OnBtnGet)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgMain message handlers
void CDlgMain::OnBtnMainexit()
{
((CNClientApp *)AfxGetApp())->m_socket->SendData("ExitClient");
CDialog::OnCancel();
}
void CDlgMain::OnBtnSend()
{
CFileDialog fileDlg(TRUE);
CString FileName = "";
fileDlg.m_ofn.lpstrFilter="all files(*.*)";
fileDlg.m_ofn.nFilterIndex=0;
fileDlg.m_ofn.lpstrInitialDir = "c:";
fileDlg.m_ofn.Flags |= OFN_EXPLORER | OFN_NOVALIDATE;
if(fileDlg.DoModal() != IDOK) return ;
FileName = fileDlg.GetPathName();
if(strlen(FileName) <= 0){
MessageBox("文件名为空,发送文件失败!");
return;
}
CString tempstr = "";
CString nData = "";
tempstr = FileName.Right(FileName.GetLength() - FileName.ReverseFind('\\') - 1);
if(strlen(FileName) <= 0){
MessageBox("文件名为空,发送文件失败!");
return;
}
nData.Format("SendFile#%s#",tempstr);
((CNClientApp *)AfxGetApp())->m_socket->SendData(nData);
Sleep(200);
int Cnt = 0;
try{
CFile pFile;
CFileException ex;
pFile.Open(FileName,CFile::modeRead,&ex); //| CFile::typeBinary
int nRead = 1;
while(nRead > 0){
char pBuf[2049];
nRead = 0;
nRead = pFile.Read(pBuf,2048);
Cnt += nRead;
pBuf[nRead] = 0;
if(nRead > 0){
((CNClientApp *)AfxGetApp())->m_socket->SendData(pBuf);
}
}
pFile.Close();
}
catch(...){;}
Sleep(100);
((CNClientApp *)AfxGetApp())->m_socket->SendData("EndSendFile");
MessageBox("文件发送成功!");
}
void CDlgMain::OnBtnReq()
{
CDlgReqMgt dReqmgt;
dReqmgt.DoModal();
}
BOOL CDlgMain::OnInitDialog()
{
CDialog::OnInitDialog();
GetDlgItem(IDC_ST_USERCODE)->SetWindowText(((CNClientApp *)AfxGetApp())->m_strUserCode);
GetDlgItem(IDC_ST_USERNAME)->SetWindowText(((CNClientApp *)AfxGetApp())->m_strUserName);
m_list.ModifyStyle(0, LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SINGLESEL);
m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP);
m_list.InsertColumn(0,"编号",LVCFMT_LEFT,70);
m_list.InsertColumn(1,"文件名称",LVCFMT_LEFT,150);
m_list.InsertColumn(2,"文件大小",LVCFMT_LEFT,100);
m_list.InsertColumn(3,"存储时间",LVCFMT_LEFT,250);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgMain::OnBtnMainmodify()
{
CDlgInfoMod dMod;
dMod.DoModal();
}
void CDlgMain::OnBtnLocat()
{
m_list.DeleteAllItems();
CString nData = "";
nData.Format("ReqFileList#%s#",((CNClientApp *)AfxGetApp())->m_strUserCode);
((CNClientApp *)AfxGetApp())->m_socket->SendData(nData);
GetDlgItem(IDC_BTN_LOCAT)->EnableWindow(false);
((CNClientApp *)AfxGetApp())->m_status = REQ_GETFILELIST;
((CNClientApp *)AfxGetApp())->DeleteLastMsg();
m_bStartReqFile = true;
SetTimer(1006,1000,NULL);
}
void CDlgMain::AddItem(CString nData)
{
if(strlen(nData) <= 0)
return;
CString strCode = "";
CString strName = "";
CString strSpace = "";
CString strTime = "";
CString yData = nData;
if(yData.Find("#") == -1 || yData.GetLength() <= 4 )
return;
yData = yData.Right(yData.GetLength() - 1);
int pNum = yData.Find("#");
if(pNum == -1)
return;
strCode = yData.Left(pNum);
yData = yData.Right(yData.GetLength() - pNum - 1);
pNum = yData.Find("#");
if(pNum == -1)
return;
strName = yData.Left(pNum);
yData = yData.Right(yData.GetLength() - pNum - 1);
pNum = yData.Find("#");
if(pNum == -1)
return;
strSpace = yData.Left(pNum);
yData = yData.Right(yData.GetLength() - pNum - 1);
if(strlen(yData) > 0)
yData.Replace("#","");
strTime = yData;
int nItem = m_list.InsertItem(0,strCode);
m_list.SetItemText(nItem,1,strName);
m_list.SetItemText(nItem,2,strSpace);
m_list.SetItemText(nItem,3,strTime);
}
void CDlgMain::OnTimer(UINT nIDEvent)
{
if(nIDEvent == 1006 && m_bStartReqFile){
if(((CNClientApp *)AfxGetApp())->m_status == STA_NORMAL){
CArrayLastMsg *pItem = ((CNClientApp *)AfxGetApp())->m_arrLastMsg;
GetDlgItem(IDC_BTN_LOCAT)->EnableWindow(true);
m_bStartReqFile = false;
while(pItem != NULL){
AddItem(pItem->strData);
pItem = pItem->pNext;
}
((CNClientApp *)AfxGetApp())->DeleteLastMsg();
}
}
else if(nIDEvent == 1006 && m_bStartGetFile){
if(((CNClientApp *)AfxGetApp())->m_status == STA_NORMAL){
m_NWFile.Close();
m_bStartGetFile = false;
GetDlgItem(IDC_BTN_SEND)->EnableWindow(true);
GetDlgItem(IDC_BTN_GET)->EnableWindow(true);
GetDlgItem(IDC_BTN_DELETE)->EnableWindow(true);
GetDlgItem(IDC_BTN_LOCAT)->EnableWindow(true);
}
}
CDialog::OnTimer(nIDEvent);
}
void CDlgMain::OnBtnDelete()
{
int nItem = m_list.GetNextItem(-1, LVNI_SELECTED);
if (nItem < 0) return;
CString tempstr = "";
tempstr = m_list.GetItemText(nItem,0);
int pNum = atoi(tempstr);
if(pNum <= 0) return;
CString nData = "";
nData.Format("DelFile#%d#",pNum);
((CNClientApp *)AfxGetApp())->m_socket->SendData(nData);
MessageBox("删除文件命令发送成功!");
m_list.DeleteItem(nItem);
}
void CDlgMain::OnBtnGet()
{
CFileDialog fileDlg(FALSE);
fileDlg.m_ofn.lpstrFilter="all files(*.*)";
fileDlg.m_ofn.nFilterIndex=0;
fileDlg.m_ofn.lpstrInitialDir = "c:";
fileDlg.m_ofn.Flags |= OFN_EXPLORER | OFN_NOVALIDATE;
if(fileDlg.DoModal() != IDOK) return ;
m_StoreFileName = fileDlg.GetPathName();
if(strlen(m_StoreFileName) <= 0){
MessageBox("文件名为空,发送文件失败!");
return;
}
((CNClientApp *)AfxGetApp())->m_status = REQ_GETFILE;
m_bStartGetFile = true;
GetDlgItem(IDC_BTN_SEND)->EnableWindow(false);
GetDlgItem(IDC_BTN_GET)->EnableWindow(false);
GetDlgItem(IDC_BTN_DELETE)->EnableWindow(false);
GetDlgItem(IDC_BTN_LOCAT)->EnableWindow(false);
m_NWFile.Open( m_StoreFileName, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary, &ex ) ;//
int nItem = m_list.GetNextItem(-1, LVNI_SELECTED);
if (nItem < 0) return;
CString tempstr = "";
tempstr = m_list.GetItemText(nItem,0);
int pNum = atoi(tempstr);
if(pNum <= 0) return;
CString nData = "";
nData.Format("GetFile#%d#",pNum);
((CNClientApp *)AfxGetApp())->m_socket->SendData(nData);
}
void CDlgMain::WriteData(CString strData)
{
int nLen = strlen(strData);
if( nLen <= 0) return;
try{
m_NWFile.Write(strData , nLen);
}
catch(...){;}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -