#include "StdAfx.h"
#include "DBOperate.h"

CDBOperate::CDBOperate(void)
{
	m_pConnection = NULL;
	m_pRecordset  = NULL;
}

CDBOperate::~CDBOperate(void)
{
}

int CDBOperate::m_nCount = 0;

BOOL CDBOperate::SaveMap( C2DMap* pMap , CString strMapName)
{
	if (m_pConnection == NULL || !(m_pConnection->GetState() != adStateClosed))
	{
		AfxMessageBox(_T("数据库未连接，请连接数据库！"));
		return FALSE;
	}
	
	// 查询数据库中表格是否齐全
	CStringArray saTables;
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	try
	{
		m_pRecordset = m_pConnection->OpenSchema(adSchemaTables);
		while(!(m_pRecordset->adoEOF))
		{
			CString strTable;
			_bstr_t tablename = m_pRecordset->Fields->GetItem("TABLE_NAME")->Value;
			_bstr_t tabletype = m_pRecordset->Fields->GetItem("TABLE_TYPE")->Value;

			strTable.Format("%s",(LPSTR)tabletype);
			if (!lstrcmp(strTable,_T("TABLE")))
			{
				saTables.Add((LPCSTR)tablename);
			}
			m_pRecordset->MoveNext();
		}
		m_pRecordset->PutSort(_T(""));
		m_pRecordset->Close();
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());
		return FALSE;
	}

	if (!CheckDB(saTables))
	{
		return FALSE;
	}

	// 检查是否有重复的MapName，有重复的返回，没有写入Map表格
	CString strSQL = _T("select * from Draw_Map");
	try
	{
		_bstr_t bsMapName;
		m_pRecordset->Open((_bstr_t)strSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
		while(!(m_pRecordset->adoEOF))
		{
			bsMapName = m_pRecordset->Fields->GetItem("MapName")->Value;
			if (!strMapName.Compare((LPCSTR)bsMapName))
			{
				CString strMsg;
				strMsg.Format(_T("MapName为%s的记录已经在表Draw_Map中存在！"),strMapName);
				AfxMessageBox(strMsg);
				m_pRecordset->Close();
				return FALSE;
			}
			m_pRecordset->MoveNext();
		}

		// 查找记录数量
		int nRows = 0;
		nRows = (int)m_pRecordset->GetRecordCount();
		if (nRows == -1)
		{
			if (m_pRecordset->adoEOF != VARIANT_TRUE)
			{
				m_pRecordset->MoveFirst();
			}
			while(m_pRecordset->adoEOF != VARIANT_TRUE)
			{
				nRows++;
				m_pRecordset->MoveNext();
			}
			if (nRows>0)
			{
				m_pRecordset->MoveFirst();
			}
		}
		m_pRecordset->AddNew();
		COleDateTime time;
		time = COleDateTime::GetCurrentTime();
		_variant_t vtField;
		vtField.vt = VT_DATE;
		vtField.date = time;
		m_pRecordset->GetFields()->GetItem("MapName")->Value = (_bstr_t)strMapName;
		m_pRecordset->GetFields()->GetItem("Time")->Value    =  vtField;
		m_pRecordset->Update();
		m_pRecordset->PutSort(_T(""));
		m_pRecordset->Close();
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());
		return FALSE;
	}


	CArray<C2DPoint*,C2DPoint*> arPt;
	CArray<C2DBeeLine*,C2DBeeLine*> arBL;
	CArray<C2DPolyLine*,C2DPolyLine*> arPL;
	CArray<C2DCurve*,C2DCurve*> arCV;
	CArray<C2DTriangle*,C2DTriangle*> arTIN;
	CArray<C2DCircle*,C2DCircle*> arCir;
	arPt.RemoveAll();
	arBL.RemoveAll();
	arPL.RemoveAll();
	arCV.RemoveAll();
	arTIN.RemoveAll();
	arCir.RemoveAll();
    
	int nCount = pMap->GetCount();
	for (int i=0; i!=nCount; ++i)
	{
		C2DObject* pObj = pMap->m_arObj.GetAt(i);
		int nClassType = (int)pObj->GetClass();
		switch(nClassType)
		{
		case 1:
			{
				arPt.Add((C2DPoint*)pObj);
			}
			break;
		case 2:
			{
				arBL.Add((C2DBeeLine*)pObj);
			}
			break;
		case 3:
			{
				arPL.Add((C2DPolyLine*)pObj);
			}
			break;
		case 4:
			{
				arCV.Add((C2DCurve*)pObj);
			}
			break;
		case 5:
			{
				arTIN.Add((C2DTriangle*)pObj);
			}
			break;
		case 6:
			{
				arCir.Add((C2DCircle*)pObj);
			}
			break;
		}
	}

	// 写入数据
	SaveC2DPoint(arPt,strMapName);
	SaveC2DBeeLine(arBL,strMapName);
	SaveC2DCircle(arCir,strMapName);
	SaveC2DPolyLine(arPL,strMapName);
	SaveC2DTriangle(arTIN,strMapName);
	SaveC2DCurve(arCV,strMapName);
//	AfxMessageBox(_T("入库成功！"));
	return TRUE;
}

C2DMap* CDBOperate::CreateMap( CString strMapName )
{
	CArray<C2DPoint*,C2DPoint*> arPt;
    CArray<C2DBeeLine*,C2DBeeLine*> arBL;
	CArray<C2DCircle*,C2DCircle*> arCir;
	CArray<C2DPolyLine*,C2DPolyLine*> arPL;
	CArray<C2DTriangle*,C2DTriangle*> arTIN;
	CArray<C2DCurve*,C2DCurve*> arCV;
	ReadC2DPoint(arPt,strMapName);
	ReadC2DBeeLine(arBL,strMapName);
	ReadC2DCircle(arCir,strMapName);
	ReadC2DPolyLine(arPL,strMapName);
	ReadC2DTriangle(arTIN,strMapName);
	ReadC2DCurve(arCV,strMapName);
	C2DMap* pMap = new C2DMap;
	for (int i=0; i!=arPt.GetCount(); ++i)
	{
		pMap->m_arObj.Add((C2DObject*)arPt.GetAt(i));
	}
	for (int i=0; i!=arBL.GetCount(); ++i)
	{
		pMap->m_arObj.Add((C2DObject*)arBL.GetAt(i));
	}
	for (int i=0; i!=arCir.GetCount(); ++i)
	{
		pMap->m_arObj.Add((C2DObject*)arCir.GetAt(i));
	}
	for (int i=0; i!=arPL.GetCount(); ++i)
	{
		pMap->m_arObj.Add((C2DObject*)arPL.GetAt(i));
	}
	for (int i=0; i!=arTIN.GetCount(); ++i)
	{
		pMap->m_arObj.Add((C2DObject*)arTIN.GetAt(i));
	}
	for (int i=0; i!=arCV.GetCount(); ++i)
	{
		pMap->m_arObj.Add((C2DObject*)arCV.GetAt(i));
	}
	return pMap;
}

BOOL CDBOperate::CreateMapTable()
{
	return TRUE;
}

BOOL CDBOperate::CreatePointTable()
{
	return TRUE;
}

BOOL CDBOperate::CreateLineTable()
{

    return TRUE;
}

BOOL CDBOperate::CreateCurveTypeTable()
{

	return TRUE;
}

BOOL CDBOperate::CheckDBTables( CStringArray& sa , CString strTableName)
{
	int nCount = (int)sa.GetCount();
	int i;
	for (i=0; i!=nCount; ++i)
	{
		CString strName = sa.GetAt(i);
		if (strName == strTableName)
		{
			break;
		}
	}
	if (i == nCount)
	{
		CString strMsg;
		strMsg.Format(_T("%s不存在，是否创建"),strTableName);
		int nRes = AfxMessageBox(strMsg,MB_YESNO);
		if (nRes == IDYES)
		{
			CreateMapTable();
			return TRUE;
		}
		else if (nRes == IDNO)
		{
			return FALSE;
		}
	}
	return TRUE;
}

BOOL CDBOperate::CheckDB( CStringArray& sa )
{
	if (!CheckDBTables(sa,_T("Draw_Map")))
	{
		return FALSE;
	}
	if (!CheckDBTables(sa,_T("Draw_Point")))
	{
		return FALSE;
	}
	if (!CheckDBTables(sa,_T("Draw_Line")))
	{
		return FALSE;
	}
	if (!CheckDBTables(sa,_T("Draw_CurveType")))
	{
		return FALSE;
	}
	return TRUE;
}


void CDBOperate::SaveC2DPoint( CArray<C2DPoint*,C2DPoint*>& arPt, CString strMapName )
{
	int nCount = (int)arPt.GetCount();
	if (nCount == 0)
	{
		return;
	}
	CString strSQL = _T("select * from Draw_Obj");
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	_RecordsetPtr pRecordset;
	pRecordset.CreateInstance(__uuidof(Recordset));
	try
	{
		m_pRecordset->Open((_bstr_t)strSQL, m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
        for (int i=0; i!=nCount; ++i)
        {
			m_pRecordset->AddNew();
			_variant_t vtID,vtR,vtG,vtB,vtClass;
			BYTE r,g,b;
			vtID.vt = VT_INT;
			vtID.intVal = (arPt.GetAt(i))->GetID();
			(arPt.GetAt(i))->GetColor(r,g,b);
			vtR.vt = VT_I2;
			vtR.iVal = r;
			vtG.vt = VT_I2;
			vtG.iVal = g;
			vtB.vt = VT_I2;
			vtB.iVal = b;
			vtClass.vt = VT_INT;
			vtClass.intVal = 1;
			m_pRecordset->GetFields()->GetItem("Obj_ID")->Value = vtID;
			m_pRecordset->GetFields()->GetItem("Obj_R")->Value = vtR;
			m_pRecordset->GetFields()->GetItem("Obj_G")->Value = vtG;
			m_pRecordset->GetFields()->GetItem("Obj_B")->Value = vtB;
			m_pRecordset->GetFields()->GetItem("Obj_Class")->Value = vtClass;
			m_pRecordset->GetFields()->GetItem("MapName")->Value = (_bstr_t)strMapName;
			m_pRecordset->Update();
		
			CString strSQL2;
			int nFlag = 0;
			int x,y;
			DWORD dwID = (arPt.GetAt(i))->GetID();
			(arPt.GetAt(i))->GetPoint(x,y);
			strSQL2.Format(_T("insert into Draw_Point (MapName,Obj_ID,Flag,Obj_X,Obj_Y) values(\'%s\',\'%d\',\'%d\',\'%d\',\'%d\')"),strMapName,dwID,nFlag,x,y);
			m_pConnection->Execute((_bstr_t)strSQL2,NULL,adCmdText);
			++m_nCount;
		}	
 		m_pRecordset->PutSort(_T(""));
 		m_pRecordset->Close();
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());		
	}
}

void CDBOperate::ReadC2DPoint( CArray<C2DPoint*,C2DPoint*>& arPt, CString strMapName )
{
	arPt.RemoveAll();
    CString strSQL;
	DWORD nClass = 1;
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	_RecordsetPtr pRecordset;
	pRecordset.CreateInstance(__uuidof(Recordset));
	strSQL.Format(_T("select * from Draw_Obj where MapName = '%s' and Obj_Class = %d"), strMapName, nClass);
	try
	{
		m_pRecordset->Open((_bstr_t)strSQL, m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
		// 查找记录数量
		int nRows = 0;
		nRows = (int)m_pRecordset->GetRecordCount();
		if (nRows == -1)
		{
			if (m_pRecordset->adoEOF != VARIANT_TRUE)
			{
				m_pRecordset->MoveFirst();
			}
			while(m_pRecordset->adoEOF != VARIANT_TRUE)
			{
				nRows++;
				m_pRecordset->MoveNext();
			}
			if (nRows>0)
			{
				m_pRecordset->MoveFirst();
			}
		}
		if (nRows<=0)
		{
			return;
		}
		for (int i=0; i!=nRows; ++i)
		{
			BYTE r,g,b;
			DWORD dwID;
			dwID = (DWORD)m_pRecordset->GetFields()->GetItem("Obj_ID")->Value;
			r    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_R")->Value;
			g    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_G")->Value;
			b    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_B")->Value;

			CString strSQL2;
			strSQL2.Format(_T("select * from Draw_Point where MapName = '%s' and Obj_ID = %d"),strMapName,dwID);
			pRecordset->Open((_bstr_t)strSQL2, m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
			int nRID = 0;
			nRID = (int)pRecordset->GetRecordCount();
			if (nRID == -1)
			{
				if (pRecordset->adoEOF != VARIANT_TRUE)
				{
					pRecordset->MoveFirst();
				}
				while(pRecordset->adoEOF != VARIANT_TRUE)
				{
					nRID++;
					pRecordset->MoveNext();
				}
				if (nRID>0)
				{
					pRecordset->MoveFirst();
				}
			}
			if (nRID == 1)
			{
				int x,y;
				x = (int)pRecordset->GetFields()->GetItem("Obj_X")->Value;
				y = (int)pRecordset->GetFields()->GetItem("Obj_Y")->Value;
				C2DPoint* pObj = new C2DPoint(CPoint(x,y));
				pObj->SetID(dwID);
				pObj->SetColor(r,g,b);
				arPt.Add(pObj);
			}
			pRecordset->Close();
			m_pRecordset->MoveNext();
		}
		m_pRecordset->Close();
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());			
	}
}

void CDBOperate::SaveC2DBeeLine( CArray<C2DBeeLine*,C2DBeeLine*>& arBL, CString strMapName )
{
	int nCount = (int)arBL.GetCount();
	if (nCount == 0)
	{
		return;
	}
	try
	{
		for (int i=0; i!=nCount; ++i)
		{
			C2DBeeLine* pObj = arBL.GetAt(i);
			int nFlag = 0;
			int x1,y1,x2,y2;
			DWORD dwID = pObj->GetID();
			BYTE r,g,b;
			int nClass = 2;
			BYTE byLineStyle;
			UINT LineWidth;
			pObj->GetColor(r,g,b);
			pObj->GetPoint(x1,y1,x2,y2);
            byLineStyle = pObj->m_byLineStyle;
			LineWidth   = pObj->m_wLineWidth;
			CString strS;
			strS.Format(_T("insert into Draw_Obj (MapName,Obj_ID,Obj_R,Obj_G,Obj_B,Obj_Class) values(\'%s\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\')")
				,strMapName,dwID,r,g,b,nClass);
			m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			strS.Format(_T("insert into Draw_Line (MapName,Obj_ID,LineStyle,LineWidth) values(\'%s\',\'%d\',\'%d\',\'%d\')")
				,strMapName,dwID,byLineStyle,LineWidth);
            m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			strS.Format(_T("insert into Draw_Point (MapName,Obj_ID,Flag,Obj_X,Obj_Y) values(\'%s\',\'%d\',\'%d\',\'%d\',\'%d\')")
				,strMapName,dwID,nFlag,x1,y1);
			++nFlag;
			m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			strS.Format(_T("insert into Draw_Point (MapName,Obj_ID,Flag,Obj_X,Obj_Y) values(\'%s\',\'%d\',\'%d\',\'%d\',\'%d\')")
				,strMapName,dwID,nFlag,x2,y2);
			m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			++m_nCount;
		}
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());
	}
}

