?? createdb.cpp
字號(hào):
// CreateDB.cpp: implementation of the CCreateDB class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "抄表系統(tǒng).h"
#include "CreateDB.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCreateDB::CCreateDB()
{
//wtableflag=0;
//operflag=0;
//數(shù)據(jù)庫(kù)卷變量賦值
szname=L"\\FlashDisk\\PDA抄表系統(tǒng)數(shù)據(jù)庫(kù).cdb";
dwFlags=OPEN_ALWAYS;
//
if(!OpenMountDBVol()) //裝配數(shù)據(jù)庫(kù)卷
::AfxMessageBox(L"PDA抄表系統(tǒng)數(shù)據(jù)庫(kù)文件目前無(wú)法使用!");
}
CCreateDB::~CCreateDB()
{
CloseMountDBVol();
}
//////////////////////////////////////////////////////
//創(chuàng)建或者打開(kāi)PDA售后服務(wù)系統(tǒng)數(shù)據(jù)卷
BOOL CCreateDB::OpenMountDBVol()
{
BOOL result;
result=CeMountDBVol(&pguid,szname,dwFlags); //裝配數(shù)據(jù)庫(kù)卷
return result;
}
BOOL CCreateDB::CloseMountDBVol() //卸載數(shù)據(jù)庫(kù)卷
{
BOOL result;
result=CeUnmountDBVol(&pguid);
return result;
}
///////////////////////////////////////////////////////
//設(shè)置抄表記錄參數(shù)
SORTORDERSPECEX CCreateDB::DfWtableInfo()
{
CEPROPID SortProp[3];
SortProp[0]=MAKELONG(CEVT_LPWSTR,prop_01); //按水表編號(hào)排序(升序)
SortProp[1]=MAKELONG(CEVT_LPWSTR,prop_02); //按用戶名稱排序(降序)
SortProp[2]=MAKELONG(CEVT_LPWSTR,prop_03); //按用戶地址排序(降序)
SORTORDERSPECEX SortInfo[3];
SortInfo[0].wVersion=1;
SortInfo[0].wNumProps =1;
SortInfo[0].wKeyFlags=CEDB_SORT_UNIQUE; //關(guān)鍵字的唯一
SortInfo[0].rgPropID[0]=SortProp[0];
//SortInfo[0].rgdwFlags [0]=CEDB_SORT_DESCENDING;
SortInfo[1].wVersion=1;
SortInfo[1].wNumProps =1;
//SortInfo[1].wKeyFlags=CEDB_SORT_UNIQUE;
SortInfo[1].rgPropID[0]=SortProp[1];
SortInfo[1].rgdwFlags [0]=CEDB_SORT_DESCENDING;
SortInfo[2].wVersion=1;
SortInfo[2].wNumProps =1;
//SortInfo[2].wKeyFlags=CEDB_SORT_UNIQUE; //關(guān)鍵字的唯一
SortInfo[2].rgPropID[0]=SortProp[2];
SortInfo[2].rgdwFlags [0]=CEDB_SORT_DESCENDING;
pWtableInfo.wVersion=1;
pWtableInfo.dwFlags=CEDB_VALIDCREATE;
wcscpy(pWtableInfo.szDbaseName,writetableDB);
//::AfxMessageBox (pOperInfo.szDbaseName);
pWtableInfo.dwDbaseType=writetable_ID;
pWtableInfo.wNumSortOrder=3;
pWtableInfo.rgSortSpecs[0]=SortInfo[0];
pWtableInfo.rgSortSpecs[1]=SortInfo[1];
pWtableInfo.rgSortSpecs[2]=SortInfo[2];
return SortInfo[0];
}
BOOL CCreateDB::openWriteDB1()
{
SORTORDERSPECEX SortInfo;
SortInfo.wVersion=1;
SortInfo.wNumProps =1;
//SortInfo[1].wKeyFlags=CEDB_SORT_UNIQUE;
SortInfo.rgPropID[0]=MAKELONG(CEVT_LPWSTR,prop_02);
SortInfo.rgdwFlags[0] =CEDB_SORT_DESCENDING;
writetable=0;
writetbhandle=CeOpenDatabaseEx2(&pguid,&writetable,writetableDB,&SortInfo,CEDB_AUTOINCREMENT,NULL);
if(writetbhandle==INVALID_HANDLE_VALUE)
return FALSE;
return TRUE;
}
BOOL CCreateDB::openWriteDB2()
{
SORTORDERSPECEX SortInfo;
SortInfo.wVersion=1;
SortInfo.wNumProps =1;
//SortInfo[1].wKeyFlags=CEDB_SORT_UNIQUE;
SortInfo.rgPropID[0]=MAKELONG(CEVT_LPWSTR,prop_03);
SortInfo.rgdwFlags[0] =CEDB_SORT_DESCENDING;
writetable=0;
writetbhandle=CeOpenDatabaseEx2(&pguid,&writetable,writetableDB,&SortInfo,CEDB_AUTOINCREMENT,NULL);
if(writetbhandle==INVALID_HANDLE_VALUE)
return FALSE;
return TRUE;
}
//設(shè)置抄表人員記錄參數(shù)
SORTORDERSPECEX CCreateDB::DfOperInfo()
{
SORTORDERSPECEX SortInfo[2];
SortInfo[0].wVersion=1;
SortInfo[0].wNumProps =1;
SortInfo[0].wKeyFlags=CEDB_SORT_UNIQUE; //關(guān)鍵字的唯一
SortInfo[0].rgPropID[0]=MAKELONG(CEVT_LPWSTR,prop_10);
//SortInfo[0].rgdwFlags [0]=CEDB_SORT_DESCENDING;
SortInfo[1].wVersion=1;
SortInfo[1].wNumProps =1;
//SortInfo[1].wKeyFlags=CEDB_SORT_UNIQUE; //關(guān)鍵字的唯一
SortInfo[1].rgPropID[0]=MAKELONG(CEVT_LPWSTR,prop_11);
//
pOperInfo.wVersion=1;
pOperInfo.dwFlags=CEDB_VALIDCREATE;
wcscpy(pOperInfo.szDbaseName,operatorsDB);
//::AfxMessageBox (pOperInfo.szDbaseName);
pOperInfo.dwDbaseType=operators_ID;
pOperInfo.wNumSortOrder=2;
pOperInfo.rgSortSpecs[0]=SortInfo[0];
pOperInfo.rgSortSpecs[1]=SortInfo[1];
//
return SortInfo[0];
}
BOOL CCreateDB::openOperator()
{
SORTORDERSPECEX SortInfo;
SortInfo.wVersion=1;
SortInfo.wNumProps =1;
//SortInfo[1].wKeyFlags=CEDB_SORT_UNIQUE; //關(guān)鍵字的唯一
SortInfo.rgPropID[0]=MAKELONG(CEVT_LPWSTR,prop_11);
//
operators=0;
operhandle=CeOpenDatabaseEx2(&pguid,&operators,operatorsDB,&SortInfo,CEDB_AUTOINCREMENT,NULL);
if(operhandle==INVALID_HANDLE_VALUE)
return FALSE;
return TRUE;
}
///
//創(chuàng)建抄表記錄
BOOL CCreateDB::CreateWtableDB()
{
writetable=0;
SORTORDERSPECEX WritetbInfo=DfWtableInfo();
//::AfxMessageBox(writetableDB);
writetbhandle=CeOpenDatabaseEx2(&pguid,&writetable,writetableDB,&WritetbInfo,CEDB_AUTOINCREMENT,NULL);
if(writetbhandle==INVALID_HANDLE_VALUE)
{
writetable=CeCreateDatabaseEx2(&pguid,&pWtableInfo);
if(writetable==0)
{
int error;
TCHAR text[64];
error=GetLastError();
wsprintf(text,L"writeDb CEOID.error=%d(%x)",error,error);
::AfxMessageBox(text);
return FALSE;
}
writetbhandle=CeOpenDatabaseEx2(&pguid,&writetable,NULL,&WritetbInfo,CEDB_AUTOINCREMENT,NULL);
if(writetbhandle==INVALID_HANDLE_VALUE)
{
int error;
TCHAR text[64];
error=GetLastError();
wsprintf(text,L"writeDb CEOID.error=%d(%x)",error,error);
::AfxMessageBox(text);
return FALSE;
}
}
return TRUE;
}
//
//創(chuàng)建抄表人員記錄
BOOL CCreateDB::CreateOperDB()
{
operators=0;
SORTORDERSPECEX OperatorsInfo=DfOperInfo();
CString str;
operhandle=CeOpenDatabaseEx2(&pguid,&operators,operatorsDB,&OperatorsInfo,CEDB_AUTOINCREMENT,NULL);
if(operhandle==INVALID_HANDLE_VALUE)
{
operators=CeCreateDatabaseEx2(&pguid,&pOperInfo);
if(operators==0)
{
int error;
TCHAR text[64];
error=GetLastError();
wsprintf(text,L"operDb Create.error=%d(%x)",error,error);
::AfxMessageBox(text);
return FALSE;
}
operhandle=CeOpenDatabaseEx2(&pguid,&operators,NULL,&OperatorsInfo,CEDB_AUTOINCREMENT,NULL);
if(operhandle==INVALID_HANDLE_VALUE)
{
int error;
TCHAR text[64];
error=GetLastError();
wsprintf(text,L"operDb Open.error=%d(%x)",error,error);
::AfxMessageBox(text);
return FALSE;
}
}
return TRUE;
}
//創(chuàng)建抄表管理員數(shù)據(jù)庫(kù)
BOOL CCreateDB::CreateManagerDB()
{
CEDBASEINFOEX pManagerInfo;
SORTORDERSPECEX SortInfo;
SortInfo.wVersion=1;
SortInfo.wNumProps =1;
SortInfo.wKeyFlags=CEDB_SORT_UNIQUE;
SortInfo.rgPropID[0]=MAKELONG(CEVT_LPWSTR,prop_20);
SortInfo.rgdwFlags[0] =CEDB_SORT_DESCENDING;
//
pManagerInfo.wVersion=1;
pManagerInfo.dwFlags=CEDB_VALIDCREATE;
wcscpy(pManagerInfo.szDbaseName,managerDB );
pManagerInfo.dwDbaseType=manager_ID;
pManagerInfo.wNumSortOrder=1;
pManagerInfo.rgSortSpecs[0]=SortInfo;
//
manager=0;
managerhandle=CeOpenDatabaseEx2(&pguid,&manager,managerDB,&SortInfo,CEDB_AUTOINCREMENT,NULL);
if(managerhandle==INVALID_HANDLE_VALUE)
{
manager=CeCreateDatabaseEx2(&pguid,&pManagerInfo);
if(manager==0)
{
int error;
TCHAR text[64];
error=GetLastError();
wsprintf(text,L"ManagerDb Create.error=%d(%x)",error,error);
::AfxMessageBox(text);
return FALSE;
}
managerhandle=CeOpenDatabaseEx2(&pguid,&manager,NULL,&SortInfo,CEDB_AUTOINCREMENT,NULL);
if(managerhandle==INVALID_HANDLE_VALUE)
{
int error;
TCHAR text[64];
error=GetLastError();
wsprintf(text,L"ManagerDb Open.error=%d(%x)",error,error);
::AfxMessageBox(text);
return FALSE;
}
}
return TRUE;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -