EventDao.cpp 2.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
#include "stdafx.h"
#include "EventDao.h"
#include "MyReader-DUI-MFC.h"
#include "EventDBHelper.h"


CEventDao::CEventDao(void)
{
	
	
}





CEventDao::~CEventDao(void)
{
}

void CEventDao::InsertOrUpdateUserInfo(CUserInfo userInfo)
{
	SYSTEMTIME curTime;
	::GetLocalTime(&curTime);
	CString updateTime;

	updateTime.Format(L"%d-%02d-%02d %02d:%02d:%02d",curTime.wYear, curTime.wMonth, curTime.wDay, curTime.wHour, curTime.wMinute, curTime.wSecond);
	CString sql;
	sql.Format(_T("replace into user_info(user_id,user_name,login_name,password,organ_name,organ_id,dept_name,grade,grade_id,user_type,image) \
	values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')"),userInfo.strUserId,userInfo.strRealName,userInfo.strLoginName,userInfo.strPassword,userInfo.strSchool,userInfo.strSchoolCode,userInfo.strDeptName,userInfo.strGrade,userInfo.strGradeId,userInfo.strType,userInfo.strHeadImage);

	CDataTable dt;
	pSqliteHelper->ExecuteNonQuery(sql);
}
CString CEventDao::GetTimeStamp(void)  
{  

	SYSTEMTIME tmSys;
	GetLocalTime(&tmSys);
	CTime tm3(tmSys);
	__int64 tmDst = __int64(tm3.GetTime())*1000 + tmSys.wMilliseconds;
	tmDst= tmDst+600000;
	CString strSignExp=L"",strSign=L"";
	strSignExp.Format(L"%lld",tmDst);

	return strSignExp;  
}
void CEventDao::AddEventLog(CString strData)
{
	//strData.Replace(_T("\\"),_T("\\\\"));
	CString sql;
	sql.Format(_T("insert into Log(id,text,isSend,isTestMode) \
				  values('%s','%s',%d,%d)"),GetTimeStamp(),strData,0,theApp.m_bTestMode);

	CDataTable dt;
	pSqliteHelper->ExecuteNonQuery(sql);
}

void CEventDao::LoadEventLogForSend(std::vector<Log_Data>& Logdata)
{
	

	CString sql;
	sql.Format(L"select * from Log where isSend=0 and isTestMode=%d limit 0,50",theApp.m_bTestMode);
	CFunction fun;
	CDataTable dt;
	pSqliteHelper->ExecuteQueryTable(sql, dt);
	
	if (dt.Rows.Count>0)
	{
		for (int i = 0; i<dt.Rows.Count; i++)
		{
			Log_Data data;
			data.id = dt.Rows[i][0];
			data.strData = dt.Rows[i][1];
			data.bSend = _ttoi(dt.Rows[i][2]);
			//data.strData=fun.UnicodeToUTF8(data.strData);
			Logdata.push_back(data);
		}

	}
}

bool CEventDao::Lock()
{
	return(m_lock.Lock());
}

bool CEventDao::UnLock()
{
	return(m_lock.Unlock());
}

void CEventDao::UpdateStatus( CString id )
{
	CString sql;
	//sql.Format(_T("update Log set isSend=1 where id='%s'"),id);
	sql.Format(_T("delete from Log where id='%s'"),id);
	CDataTable dt;
	pSqliteHelper->ExecuteNonQuery(sql);
}