void CDBOperate::ReadC2DBeeLine( CArray<C2DBeeLine*,C2DBeeLine*>& arBL, CString strMapName )
{
	arBL.RemoveAll();
	CString strSQL;
	DWORD nClass = 2;
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	_RecordsetPtr pRecordset;
	pRecordset.CreateInstance(__uuidof(Recordset));
	strSQL.Format(_T("select * from Draw_Obj where MapName = '%s' and Obj_Class = %d"), strMapName, nClass);
	try
	{
		m_pRecordset->Open((_bstr_t)strSQL, m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
		// 查找记录数量
		int nRows = 0;
		nRows = (int)m_pRecordset->GetRecordCount();
		if (nRows == -1)
		{
			if (m_pRecordset->adoEOF != VARIANT_TRUE)
			{
				m_pRecordset->MoveFirst();
			}
			while(m_pRecordset->adoEOF != VARIANT_TRUE)
			{
				nRows++;
				m_pRecordset->MoveNext();
			}
			if (nRows>0)
			{
				m_pRecordset->MoveFirst();
			}
		}
		if (nRows<=0)
		{
			return;
		}
		for (int i=0; i!=nRows; ++i)
		{
			BYTE r,g,b;
			DWORD dwID;
			dwID = (DWORD)m_pRecordset->GetFields()->GetItem("Obj_ID")->Value;
			r    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_R")->Value;
			g    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_G")->Value;
			b    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_B")->Value;

			CString strSQL2;
			strSQL2.Format(_T("select * from Draw_Point where MapName = '%s' and Obj_ID = %d order by Flag asc"),strMapName,dwID);
			pRecordset->Open((_bstr_t)strSQL2, m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
			int nRID = 0;
			nRID = (int)pRecordset->GetRecordCount();
			if (nRID == -1)
			{
				if (pRecordset->adoEOF != VARIANT_TRUE)
				{
					pRecordset->MoveFirst();
				}
				while(pRecordset->adoEOF != VARIANT_TRUE)
				{
					nRID++;
					pRecordset->MoveNext();
				}
				if (nRID>0)
				{
					pRecordset->MoveFirst();
				}
			}
			if (nRID == 2)
			{
				pRecordset->MoveFirst();
				int x1,y1,x2,y2;
				x1 = (int)pRecordset->GetFields()->GetItem("Obj_X")->Value;
				y1 = (int)pRecordset->GetFields()->GetItem("Obj_Y")->Value;
				pRecordset->MoveNext();
				x2 = (int)pRecordset->GetFields()->GetItem("Obj_X")->Value;
				y2 = (int)pRecordset->GetFields()->GetItem("Obj_Y")->Value;
                pRecordset->Close();

				CString strSQL3;
				BYTE byLineStyle;
				UINT LineWidth;
				strSQL3.Format(_T("select * from Draw_Line where MapName = '%s' and Obj_ID = %d"),strMapName,dwID);
				pRecordset->Open((_bstr_t)strSQL3,m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
				int nCou = 0;
				nCou = (int)pRecordset->GetRecordCount();
				if (nCou == -1)
				{
					if (pRecordset->adoEOF != VARIANT_TRUE)
					{
						pRecordset->MoveFirst();
					}
					while(pRecordset->adoEOF != VARIANT_TRUE)
					{
						nCou++;
						pRecordset->MoveNext();
					}
					if (nCou>0)
					{
						pRecordset->MoveFirst();
					}
				}

				C2DBeeLine* pObj = new C2DBeeLine(CPoint(x1,y1),CPoint(x2,y2));
				pObj->SetID(dwID);
				pObj->SetColor(r,g,b);
	         	if (nCou == 1)
				{
					byLineStyle = (BYTE)pRecordset->GetCollect("LineStyle");
					LineWidth   = (UINT)pRecordset->GetCollect("LineWidth");
					pObj->m_byLineStyle = byLineStyle;
					pObj->m_wLineWidth = LineWidth;
				}
				arBL.Add(pObj);
			}
			pRecordset->Close();
			m_pRecordset->MoveNext();
		}
		m_pRecordset->Close();
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());			
	}
}

void CDBOperate::SaveC2DCircle( CArray<C2DCircle*,C2DCircle*>& arCir, CString strMapName )
{
	int nCount = (int)arCir.GetCount();
	if (nCount == 0)
	{
		return;
	}
	try
	{
		for (int i=0; i!=nCount; ++i)
		{
			C2DCircle* pObj = arCir.GetAt(i);
			int nFlag = 0;
			int x1,y1,x2,y2;
			DWORD dwID = pObj->GetID();
			BYTE r,g,b;
			int nClass = 6;
			CString strSQL3;
			BYTE byLineStyle;
			UINT LineWidth;
			pObj->GetColor(r,g,b);
			pObj->GetPoint(x1,y1,x2,y2);
			byLineStyle = pObj->m_byLineStyle;
			LineWidth   = pObj->m_wLineWidth;
			CString strS;
			strS.Format(_T("insert into Draw_Obj (MapName,Obj_ID,Obj_R,Obj_G,Obj_B,Obj_Class) values(\'%s\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\')")
				,strMapName,dwID,r,g,b,nClass);
			m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			strS.Format(_T("insert into Draw_Line (MapName,Obj_ID,LineStyle,LineWidth) values(\'%s\',\'%d\',\'%d\',\'%d\')")
				,strMapName,dwID,byLineStyle,LineWidth);
			m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			strS.Format(_T("insert into Draw_Point (MapName,Obj_ID,Flag,Obj_X,Obj_Y) values(\'%s\',\'%d\',\'%d\',\'%d\',\'%d\')")
				,strMapName,dwID,nFlag,x1,y1);
			++nFlag;
			m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			strS.Format(_T("insert into Draw_Point (MapName,Obj_ID,Flag,Obj_X,Obj_Y) values(\'%s\',\'%d\',\'%d\',\'%d\',\'%d\')")
				,strMapName,dwID,nFlag,x2,y2);
			m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			++m_nCount;
		}
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());
	}
}

void CDBOperate::ReadC2DCircle( CArray<C2DCircle*,C2DCircle*>& arCir, CString strMapName )
{
	arCir.RemoveAll();
	CString strSQL;
	DWORD nClass = 6;
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	_RecordsetPtr pRecordset;
	pRecordset.CreateInstance(__uuidof(Recordset));
	strSQL.Format(_T("select * from Draw_Obj where MapName = '%s' and Obj_Class = %d"), strMapName, nClass);
	try
	{
		m_pRecordset->Open((_bstr_t)strSQL, m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
		// 查找记录数量
		int nRows = 0;
		nRows = (int)m_pRecordset->GetRecordCount();
		if (nRows == -1)
		{
			if (m_pRecordset->adoEOF != VARIANT_TRUE)
			{
				m_pRecordset->MoveFirst();
			}
			while(m_pRecordset->adoEOF != VARIANT_TRUE)
			{
				nRows++;
				m_pRecordset->MoveNext();
			}
			if (nRows>0)
			{
				m_pRecordset->MoveFirst();
			}
		}
		if (nRows<=0)
		{
			return;
		}
		for (int i=0; i!=nRows; ++i)
		{
			BYTE r,g,b;
			DWORD dwID;
			dwID = (DWORD)m_pRecordset->GetFields()->GetItem("Obj_ID")->Value;
			r    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_R")->Value;
			g    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_G")->Value;
			b    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_B")->Value;

			CString strSQL2;
			strSQL2.Format(_T("select * from Draw_Point where MapName = '%s' and Obj_ID = %d order by Flag asc"),strMapName,dwID);
			pRecordset->Open((_bstr_t)strSQL2, m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
			int nRID = 0;
			nRID = (int)pRecordset->GetRecordCount();
			if (nRID == -1)
			{
				if (pRecordset->adoEOF != VARIANT_TRUE)
				{
					pRecordset->MoveFirst();
				}
				while(pRecordset->adoEOF != VARIANT_TRUE)
				{
					nRID++;
					pRecordset->MoveNext();
				}
				if (nRID>0)
				{
					pRecordset->MoveFirst();
				}
			}
			if (nRID == 2)
			{
				pRecordset->MoveFirst();
				int x1,y1,x2,y2;
				x1 = (int)pRecordset->GetFields()->GetItem("Obj_X")->Value;
				y1 = (int)pRecordset->GetFields()->GetItem("Obj_Y")->Value;
				pRecordset->MoveNext();
				x2 = (int)pRecordset->GetFields()->GetItem("Obj_X")->Value;
				y2 = (int)pRecordset->GetFields()->GetItem("Obj_Y")->Value;
				pRecordset->Close();

				CString strSQL3;
				strSQL3.Format(_T("select * from Draw_Line where MapName = '%s' and Obj_ID = %d"),strMapName,dwID);	
				pRecordset->Open((_bstr_t)strSQL3,m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
				int nCou = 0;
				nCou = (int)pRecordset->GetRecordCount();
				if (nCou == -1)
				{
					if (pRecordset->adoEOF != VARIANT_TRUE)
					{
						pRecordset->MoveFirst();
					}
					while(pRecordset->adoEOF != VARIANT_TRUE)
					{
						nCou++;
						pRecordset->MoveNext();
					}
					if (nCou>0)
					{
						pRecordset->MoveFirst();
					}
				}
				C2DCircle* pObj = new C2DCircle(CPoint(x1,y1),CPoint(x2,y2));
				pObj->SetID(dwID);
				pObj->SetColor(r,g,b);
				if (nCou == 1)
				{
					BYTE byLineStyle;
					UINT LineWidth;
					byLineStyle = (BYTE)pRecordset->GetCollect("LineStyle");
					LineWidth   = (UINT)pRecordset->GetCollect("LineWidth");
					pObj->m_byLineStyle = byLineStyle;
					pObj->m_wLineWidth = LineWidth;
				}
				arCir.Add(pObj);
			}
			pRecordset->Close();
			m_pRecordset->MoveNext();
		}
		m_pRecordset->Close();
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());			
	}
}

void CDBOperate::SaveC2DPolyLine( CArray<C2DPolyLine*,C2DPolyLine*>& arPL, CString strMapName )
{
	int nCount = (int)arPL.GetCount();
	if (nCount == 0)
	{
		return;
	}
	try
	{
		for (int i=0; i!=nCount; ++i)
		{
			C2DPolyLine* pObj = arPL.GetAt(i);
			int nFlag = 0;
			DWORD dwID = pObj->GetID();
			BYTE r,g,b;
			int nClass = 3;
			pObj->GetColor(r,g,b);
			CString strS;
			strS.Format(_T("insert into Draw_Obj (MapName,Obj_ID,Obj_R,Obj_G,Obj_B,Obj_Class) values(\'%s\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\')")
				,strMapName,dwID,r,g,b,nClass);
			m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			BYTE byLineStyle;
			UINT LineWidth;
			byLineStyle = pObj->m_byLineStyle;
			LineWidth   = pObj->m_wLineWidth;
			strS.Format(_T("insert into Draw_Line (MapName,Obj_ID,LineStyle,LineWidth) values(\'%s\',\'%d\',\'%d\',\'%d\')")
				,strMapName,dwID,byLineStyle,LineWidth);
			m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			int nCou = pObj->GetCount();
			for (int i=0; i!=nCou; ++i)
			{
				int x,y;
				pObj->GetPoint(i,x,y);
 			    strS.Format(_T("insert into Draw_Point (MapName,Obj_ID,Flag,Obj_X,Obj_Y) values(\'%s\',\'%d\',\'%d\',\'%d\',\'%d\')")
 				            ,strMapName,dwID,nFlag++,x,y);
			    m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			}
			++m_nCount;
		}
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());
	}
}

void CDBOperate::ReadC2DPolyLine( CArray<C2DPolyLine*,C2DPolyLine*>& arPL, CString strMapName )
{
	arPL.RemoveAll();
	CString strSQL;
	DWORD nClass = 3;
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	_RecordsetPtr pRecordset;
	pRecordset.CreateInstance(__uuidof(Recordset));
	strSQL.Format(_T("select * from Draw_Obj where MapName = '%s' and Obj_Class = %d"), strMapName, nClass);
	try
	{
		m_pRecordset->Open((_bstr_t)strSQL, m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
		// 查找记录数量
		int nRows = 0;
		nRows = (int)m_pRecordset->GetRecordCount();
		if (nRows == -1)
		{
			if (m_pRecordset->adoEOF != VARIANT_TRUE)
			{
				m_pRecordset->MoveFirst();
			}
			while(m_pRecordset->adoEOF != VARIANT_TRUE)
			{
				nRows++;
				m_pRecordset->MoveNext();
			}
			if (nRows>0)
			{
				m_pRecordset->MoveFirst();
			}
		}
		if (nRows<=0)
		{
			return;
		}
		for (int i=0; i!=nRows; ++i)
		{
			BYTE r,g,b;
			DWORD dwID;
			dwID = (DWORD)m_pRecordset->GetFields()->GetItem("Obj_ID")->Value;
			r    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_R")->Value;
			g    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_G")->Value;
			b    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_B")->Value;

			CString strSQL2;
			strSQL2.Format(_T("select * from Draw_Point where MapName = '%s' and Obj_ID = %d order by Flag asc"),strMapName,dwID);
			pRecordset->Open((_bstr_t)strSQL2, m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
			int nRID = 0;
			nRID = (int)pRecordset->GetRecordCount();
			if (nRID == -1)
			{
				if (pRecordset->adoEOF != VARIANT_TRUE)
				{
					pRecordset->MoveFirst();
				}
				while(pRecordset->adoEOF != VARIANT_TRUE)
				{
					nRID++;
					pRecordset->MoveNext();
				}
				if (nRID>0)
				{
					pRecordset->MoveFirst();
				}
			}
			if (nRID > 1)
			{
				pRecordset->MoveFirst();
				CArray<CPoint,CPoint&> arPt;
				arPt.RemoveAll();
				while(!pRecordset->adoEOF)
				{
					int x,y;
					x = (int)pRecordset->GetFields()->GetItem("Obj_X")->Value;
					y = (int)pRecordset->GetFields()->GetItem("Obj_Y")->Value;
					arPt.Add(CPoint(x,y));
					pRecordset->MoveNext();
				}
				pRecordset->Close();

				CString strSQL3;
				strSQL3.Format(_T("select * from Draw_Line where MapName = '%s' and Obj_ID = %d"),strMapName,dwID);				
				pRecordset->Open((_bstr_t)strSQL3,m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
				int nCou = 0;
				nCou = (int)pRecordset->GetRecordCount();
				if (nCou == -1)
				{
					if (pRecordset->adoEOF != VARIANT_TRUE)
					{
						pRecordset->MoveFirst();
					}
					while(pRecordset->adoEOF != VARIANT_TRUE)
					{
						nCou++;
						pRecordset->MoveNext();
					}
					if (nCou>0)
					{
						pRecordset->MoveFirst();
					}
				}
				C2DPolyLine* pObj = new C2DPolyLine(arPt);
				pObj->SetID(dwID);
				pObj->SetColor(r,g,b);
				if (nCou == 1)
				{
					BYTE byLineStyle;
					UINT LineWidth;
					byLineStyle = (BYTE)pRecordset->GetCollect("LineStyle");
					LineWidth   = (UINT)pRecordset->GetCollect("LineWidth");
					pObj->m_byLineStyle = byLineStyle;
					pObj->m_wLineWidth = LineWidth;
				}
				arPL.Add(pObj);
			}
			pRecordset->Close();
			m_pRecordset->MoveNext();
		}
		m_pRecordset->Close();
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());			
	}
}

void CDBOperate::SaveC2DTriangle( CArray<C2DTriangle*,C2DTriangle*>& arTIN, CString strMapName )
{
	int nCount = (int)arTIN.GetCount();
	if (nCount == 0)
	{
		return;
	}
	try
	{
		for (int i=0; i!=nCount; ++i)
		{
			C2DTriangle* pObj = arTIN.GetAt(i);
			int nFlag = 0;
			DWORD dwID = pObj->GetID();
			BYTE r,g,b;
			int nClass = 5;
			pObj->GetColor(r,g,b);
			CString strS;
			strS.Format(_T("insert into Draw_Obj (MapName,Obj_ID,Obj_R,Obj_G,Obj_B,Obj_Class) values(\'%s\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\')")
				,strMapName,dwID,r,g,b,nClass);
			m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			BYTE byLineStyle;
			UINT LineWidth;
			byLineStyle = pObj->m_byLineStyle;
			LineWidth   = pObj->m_wLineWidth;
			strS.Format(_T("insert into Draw_Line (MapName,Obj_ID,LineStyle,LineWidth) values(\'%s\',\'%d\',\'%d\',\'%d\')")
				,strMapName,dwID,byLineStyle,LineWidth);
			m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			int nCou = 3;
			for (int i=0; i!=nCou; ++i)
			{
				int x,y;
				pObj->GetPoint(i,x,y);
				strS.Format(_T("insert into Draw_Point (MapName,Obj_ID,Flag,Obj_X,Obj_Y) values(\'%s\',\'%d\',\'%d\',\'%d\',\'%d\')")
					,strMapName,dwID,nFlag++,x,y);
				m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			}
			++m_nCount;
		}
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());
	}
}

void CDBOperate::ReadC2DTriangle( CArray<C2DTriangle*,C2DTriangle*>& arTIN, CString strMapName )
{
	arTIN.RemoveAll();
	CString strSQL;
	DWORD nClass = 5;
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	_RecordsetPtr pRecordset;
	pRecordset.CreateInstance(__uuidof(Recordset));
	strSQL.Format(_T("select * from Draw_Obj where MapName = '%s' and Obj_Class = %d"), strMapName, nClass);
	try
	{
		m_pRecordset->Open((_bstr_t)strSQL, m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
		// 查找记录数量
		int nRows = 0;
		nRows = (int)m_pRecordset->GetRecordCount();
		if (nRows == -1)
		{
			if (m_pRecordset->adoEOF != VARIANT_TRUE)
			{
				m_pRecordset->MoveFirst();
			}
			while(m_pRecordset->adoEOF != VARIANT_TRUE)
			{
				nRows++;
				m_pRecordset->MoveNext();
			}
			if (nRows>0)
			{
				m_pRecordset->MoveFirst();
			}
		}
		if (nRows<=0)
		{
			return;
		}
		for (int i=0; i!=nRows; ++i)
		{
			BYTE r,g,b;
			DWORD dwID;
			dwID = (DWORD)m_pRecordset->GetFields()->GetItem("Obj_ID")->Value;
			r    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_R")->Value;
			g    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_G")->Value;
			b    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_B")->Value;

			CString strSQL2;
			strSQL2.Format(_T("select * from Draw_Point where MapName = '%s' and Obj_ID = %d order by Flag asc"),strMapName,dwID);
			pRecordset->Open((_bstr_t)strSQL2, m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
			int nRID = 0;
			nRID = (int)pRecordset->GetRecordCount();
			if (nRID == -1)
			{
				if (pRecordset->adoEOF != VARIANT_TRUE)
				{
					pRecordset->MoveFirst();
				}
				while(pRecordset->adoEOF != VARIANT_TRUE)
				{
					nRID++;
					pRecordset->MoveNext();
				}
				if (nRID>0)
				{
					pRecordset->MoveFirst();
				}
			}
			if (nRID > 1)
			{
				pRecordset->MoveFirst();
				CArray<CPoint,CPoint&> arPt;
				arPt.RemoveAll();
				int nC = 0;
				while(!pRecordset->adoEOF)
				{
					int x,y;
					x = (int)pRecordset->GetFields()->GetItem("Obj_X")->Value;
					y = (int)pRecordset->GetFields()->GetItem("Obj_Y")->Value;
					arPt.Add(CPoint(x,y));
					nC++;
					pRecordset->MoveNext();
				}
				pRecordset->Close();
				if (nC == 3)
				{
					C2DTriangle* pObj = new C2DTriangle(arPt);
					pObj->SetID(dwID);
					pObj->SetColor(r,g,b);
					CString strSQL3;
					strSQL3.Format(_T("select * from Draw_Line where MapName = '%s' and Obj_ID = %d"),strMapName,dwID);				
					pRecordset->Open((_bstr_t)strSQL3,m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
					int nCou = 0;
					nCou = (int)pRecordset->GetRecordCount();
					if (nCou == -1)
					{
						if (pRecordset->adoEOF != VARIANT_TRUE)
						{
							pRecordset->MoveFirst();
						}
						while(pRecordset->adoEOF != VARIANT_TRUE)
						{
							nCou++;
							pRecordset->MoveNext();
						}
						if (nCou>0)
						{
							pRecordset->MoveFirst();
						}
					}
					if (nCou == 1)
					{
						BYTE byLineStyle;
						UINT LineWidth;
						byLineStyle = (BYTE)pRecordset->GetCollect("LineStyle");
						LineWidth   = (UINT)pRecordset->GetCollect("LineWidth");
						pObj->m_byLineStyle = byLineStyle;
						pObj->m_wLineWidth = LineWidth;
					}
					arTIN.Add(pObj);
				}
			}
			pRecordset->Close();
			m_pRecordset->MoveNext();
		}
		m_pRecordset->Close();
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());			
	}
}

void CDBOperate::SaveC2DCurve( CArray<C2DCurve*,C2DCurve*>& arCV, CString strMapName )
{
	int nCount = (int)arCV.GetCount();
	if (nCount == 0)
	{
		return;
	}
	try
	{
		for (int i=0; i!=nCount; ++i)
		{
			C2DCurve* pObj = arCV.GetAt(i);
			int nFlag = 0;
			DWORD dwID = pObj->GetID();
			BYTE r,g,b;
			int nClass = 4;
			pObj->GetColor(r,g,b);
			CString strS;
			strS.Format(_T("insert into Draw_Obj (MapName,Obj_ID,Obj_R,Obj_G,Obj_B,Obj_Class) values(\'%s\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\')")
				,strMapName,dwID,r,g,b,nClass);
			m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			BYTE byLineStyle;
			UINT LineWidth;
			byLineStyle = pObj->m_byLineStyle;
			LineWidth   = pObj->m_wLineWidth;
			strS.Format(_T("insert into Draw_Line (MapName,Obj_ID,LineStyle,LineWidth) values(\'%s\',\'%d\',\'%d\',\'%d\')")
				,strMapName,dwID,byLineStyle,LineWidth);
			m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			int nCou = pObj->GetCount();
			for (int i=0; i!=nCou; ++i)
			{
				int x,y;
				pObj->GetPoint(i,x,y);
				strS.Format(_T("insert into Draw_Point (MapName,Obj_ID,Flag,Obj_X,Obj_Y) values(\'%s\',\'%d\',\'%d\',\'%d\',\'%d\')")
					,strMapName,dwID,nFlag++,x,y);
				m_pConnection->Execute((_bstr_t)strS,NULL,adCmdText);
			}
			++m_nCount;
		}
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());
	}
}

void CDBOperate::ReadC2DCurve( CArray<C2DCurve*,C2DCurve*>& arCV, CString strMapName )
{
	arCV.RemoveAll();
	CString strSQL;
	DWORD nClass = 4;
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	_RecordsetPtr pRecordset;
	pRecordset.CreateInstance(__uuidof(Recordset));
	strSQL.Format(_T("select * from Draw_Obj where MapName = '%s' and Obj_Class = %d"), strMapName, nClass);
	try
	{
		m_pRecordset->Open((_bstr_t)strSQL, m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
		// 查找记录数量
		int nRows = 0;
		nRows = (int)m_pRecordset->GetRecordCount();
		if (nRows == -1)
		{
			if (m_pRecordset->adoEOF != VARIANT_TRUE)
			{
				m_pRecordset->MoveFirst();
			}
			while(m_pRecordset->adoEOF != VARIANT_TRUE)
			{
				nRows++;
				m_pRecordset->MoveNext();
			}
			if (nRows>0)
			{
				m_pRecordset->MoveFirst();
			}
		}
		if (nRows<=0)
		{
			return;
		}
		for (int i=0; i!=nRows; ++i)
		{
			BYTE r,g,b;
			DWORD dwID;
			dwID = (DWORD)m_pRecordset->GetFields()->GetItem("Obj_ID")->Value;
			r    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_R")->Value;
			g    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_G")->Value;
			b    = (BYTE)m_pRecordset->GetFields()->GetItem("Obj_B")->Value;

			CString strSQL2;
			strSQL2.Format(_T("select * from Draw_Point where MapName = '%s' and Obj_ID = %d order by Flag asc"),strMapName,dwID);
			pRecordset->Open((_bstr_t)strSQL2, m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
			int nRID = 0;
			nRID = (int)pRecordset->GetRecordCount();
			if (nRID == -1)
			{
				if (pRecordset->adoEOF != VARIANT_TRUE)
				{
					pRecordset->MoveFirst();
				}
				while(pRecordset->adoEOF != VARIANT_TRUE)
				{
					nRID++;
					pRecordset->MoveNext();
				}
				if (nRID>0)
				{
					pRecordset->MoveFirst();
				}
			}
			if (nRID > 1)
			{
				pRecordset->MoveFirst();
				CArray<CPoint,CPoint&> arPt;
				arPt.RemoveAll();
				while(!pRecordset->adoEOF)
				{
					int x,y;
					x = (int)pRecordset->GetFields()->GetItem("Obj_X")->Value;
					y = (int)pRecordset->GetFields()->GetItem("Obj_Y")->Value;
					arPt.Add(CPoint(x,y));
					pRecordset->MoveNext();
				}
				pRecordset->Close();
				CString strSQL3;
				strSQL3.Format(_T("select * from Draw_Line where MapName = '%s' and Obj_ID = %d"),strMapName,dwID);			
				pRecordset->Open((_bstr_t)strSQL3,m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
				int nCou = 0;
				nCou = (int)pRecordset->GetRecordCount();
				if (nCou == -1)
				{
					if (pRecordset->adoEOF != VARIANT_TRUE)
					{
						pRecordset->MoveFirst();
					}
					while(pRecordset->adoEOF != VARIANT_TRUE)
					{
						nCou++;
						pRecordset->MoveNext();
					}
					if (nCou>0)
					{
						pRecordset->MoveFirst();
					}
				}
				C2DCurve* pObj = new C2DCurve(arPt,CURVE_BEZIER);
				pObj->SetID(dwID);
				pObj->SetColor(r,g,b);
				if (nCou == 1)
				{
					BYTE byLineStyle;
					UINT LineWidth;
					byLineStyle = (BYTE)pRecordset->GetCollect("LineStyle");
					LineWidth   = (UINT)pRecordset->GetCollect("LineWidth");
					pObj->m_byLineStyle = byLineStyle;
					pObj->m_wLineWidth = LineWidth;
				}
				arCV.Add(pObj);
			}
			pRecordset->Close();
			m_pRecordset->MoveNext();
		}
		m_pRecordset->Close();
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());			
	}
}

BOOL CDBOperate::DeleteMap( CString strMapName )
{
	try
	{
		CString strSQL;
		strSQL.Format(_T("delete * from Draw_Map where MapName = '%s'"),strMapName);
		m_pConnection->Execute((_bstr_t)strSQL,NULL,adCmdText);
		strSQL.Format(_T("delete * from Draw_Obj where MapName = '%s'"),strMapName);
		m_pConnection->Execute((_bstr_t)strSQL,NULL,adCmdText);
		strSQL.Format(_T("delete * from Draw_Point where MapName = '%s'"),strMapName);
		m_pConnection->Execute((_bstr_t)strSQL,NULL,adCmdText);
		strSQL.Format(_T("delete * from Draw_Line where MapName = '%s'"),strMapName);
		m_pConnection->Execute((_bstr_t)strSQL,NULL,adCmdText);
		strSQL.Format(_T("delete * from Draw_CurveType where MapName = '%s'"),strMapName);
		m_pConnection->Execute((_bstr_t)strSQL,NULL,adCmdText);
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());
		return FALSE;
	}
	return TRUE;
}

void CDBOperate::GetMapName( CStringArray& arMapName,CStringArray& arTime )
{
	arMapName.RemoveAll();
	arTime.RemoveAll();
	CString strSQL = _T("select * from Draw_Map");
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	try
	{
		m_pRecordset->Open((_bstr_t)strSQL,m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
		while(!(m_pRecordset->adoEOF))
		{
			CString strTable,strTime;
			COleDateTime time;
			strTable = (CString)m_pRecordset->GetCollect("MapName");
            time     = (COleDateTime)m_pRecordset->GetCollect("Time");
            strTime  = time.Format();
			arMapName.Add(strTable);
			arTime.Add(strTime);
			m_pRecordset->MoveNext();
		}
		m_pRecordset->PutSort(_T(""));
		m_pRecordset->Close();
	}
	catch(_com_error e)
	{
		AfxMessageBox(e.Description());
	}
}
