Click here to Skip to main content
15,892,298 members
Articles / Web Development / HTML

A Comprehensive CE Class Library to Replace ATL and MFC

Rate me:
Please Sign up or sign in to vote.
4.48/5 (14 votes)
4 Oct 2000CPOL 281.1K   998   70  
A collection of classes for CE that do not use ATL or MFC, plus an FTP client, database viewer, and sample application that solves beam deflection equations.

#include "stdafx.h"
#include "ftpSite.h"

#pragma warning(disable:4800)

CeFtpSite::CeFtpSite()
{
}


CeFtpSite::CeFtpSite(CeDbRecord& rec)
{
	rec.GetIdVal(SITE_NAME, m_strName);
	rec.GetIdVal(SITE_ADDRESS, m_strAddress);
	rec.GetIdVal(SITE_USER, m_strUser);
	rec.GetIdVal(SITE_PASSWORD, m_strPassword);
	rec.GetIdVal(SITE_ANONYMOUS, (LONG&)m_bAnon);

	if (!rec.GetIdVal(SITE_PASSIVE, (LONG&)m_bPassive))
		m_bPassive = false;
}


// static 
bool CeFtpSite::Open(CeDb& db)
{
	DWORD dwPropid = MAKELONG(CEVT_LPWSTR, SITE_NAME);

	if (! db.Open(_T("Ftp Sites"), dwPropid))
	{
		if (ERROR_FILE_NOT_FOUND != GetLastError())
		{
			MessageBox(NULL, _T("Unable to open database"), _T("Database Operation Failed"), MB_OK);
			return false;
		}

		SORTORDERSPEC sortSpec;
		sortSpec.propid = dwPropid;
		sortSpec.dwFlags = CEDB_SORT_CASEINSENSITIVE;

		if (! db.Create(_T("Ftp Sites"), 0, 1, &sortSpec))
		{
			MessageBox(NULL, _T("Unable to create save database"), _T("Database Operation Failed"), MB_OK);
			return false;
		}

		if (! db.Open())
		{
			MessageBox(NULL, _T("Error openning Site database"), _T("CeDBError"), MB_OK);
			return false;
		}
	}

	return true;
}


bool CeFtpSite::Update()
{
	CeDb db;
	if (! Open(db))
		return false;

	// Get the current file time of record modificaion
	SYSTEMTIME stNow;
	FILETIME ftNow;
	GetSystemTime(&stNow); 
	FileTimeToSystemTime(&ftNow, &stNow);

	CeDbRecord recFind;
	recFind.AddProp(SITE_NAME, CEVT_LPWSTR);
	recFind.SetIdVal(SITE_NAME, (LPCTSTR) m_strName);
	CEOID oid = db.SeekRec(recFind.m_pProps);

	// always overwrite, we've already asked when the name exists already
	CeDbRecord rec;
	rec.m_oid = oid;

	rec.AddProp(SITE_NAME, CEVT_LPWSTR);
	rec.AddProp(SITE_ADDRESS, CEVT_LPWSTR);
	rec.AddProp(SITE_USER, CEVT_LPWSTR);
	rec.AddProp(SITE_PASSWORD, CEVT_LPWSTR);
	rec.AddProp(SITE_ANONYMOUS, CEVT_I4);
	rec.AddProp(SITE_PASSIVE, CEVT_I4);
	rec.AddProp(SITE_MODIFYDATE, CEVT_FILETIME);

	rec.SetIdVal(SITE_NAME, (LPCTSTR) m_strName);
	rec.SetIdVal(SITE_ADDRESS, (LPCTSTR) m_strAddress);
	rec.SetIdVal(SITE_USER, (LPCTSTR) m_strUser);
	rec.SetIdVal(SITE_PASSWORD, (LPCTSTR) m_strPassword);
	rec.SetIdVal(SITE_ANONYMOUS, (LONG) m_bAnon);
	rec.SetIdVal(SITE_PASSIVE, (LONG) m_bPassive);
//	rec.SetIdVal(SITE_MODIFYDATE, m_ftNow);

	if (rec.m_oid)
	{
		if (! db.UpdateRec(rec))
		{
			MessageBox(NULL, _T("Update Ftp Site Failed"), _T("Update Failed"), MB_OK);
			return false;
		}
	}
	else
	{
		if (! db.AddRec(rec))
		{
			MessageBox(NULL, _T("Add Ftp Site Failed"), _T("Add Failed"), MB_OK);
			return false;
		}
	}

	db.Close();

	return true;
}


bool CeFtpSite::Find(LPCTSTR lpszName)
{
	CeDb db;
	if (! Open(db))
		return false;

	CeDbRecord recFind;
	recFind.AddProp(SITE_NAME, CEVT_LPWSTR);
	recFind.SetIdVal(SITE_NAME, lpszName);
	CEOID oid = db.SeekRec(recFind.m_pProps);

	if (oid == 0)
		return false;

	db.ReadRec(recFind);

	m_strName = lpszName;
	recFind.GetIdVal(SITE_ADDRESS, m_strAddress);
	recFind.GetIdVal(SITE_USER, m_strUser);
	recFind.GetIdVal(SITE_PASSWORD, m_strPassword);
	recFind.GetIdVal(SITE_ANONYMOUS, (LONG&)m_bAnon);

	if (!recFind.GetIdVal(SITE_PASSIVE, (LONG&)m_bPassive))
		m_bPassive = false;

	return true;
}

// static
bool CeFtpSite::Remove(LPCTSTR lpsz)
{
	CeDb db;
	if (! Open(db))
		return false;

	CeDbRecord recFind;
	recFind.AddProp(SITE_NAME, CEVT_LPWSTR);
	recFind.SetIdVal(SITE_NAME, lpsz);

	CEOID oid = db.SeekRec(recFind.m_pProps);

	if (oid)
		return (bool) db.DeleteRecord(oid);

	return false;
}

// static
bool CeFtpSite::Rename(LPCTSTR lpszOld, LPCTSTR lpszNew)
{
	CeDb db;
	if (! Open(db))
		return false;

	CeDbRecord recFind;
	recFind.AddProp(SITE_NAME, CEVT_LPWSTR);
	recFind.SetIdVal(SITE_NAME, lpszOld);

	CEOID oid = db.SeekRec(recFind.m_pProps);
	if (oid)
	{
		db.ReadRec(recFind);
		recFind.SetIdVal(SITE_NAME, lpszNew);

		if (! db.UpdateRec(recFind))
			return false;

		return true;
	}

	return false;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions