SQLserver 数据库课程设计Word下载.docx
《SQLserver 数据库课程设计Word下载.docx》由会员分享,可在线阅读,更多相关《SQLserver 数据库课程设计Word下载.docx(17页珍藏版)》请在冰豆网上搜索。
四、应用系统实现与测试
登陆界面
系统界面
文档基本信息
日志管理
文档类别
单位列表
五、部分代码
//ADO.cpp:
implementationoftheCADOclass.
//
//////////////////////////////////////////////////////////////////////
#include"
stdafx.h"
ADO.h"
#include<
comdef.h>
#ifdef_DEBUG
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#definenewDEBUG_NEW
#endif
//Construction/Destruction
intConCount=0;
CADOConnectiong_Connection;
//全局数据库连接对象
CADOConnection*GetConnection()
{
return&
g_Connection;
}
CADOConnection:
:
CADOConnection()
InitADO();
m_Connection.CreateInstance("
ADODB.Connection"
);
~CADOConnection()
if(IsOpen())
m_Connection->
Close();
m_Connection=NULL;
UnInitADO();
voidCADOConnection:
InitADO()
if(ConCount++==0)
CoInitialize(NULL);
};
UnInitADO()
if(--ConCount==0)
CoUninitialize();
BOOLCADOConnection:
Open(CStringConStr)
m_Connection->
Open((_bstr_t)ConStr,"
"
"
adModeUnknown);
returnIsOpen();
CStringCADOConnection:
GetSQLConStr(CStringIP,CStringDBName)
CStringStr;
Str.Format("
Provider=SQLOLEDB.1;
PersistSecurityInfo=False;
UserID=sa;
InitialCatalog=%s;
DataSource=%s"
DBName,IP);
returnStr;
_ConnectionPtrCADOConnection:
GetConnection()
returnm_Connection;
IsOpen()
longState;
get_State(&
State);
if(State==adStateOpen)
returntrue;
returnfalse;
////////////////////////////////////////
CADODataSet:
CADODataSet()
m_DataSet.CreateInstance("
ADODB.Recordset"
~CADODataSet()
m_DataSet->
m_DataSet=NULL;
voidCADODataSet:
SetConnection(CADOConnection*pCon)
m_Connection=pCon;
intCADODataSet:
GetRecordCount()
returnm_DataSet->
GetRecordCount();
else
return0;
BOOLCADODataSet:
Open(CStringSQLStr)
//*/
m_DataSet->
Open(_bstr_t(SQLStr),
_variant_t((IDispatch*)g_Connection.GetConnection(),true),
adOpenKeyset,adLockOptimistic,adCmdText);
FieldsPtrCADODataSet:
GetFields()
returnm_DataSet->
GetFields();
Next()
if(m_DataSet->
adoEOF)
returnfalse;
MoveNext();
returntrue;
AddNew()
AddNew();
SetFieldValue(CStringFieldName,_variant_tValue)
PutCollect((_bstr_t)FieldName,Value);
Save()
Update();
move(intnIndex)
MoveFirst();
Move(nIndex);
GetRecordNo()
AbsolutePosition;
Delete()
Delete(adAffectCurrent);
Open(CStringSQLStr,intLockType)
adOpenKeyset,(LockTypeEnum)LockType,adCmdText);
/CheckSum.cpp:
implementationfile
Person.h"
CheckSum.h"
staticcharTHIS_FILE[]=__FILE__;
/////////////////////////////////////////////////////////////////////////////
//CCheckSumdialog
CCheckSum:
CCheckSum(CWnd*pParent/*=NULL*/)
:
CDialog(CCheckSum:
IDD,pParent)
//{{AFX_DATA_INIT(CCheckSum)
m_emp=_T("
m_mm=_T("
m_yy=_T("
//}}AFX_DATA_INIT
voidCCheckSum:
DoDataExchange(CDataExchange*pDX)
CDialog:
DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCheckSum)
DDX_Control(pDX,IDC_LISTEMP,m_list);
DDX_Control(pDX,IDC_CYY,m_cyy);
DDX_Control(pDX,IDC_CMM,m_cmm);
DDX_Control(pDX,IDC_CEMP,m_cemp);
DDX_CBString(pDX,IDC_CEMP,m_emp);
DDX_CBString(pDX,IDC_CMM,m_mm);
DDX_CBString(pDX,IDC_CYY,m_yy);
//}}AFX_DATA_MAP
BEGIN_MESSAGE_MAP(CCheckSum,CDialog)
//{{AFX_MSG_MAP(CCheckSum)
ON_CBN_CLOSEUP(IDC_CEMP,OnCloseupCemp)
ON_CBN_CLOSEUP(IDC_CYY,OnCloseupCyy)
ON_CBN_CLOSEUP(IDC_CMM,OnCloseupCmm)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//CCheckSummessagehandlers
BOOLCCheckSum:
OnInitDialog()
OnInitDialog();
inti=0;
m_list.InsertColumn(i,"
人员姓名"
m_list.SetColumnWidth(i++,100);
工作总天数"
迟到总天数"
早退总天数"
病假总天数"
事假总天数"
m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
intcuryear,curmonth;
CTimetime(CTime:
GetCurrentTime());
curyear=time.GetYear();
curmonth=time.GetMonth();
charvalue[10];
for(inty=2000;
y<
2100;
y++)
{
_itoa(y,value,10);
m_cyy.InsertString(y-2000,value);
}
m_cyy.SetCurSel(curyear-2000);
for(intn=1;
n<
=12;
n++)
_itoa(n,value,10);
m_cmm.InsertString(n-1,value);
m_cmm.SetCurSel(curmonth-1);
CADODataSetdataset;
dataset.SetConnection(:
GetConnection());
dataset.Open("
Select*Fromtab_Employees"
m_cemp.InsertString(0,"
(全部)"
for(intindex=1;
index<
=dataset.GetRecordCount();
index++)
m_cemp.InsertString(index,(_bstr_t)dataset.GetFields()->
Item["
emp_name"
]->
Value);
dataset.Next();
m_cemp.SetCurSel(0);
UpdateList();
returnTRUE;
//returnTRUEunlessyousetthefocustoacontrol
//EXCEPTION:
OCXPropertyPagesshouldreturnFALSE
UpdateList()
m_list.DeleteAllItems();
this->
UpdateData();
CStringstr,temp,where,datestr,StartDate,EndDate;
StartDate=m_yy+"
-"
+m_mm+"
-1"
;
EndDate.Format("
DATEADD(month,1,'
%s'
)"
StartDate);
datestr.Format("
between'
and%s"
StartDate,EndDate);
temp+="
selectemp.emp_name,ROUND(isnull(works.workday,0),2)"
;
workday,ROUND(isnull(lates.lateday,0),2)lateday,"
ROUND(isnull(leaveearlys.leaveearlyday,0),2)leaveearlyday,"
ROUND(isnull(bjdays.bjday,0),2)bjday,ROUND(isnull(sjdays.sjday,0),2)sjday"
fromtab_Employeesemp"
leftjoin"
(selectsum(DATEDIFF(second,ontime,offtime))/60.0/60.0/8.0"
asworkday,nameFromtab_Checkwherecheckdate%sgroupbyname)"
worksonemp.emp_name=works.name"
(select(sum(DATEPART(Hour,latetime))*60*60+"
sum(DATEPART(minute,latetime))*60+sum(DATEPART(second,latetime)))"
/60.0/60.0/8.0aslateday,nameFromtab_Checkwherecheckdate"
%sgroupbyname)latesonemp.emp_name=lates.name"
(select(sum(DATEPART(Hour,leaveearly))*60*60+"
sum(DATEPART(minute,leaveearly))*60+sum(DATEPART(second,leaveearly)))"
/60.0/60.0/8.0asleaveearlyday,nameFromtab_Checkwhere"
checkdate%sgroupbyname)leaveearlysonemp.emp_name"
=leaveearlys.name"
(selectisnull(sum(DATEDIFF(second,onleave,offleave))"
/60.0/60.0/8.0,0)asbjday,nameFromtab_Checkwhere"
leave='
病假'
andcheckdate%sgroupbyname)"
bjdaysonemp.emp_name=bjdays.name"
(selectisnull(sum(DATEDIFF(second,onleave,offleave))"
/60.0/60.0/8.0,0)assjday,nameFromtab_Checkwhere"
事假'
sjdaysonemp.emp_name=sjdays.name"
%s"
//*/
//
where.Format("
whereemp.emp_name='
m_emp);
if(m_emp=="
)
str.Format(temp,datestr,datestr,datestr,datestr,datestr,"
str.Format(temp,datestr,datestr,datestr,datestr,datestr,where);
dataset.Open(str,adLockUnspecified);
for(inti=0;
i<
dataset.GetRecordCount();
i++)
intn=0;
m_list.InsertItem(i,"
m_list.SetItemText(i,n++,(_bstr_t)dataset.GetFields()->
workday"
lateday"
leaveearlyday"
bjday"
sjday"
}//*/
OnCloseupCemp()
OnCloseupCyy()
OnCloseupCmm()
六、课程设计心得体会
这次历时两周的课程设计,对于我们来说确实收获了不少。
第一天我们查找资料、了解有关的知识,相互探讨,了解文档管理系统的需求,做好需求分析后,开始系统的设计,画出E-R图,写出各个实体的属性。
对于数据库的创建,虽然出现很多的问题,