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

📄 syncview.cpp

📁 windows ce开发技巧与实例光盘代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:

		
	COleDateTime dtToday = COleDateTime::GetCurrentTime();
	COleDateTime dtTodayEnd = COleDateTime(
										dtToday.GetYear(), 
										dtToday.GetMonth(),
										dtToday.GetDay(),
										23,
										59,
										59);		//今天结束
	COleDateTime dtDayofTheMonth = COleDateTime(
										dtToday.GetYear(), 
										dtToday.GetMonth(),
										1,
										0,
										0,
										1);		//月初		
	COleDateTime dtTomorrow = COleDateTime(dtToday);
	COleDateTime dtNext7Day = COleDateTime(dtToday);

	dtTomorrow += 1;	//计算下一天
	dtNext7Day += 7;	//7天以后

	if (pThis->m_bRenew)
	{
/*
		UpdateMsg(hWndMsg, L"正在生成customer...");
		strLocalTable = L"SELECT * from CUSTOMER";
		strSQL.Format(L"");
		
		
		if (FAILED(pCERDA->CERDA->Pull(
			_bstr_t(strLocalTable), 
			_bstr_t(strSQL), 
			_bstr_t(strRemoteConn), 
			TRACKINGOFF, 
			_bstr_t(strErrorTable))))
		{
			UpdateMsg(hWndMsg, L"customer失败");
			bAllSuccess = FALSE;
		}	

*/

		UpdateMsg(hWndMsg, L"正在生成data_dictionary...");
		strLocalTable = L"data_dictionary";
		strSQL.Format(L"SELECT * from data_dictionary");
		
		
		if (FAILED(pCERDA->CERDA->Pull(
			_bstr_t(strLocalTable), 
			_bstr_t(strSQL), 
			_bstr_t(strRemoteConn), 
			TRACKINGOFF, 
			_bstr_t(strErrorTable))))
		{
			UpdateMsg(hWndMsg, L"data_dictionary失败");
			bAllSuccess = FALSE;
		}	

		UpdateMsg(hWndMsg, L"正在生成table1...");
		strLocalTable = L"table1";

	strSQL.Format(L"SELECT * from table1 WHERE user_id = %d \
		and call_date>=DATEADD(weekday, 1-(datepart(weekday,getdate())), getdate()) \
		and call_date<=DATEADD(weekday, 7-(datepart(weekday,getdate())), getdate())", nUser_ID);

		
		if (FAILED(pCERDA->CERDA->Pull(
			_bstr_t(strLocalTable), 
			_bstr_t(strSQL), 
			_bstr_t(strRemoteConn), 
			TRACKINGOFF, 
			_bstr_t(strErrorTable))))
		{
			UpdateMsg(hWndMsg, L"table1失败");
			bAllSuccess = FALSE;
		}
		

		UpdateMsg(hWndMsg, L"正在生成table2...");
		strLocalTable = L"table2";

	strSQL.Format(L"SELECT * from table2 WHERE (ACTIVITY_ID IN (SELECT ACTIVITY_ID FROM table1 WHERE user_id = %d \
				and call_date>=DATEADD(weekday, 1-(datepart(weekday,getdate())), getdate()) \
		and call_date<=DATEADD(weekday, 7-(datepart(weekday,getdate())), getdate())))", nUser_ID);
		
		if (FAILED(pCERDA->CERDA->Pull(
			_bstr_t(strLocalTable), 
			_bstr_t(strSQL), 
			_bstr_t(strRemoteConn), 
			TRACKINGOFF, 
			_bstr_t(strErrorTable))))
		{
			UpdateMsg(hWndMsg, L"table2失败");
			bAllSuccess = FALSE;
		}

		//对于不下载只上传的数据,可如下处理,令下载条件为1=0
		UpdateMsg(hWndMsg, L"正在生成table4...");
		strLocalTable = L"table4";
		strErrorTable = L"table4errortable";
		
		strSQL.Format(L"SELECT * from table4 ");
		
		if (FAILED(pCERDA->CERDA->Pull(
			_bstr_t(strLocalTable), 
			_bstr_t(strSQL), 
			_bstr_t(strRemoteConn), 
			TRACKINGON, 
			_bstr_t(strErrorTable))))
		{
			UpdateMsg(hWndMsg, L"table4失败");
			bAllSuccess = FALSE;
		}

		
		UpdateMsg(hWndMsg, L"正在生成table3...");
		strLocalTable = L"table3";
		strErrorTable = L"table3errortable";
		

		strSQL.Format(L"SELECT * from table3 WHERE 1=0");
		
		if (FAILED(pCERDA->CERDA->Pull(
			_bstr_t(strLocalTable), 
			_bstr_t(strSQL), 
			_bstr_t(strRemoteConn), 
			TRACKINGON, 
			_bstr_t(strErrorTable))))
		{
			UpdateMsg(hWndMsg, L"table3失败");
			bAllSuccess = FALSE;
		}		



		

	dtNow = COleDateTime::GetCurrentTime();

	UpdateMsg(hWndMsg, L"正在清除在线状态...");
	strSQL.Format(L"UPDATE UserOnline SET end_time = '%s' WHERE uo_code = '%s'", CCommon::getFormatDateTime(dtNow, TRUE), strUOCode);

	if (FAILED(pCERDA->CERDA->SubmitSQL(
			_bstr_t(strSQL),
			_bstr_t(strRemoteConn))
			))			
	{
		UpdateMsg(hWndMsg, L"清除用户状态失败,请检查服务器数据表");
		hWndSync->EnableWindow(TRUE);
		hWndReturn->EnableWindow(TRUE);
		hWndAdvance->EnableWindow(TRUE);
		//return;
	}

	delete pCERDA;
//pull结束



	BackUp(pThis, FALSE);

	UpdateMsg(hWndMsg, L"正在记录本次登录用户信息...");
//写用户名
	CString strSection       = L"User";
	CString strStringItem    = L"UserName";
	
	pTheApp->WriteProfileString(strSection, strStringItem, CUser::m_pUser_Name);

	UpdateMsg(hWndMsg, L"正在记录本次同步时间...");
//写同步时间
	strSection       = L"Time";
	strStringItem    = L"LastSyncTime";
	pTheApp->WriteProfileString(strSection, strStringItem, CCommon::getFormatDateTime(COleDateTime::GetCurrentTime(), TRUE));


//重新连接	
	UpdateMsg(hWndMsg, L"正在重新启动数据库...");

	if ((pTheApp->m_pADOConn != NULL) && (pTheApp->m_pADORs != NULL)) {
		AdoNS::_ConnectionPtr pConnection = pTheApp->m_pADOConn->OpenDB(_T("\\palmheart.sdf"));
		
		if ((pConnection != NULL) && 
			(pTheApp->m_pADORs->PutConnection(pConnection)) ) 
		{

			hWndSync->EnableWindow(TRUE);
			hWndReturn->EnableWindow(TRUE);
			hWndAdvance->EnableWindow(TRUE);

			if (bAllSuccess)
			{
				::PostMessage(AfxGetMainWnd()->m_hWnd,WM_USER_COMMAND, CMainFrame.LoginForm, 0);	
			}
			else
			{
				UpdateMsg(hWndMsg, L"下载过程中发生错误,请重新下载");
				DeleteFile(L"\\palmheart.sdf");
			}			
			return;			
		}
	}
	
}
}





