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

📄 client.cpp

📁 数据库服务
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	}
	catch(...){
		SendData("DoFail");
	}

}

void Cclient::BackSendFile(CString strData)//#FileIndex#
{
	((CNServerApp *)AfxGetApp())->AddLog(m_strUserCode,m_strUserName,"索回存储文件");

	CString yData = strData;
	if(yData.Find("#") == -1 || yData.GetLength() <= 2 )
	{
		SendData("BadData");
		return;
	}

	yData.Replace("#","");
	if(yData.GetLength() <= 0 )
	{
		SendData("BadData");
		return;
	}
	
	try{
		CStoreFileRst dFile;

		if(dFile.IsOpen())
			dFile.Close();

		CString strFl = "";
		strFl.Format("FileIndex = %s" , yData );
		dFile.m_strFilter = strFl;
		dFile.Open();
		if(!dFile.IsEOF()){
			SendFile(dFile.m_FilePath);
		}
		else{
			SendData("NoThisFile");
		}

		dFile.Close();
	}
	catch(...){
		SendData("DoFail");
	}

}

void Cclient::DeleteFile(CString strData)//#FileIndex#
{
	((CNServerApp *)AfxGetApp())->AddLog(m_strUserCode,m_strUserName,"删除存储文件");

	CString yData = strData;
	if(yData.Find("#") == -1 || yData.GetLength() <= 2 )
	{
		SendData("BadData");
		return;
	}

	yData.Replace("#","");
	if(yData.GetLength() <= 0 )
	{
		SendData("BadData");
		return;
	}
	
	try{
		CStoreFileRst dFile;

		if(dFile.IsOpen())
			dFile.Close();

		CString strFl = "";
		strFl.Format("FileIndex = %s" , yData );
		dFile.m_strFilter = strFl;
		dFile.Open();
		if(!dFile.IsEOF()){
			if(strlen(dFile.m_FilePath) > 0){
				remove(dFile.m_FilePath);
			}
			dFile.Delete();
		}
		else{
			SendData("NoThisFile");
			dFile.Close();
			return;
		}

		dFile.Close();
	}
	catch(...){
		SendData("DoFail");
	}

}

void Cclient::SendFile(CString FileName)
{
	if(strlen(FileName) <=0 )
		return;

	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);
			pBuf[nRead] = 0;
			if(nRead > 0){
				SendData(pBuf);
			}
		}
		pFile.Close();
	}
	catch(...){;}	

	Sleep(100);

	((CNServerApp *)AfxGetApp())->AddLog(m_strUserCode,m_strUserName,"成功索回存储文件");

	SendData("EndSendFile");	

}

void Cclient::GetFile(CString strData)
{
	CString yData = strData;
	if(yData.Find("#") == -1 || yData.GetLength() <= 2 )
	{
		SendData("BadData");
		return;
	}

	yData.Replace("#","");
	if(yData.GetLength() <= 0 )
	{
		SendData("BadData");
		return;
	}
	
	try{
		CString ChkStr = "";
		ChkStr.Format("%s%s" , ((CNServerApp *)AfxGetApp())->m_strMainPath,yData);
		m_NWFileName = ChkStr;
		m_NWFile.Open( m_NWFileName, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary, &ex ) ;//
		Status = C_GETFILE;
	}
	catch(...){;}

}

void Cclient::EndGetFile()
{
	m_NWFile.Close();
	Status = C_FREE;
	CString tempstr = "";
	tempstr.Format("存储文件:%s" , m_NWFileName);
	((CNServerApp *)AfxGetApp())->AddLog(m_strUserCode,m_strUserName,tempstr);
	
	try{
		int nIndex = 0;
		
		CTime tm = CTime::GetCurrentTime();
		CString strTM = "";
		strTM.Format("%04d-%02d-%02d %02d:%02d:%02d",tm.GetYear(),tm.GetMonth(),tm.GetDay(),tm.GetHour(),tm.GetMinute(),tm.GetSecond());

		CAllIndexRst dIndex;
		if(dIndex.IsOpen())
			dIndex.Close();
		
		dIndex.m_strFilter = "IndexType = 103";
		dIndex.Open();
		if(!dIndex.IsEOF()){
			nIndex = dIndex.m_IndexValue + 1;
			dIndex.Edit();
			dIndex.m_IndexValue = nIndex;
			dIndex.Update();
		}
		else{
			nIndex = 100;
			dIndex.AddNew();
			dIndex.m_IndexValue = nIndex;
			dIndex.Update();
		}
		
		dIndex.Close();
		
		if(nIndex <= 0 )
		{
			SendData("DoFail");
			return;
		}
		
		CStoreFileRst dStorFile;
		if(dStorFile.IsOpen())
			dStorFile.Close();

		dStorFile.m_strFilter = "1=0";
		dStorFile.Open();

		dStorFile.AddNew();

		dStorFile.m_FileIndex		= nIndex;
		dStorFile.m_FileName		= m_NWFileName.Right(m_NWFileName.GetLength() - m_NWFileName.ReverseFind('\\') - 1);
		dStorFile.m_FilePath		= m_NWFileName;
		dStorFile.m_FileSpace		= m_FileLen;
		dStorFile.m_StoreUserCode	= atoi(m_strUserCode);
		dStorFile.m_StoreUserName	= m_strUserName;
		dStorFile.m_StoreTime		= strTM;
		dStorFile.Update();

		dStorFile.Close();

	}
	catch(...){;}
}

void Cclient::CheckUser(CString strData)//#用户编号#
{
	CString dUsercode = "";
	CString dUsername = "";

	CString yData = strData;
	if(yData.Find("#") == -1 || yData.GetLength() <= 3 )
	{
		SendData("BadData");
		return;
	}

	yData = yData.Right(yData.GetLength() - 1);
	int pNum = yData.Find("#");
	if(pNum == -1)
	{
		SendData("BadData");
		return;
	}

	dUsercode = yData.Left(pNum);
	yData = yData.Right(pNum + 1);
	if(strlen(yData) > 0)
		yData.Replace("#","");

	dUsername = yData;

	if(strlen(dUsercode) <= 0 || strlen(dUsername) <= 0)
	{
		SendData("BadData");
		return;
	}

	((CNServerApp *)AfxGetApp())->AddLog(dUsercode,dUsername,"要求登录");

	try{
		CString strFl = "";
		CUserRst dUser;
		
		if(dUser.IsOpen())
			dUser.Close();

		strFl.Format("UserIndex = %s and UserName = '%s'",dUsercode,dUsername);

		dUser.m_strFilter = strFl;
		
		dUser.Open();
		
		if(!dUser.IsEOF()){
			SendData("CheckUserOk");
		}
		else{
			SendData("NoThisUser");
			dUser.Close();
			return;
		}

		dUser.Close();

	}
	catch(...){
		SendData("DoFail");
		((CNServerApp *)AfxGetApp())->AddLog(dUsercode,dUsername,"登录失败");
	}
	m_strUserCode = dUsercode;
	m_strUserName = dUsername;

	((CNServerApp *)AfxGetApp())->AddLog(dUsercode,dUsername,"成功登录");

}

void Cclient::SaveRequest(CString strData)//#UserCode#UserName#Number#
{
	CString strCode = "";
	CString strName = "";
	CString strNum = "";

	CString yData = strData;
	if(yData.Find("#") == -1 || yData.GetLength() <= 4 )
	{
		SendData("BadData");
		return;
	}

	yData = yData.Right(yData.GetLength() - 1);
	int pNum = yData.Find("#");
	if(pNum == -1)
	{
		SendData("BadData");
		return;
	}

	strCode = yData.Left(pNum);
	yData = yData.Right(yData.GetLength() - pNum - 1);
	pNum = yData.Find("#");
	if(pNum == -1)
	{
		SendData("BadData");
		return;
	}

	strName = yData.Left(pNum);
	yData = yData.Right(yData.GetLength() - pNum - 1);
	if(strlen(yData) > 0)
		yData.Replace("#","");
	strNum = yData;

	if(strlen(strCode) <= 0 || strlen(strName) <= 0 || strlen(strNum) <= 0)
	{
		SendData("BadData");
		return;
	}

	((CNServerApp *)AfxGetApp())->AddLog(m_strUserCode,m_strUserName,"存储空间申请");

	try{
		int nIndex = 0;
		
		CAllIndexRst dIndex;
		if(dIndex.IsOpen())
			dIndex.Close();
		
		dIndex.m_strFilter = "IndexType = 102";
		dIndex.Open();
		if(!dIndex.IsEOF()){
			nIndex = dIndex.m_IndexValue + 1;
			dIndex.Edit();
			dIndex.m_IndexValue = nIndex;
			dIndex.Update();
		}
		else{
			nIndex = 100;
			dIndex.AddNew();
			dIndex.m_IndexValue = nIndex;
			dIndex.Update();
		}
		
		dIndex.Close();
		
		if(nIndex <= 0 )
			SendData("DoFail");
		
		CRequestRst m_ReqRst;
		
		if(m_ReqRst.IsOpen())
			m_ReqRst.Close();
		
		m_ReqRst.Open();
		m_ReqRst.AddNew();
		m_ReqRst.m_RequestIndex = nIndex;
		m_ReqRst.m_RequestUserCode = atoi(strCode);
		m_ReqRst.m_RequestUserName = strName;
		m_ReqRst.m_RequestSpace = atoi(strNum);
		m_ReqRst.m_HasAgree = 0;
		m_ReqRst.Update();
		
		m_ReqRst.Close();
	}
	catch(...){
		SendData("DoFail");
	}

}

void Cclient::GetRequest(CString strData)//#UserCode#
{
	CString strCode = strData;

	if(strlen(strCode) <=0){
		SendData("BadData");
		return;
	}

	strCode.Replace("#","");
	if(strlen(strCode) <=0){
		SendData("BadData");
		return;
	}

	((CNServerApp *)AfxGetApp())->AddLog(m_strUserCode,m_strUserName,"获取存储空间申请处理结果");

	try{
		CRequestRst m_ReqRst;
		CString strFt = "";
		
		if(m_ReqRst.IsOpen())
			m_ReqRst.Close();
		
		strFt.Format("RequestUserCode = %s", strCode);

		m_ReqRst.Open();

		while(!m_ReqRst.IsEOF()){
			CString nData = "";
			nData.Format("#%d#%d#%d#",m_ReqRst.m_RequestIndex,m_ReqRst.m_RequestSpace,m_ReqRst.m_HasAgree);
			SendData(nData);
			m_ReqRst.MoveNext();
		}

		m_ReqRst.Close();

		SendData("SendReqEnd");
	}
	catch(...){
		SendData("DoFail");
	}

}	

⌨️ 快捷键说明

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