int CSyncView::Restore(CSyncView *pThis, BOOL bPrompted)
{
	CStorageCard p;	
	POSITION pos = p.s_listStorageName.GetHeadPosition();	
	CString strPath, strMSG;

	CEdit* hWndMsg = (CEdit*)pThis->GetDlgItem(IDC_EDIT_MSG);
	
	if (p.s_listStorageName.GetCount() > 0)
	{
		strPath = p.s_listStorageName.GetNext(pos);		
		strPath += L"\\palmheart.sdf";

		if (!SearchDB(strPath))
		{
			hWndMsg->GetWindowText(strMSG);
			strMSG += L"\r\n";
			strMSG += L"存储卡上没有备份数据";
			hWndMsg->SetWindowText(strMSG);
			hWndMsg->LineScroll (hWndMsg->GetLineCount(), 0);
			return Cnemb::backuprestoreSrcNotExisted;
		}

		if (bPrompted)
		{
			if (AfxMessageBox(L"是否从存储卡上恢复备份数据?", MB_YESNO | MB_ICONQUESTION) == IDYES)
			{				
				hWndMsg->GetWindowText(strMSG);
				strMSG += L"\r\n";
				strMSG += L"正在恢复数据库...";
				hWndMsg->SetWindowText(strMSG);
				hWndMsg->LineScroll (hWndMsg->GetLineCount(), 0);
				BOOL bReturn = CopyFile(strPath, L"\\palmheart.sdf", FALSE);
				if (!bReturn)	//copy and overwrite
				{
					hWndMsg->GetWindowText(strMSG);
					strMSG += L"\r\n";
					strMSG += L"恢复数据失败";
					hWndMsg->SetWindowText(strMSG);
					hWndMsg->LineScroll (hWndMsg->GetLineCount(), 0);
					return Cnemb::backuprestoreCopyFailed;
				}	
				else
				{
					hWndMsg->GetWindowText(strMSG);
					strMSG += L"\r\n";
					strMSG += L"恢复数据成功";
					hWndMsg->SetWindowText(strMSG);
					hWndMsg->LineScroll (hWndMsg->GetLineCount(), 0);					
					return Cnemb::backuprestoreSuccess;
				}				
			}
			return Cnemb::backuprestoreUserAbort;
		}
		else
		{
			hWndMsg->GetWindowText(strMSG);
			strMSG += L"\r\n";
			strMSG += L"正在恢复数据...";
			hWndMsg->SetWindowText(strMSG);
			hWndMsg->LineScroll (hWndMsg->GetLineCount(), 0);								
			BOOL bReturn = CopyFile(L"\\palmheart.sdf", strPath, FALSE);
			if (bReturn)
			{
				hWndMsg->GetWindowText(strMSG);
				strMSG += L"\r\n";
				strMSG += L"恢复数据成功";
				hWndMsg->SetWindowText(strMSG);
				hWndMsg->LineScroll (hWndMsg->GetLineCount(), 0);					
				return Cnemb::backuprestoreSuccess;
			}				
			else
			{
				hWndMsg->GetWindowText(strMSG);
				strMSG += L"\r\n";
				strMSG += L"恢复数据失败";
				hWndMsg->SetWindowText(strMSG);
				hWndMsg->LineScroll (hWndMsg->GetLineCount(), 0);					
				return Cnemb::backuprestoreCopyFailed;
			}
		}
	}		
	return Cnemb::backuprestoreHasNoCard;	
}

void CSyncView::UpdateMsg(CEdit *hWndEdit, CString strMsg)
{
	CString strText;
	hWndEdit->SetRedraw(FALSE);
	hWndEdit->GetWindowText(strText);
	strText += L"\r\n";
	strText += strMsg;
	hWndEdit->SetWindowText(strText);
	hWndEdit->LineScroll (hWndEdit->GetLineCount(), 0);		
	hWndEdit->SetRedraw(TRUE);
}

void CSyncView::OnButtonAdvance() 
{
	// TODO: Add your control notification handler code here
	CAdminPasswordDlg dlg;
	dlg.DoModal();
}

BOOL CSyncView::SearchDB(CString strDBPathName)
{
	WIN32_FIND_DATA fd;	
	return (::FindFirstFile(strDBPathName, &fd) != INVALID_HANDLE_VALUE);
}

int CSyncView::BackUp(CSyncView *pThis, BOOL bPrompted)
{
	CStorageCard p;	
	POSITION pos = p.s_listStorageName.GetHeadPosition();	
	CString strPath, strMSG;
	CEdit* hWndMsg = (CEdit*)pThis->GetDlgItem(IDC_EDIT_MSG);
	
	if (p.s_listStorageName.GetCount() > 0)
	{
		strPath = p.s_listStorageName.GetNext(pos);		
		strPath += L"\\palmheart.sdf";
		
		if (bPrompted)
		{
			if (AfxMessageBox(L"是否将本地数据备份?", MB_YESNO | MB_ICONQUESTION) == IDYES)
			{				
				hWndMsg->GetWindowText(strMSG);
				strMSG += L"\r\n";
				strMSG += L"正在备份数据库...";
				hWndMsg->SetWindowText(strMSG);
				hWndMsg->LineScroll (hWndMsg->GetLineCount(), 0);

				BOOL bReturn = CopyFile(L"\\palmheart.sdf", strPath, FALSE);
				if (!bReturn)	//copy and overwrite
				{
					hWndMsg->GetWindowText(strMSG);
					strMSG += L"\r\n";
					strMSG += L"备份数据失败";
					hWndMsg->SetWindowText(strMSG);
					hWndMsg->LineScroll (hWndMsg->GetLineCount(), 0);
					return Cnemb::backuprestoreCopyFailed;
				}			
				else
				{
					hWndMsg->GetWindowText(strMSG);
					strMSG += L"\r\n";
					strMSG += L"备份数据成功";
					hWndMsg->SetWindowText(strMSG);
					hWndMsg->LineScroll (hWndMsg->GetLineCount(), 0);				
					return Cnemb::backuprestoreSuccess;					
				}				
			}				
			return Cnemb::backuprestoreUserAbort;
		}
		else
		{
			hWndMsg->GetWindowText(strMSG);
			strMSG += L"\r\n";
			strMSG += L"正在备份数据库...";
			hWndMsg->SetWindowText(strMSG);
			hWndMsg->LineScroll (hWndMsg->GetLineCount(), 0);
			if (CopyFile(L"\\palmheart.sdf", strPath, FALSE))
			{
				hWndMsg->GetWindowText(strMSG);
				strMSG += L"\r\n";
				strMSG += L"备份数据成功";
				hWndMsg->SetWindowText(strMSG);
				hWndMsg->LineScroll (hWndMsg->GetLineCount(), 0);				
				return Cnemb::backuprestoreSuccess;
			}
			else
			{
				hWndMsg->GetWindowText(strMSG);
				strMSG += L"\r\n";
				strMSG += L"备份数据失败";
				hWndMsg->SetWindowText(strMSG);
				hWndMsg->LineScroll (hWndMsg->GetLineCount(), 0);
				return Cnemb::backuprestoreCopyFailed;
			}
		}
	}		
	return Cnemb::backuprestoreHasNoCard;
}



void CSyncView::OnBtnReturn() 
{
	// TODO: Add your control notification handler code here
	CSQLCEDemoApp* pTheApp = (CSQLCEDemoApp*)AfxGetApp();
	
	if (m_bEnableExit)
	{
		if ((pTheApp->m_pADOConn != NULL) && (pTheApp->m_pADORs != NULL)) 
		{
			AdoNS::_ConnectionPtr pConnection = pTheApp->m_pADOConn->OpenDB(_T("\\palmheart.sdf"));
		
			if ((pConnection != NULL) && 
				(pTheApp->m_pADORs->PutConnection(pConnection)))
			{
				::PostMessage(AfxGetMainWnd()->m_hWnd,WM_USER_COMMAND, CMainFrame.MainForm, 0);	
				return;
			}
		}				
	}
	//第一次登录或者没有数据库的时候,不允许返回上一界面,而是直接退出
	if (AfxMessageBox(L"确定退出吗?", MB_YESNO | MB_ICONQUESTION) == IDYES)
	{
		CSQLCEDemoApp* pTheApp = (CSQLCEDemoApp*)AfxGetApp();
		if (pTheApp->m_pADORs->IsOpened()) 
			pTheApp->m_pADORs->Close();		
		if (pTheApp->m_pADOConn->IsConnected())
			pTheApp->m_pADOConn->Close();	
		::PostQuitMessage(0);
	}
	
}

⌨️ 快捷键说明

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