#include "stdafx.h"
#include <iostream>
#include "windows.h"
#include "allclass.h"
#pragma comment(lib,"Shlwapi.lib")
#include <String>
#include <stdio.h>
using namespace std;
void ConnectionDB::OpenDB(){
if(S_OK!=CoInitialize(NULL)) {
MessageBox(NULL,TEXT("初始化COM库错误!"),TEXT("初始化COM库错误!"),0);
}
HRESULT hr;
try
{
hr=m_pConnection.CreateInstance("ADODB.Connection"); //创建Connection对象
if(SUCCEEDED(hr))
{
m_pConnection->Open("Provider=SQLOLEDB;Server=(LOCAL);Database=yc;User ID=sa;pwd=NULL;Integrated Security=SSPI","","",adModeUnknown); //DSN=OBDC数据源;Provider=MSDASQL
m_pRecordset.CreateInstance("ADODB.Recordset");
MessageBox(NULL,TEXT("连接数据库成功"),TEXT("连接数据库成功"),0);
}
}
catch(_com_error e){
printf("%s",e.ErrorMessage());
string errorMsg;
errorMsg="连接数据库失败!\r\n错误信息:%s" ;
//MessageBox(NULL,errorMsg,"宿舍管理",MB_OK);
MessageBox(NULL,TEXT("连接数据库失败!\r\n错误信息:%s"),TEXT("连接数据库失败!\r\n错误信息:%s"),0);
}
}
_RecordsetPtr ConnectionDB::ExecuteSQL(_variant_t sql)
{
cout << "test!";
m_pRecordset->Open(sql,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
MessageBox(NULL,TEXT("连接数据库成功"),TEXT("连接数据库成功"),0);
return m_pRecordset;
/*cout << " test!";
m_pRecordset->Open(sql,
m_pConnection.GetInterfacePtr(),
adOpenDynamic, adLockOptimistic, adCmdText); //WHERE STDCODE = '" + bstrStdCode+"'"),
return m_pRecordset;*/
}
void ConnectionDB::CloseDB()
{
if(m_pConnection!=NULL)
{
m_pConnection->Close();//关闭连接
m_pConnection.Release();//释放对象
}
}
void ConnectionDB::WageSelect(_RecordsetPtr m_pRecordset){
_variant_t Emp_code,Tax,ActualWage,DueWage,HouseFund,var; /*返回结果变量 _variant_t 不能直接转换成MBCS字符串。要建立一个过渡的_bstr_t 变量,用其它提供转换Unicode到MBCS的类函数,或ATL转换宏来转换。与_bstr_t 不同,_variant_t 数据可以作为参数直接传送给COM方法。_variant_t 继承了VARIANT类型,所以在需要使用VARIANT的地方使用_variant_t 是C++语言规则允许的。*/
while(!m_pRecordset->adoEOF) {
Emp_code = m_pRecordset->GetCollect(_variant_t((long)0)); //取得第1列的值,从0开始计数,你也可以直接给出列的名称,如下一行
Tax = m_pRecordset->GetCollect("Tax"); //取得姓名字段的值
ActualWage = m_pRecordset->GetCollect("ActualWage");
DueWage = m_pRecordset->GetCollect("DueWage");
HouseFund = m_pRecordset->GetCollect("HouseWage");
cout << "employeecode is ::"<<(_bstr_t)Emp_code <<" " <<"tax is ::" <<(_bstr_t)Tax << " " << "actual wage is :" <<(_bstr_t)ActualWage << " " << "due wage is :" << (_bstr_t)DueWage << " " << "housefund is :" << (_bstr_t)HouseFund <<endl;
m_pRecordset->MoveNext();
}//移到下一条记录
// m_pRecordset->MoveFirst(); //移到首条记录
// m_pRecordset->Move(1); //从第一条记录往下移动一条记录,即移动到第二条记录处
// m_pRecordset->PutCollect(_variant_t("city"),_variant_t((long)45)); //修改其年龄
//m_pRecordset->MoveLast(); //移到最后
// m_pRecordset->Update(); //保存到库中
}
void ConnectionDB::EmployeeSelect(_RecordsetPtr m_pRecordset)
{
_variant_t Emp_code,Emp_name,Phone,Department,var; /*返回结果变量 _variant_t 不能直接转换成MBCS字符串。要建立一个过渡的_bstr_t 变量,用其它提供转换Unicode到MBCS的类函数,或ATL转换宏来转换。与_bstr_t 不同,_variant_t 数据可以作为参数直接传送给COM方法。_variant_t 继承了VARIANT类型,所以在需要使用VARIANT的地方使用_variant_t 是C++语言规则允许的。*/
while(!m_pRecordset->adoEOF)
{
Emp_code = m_pRecordset->GetCollect(_variant_t((long)0)); //取得第1列的值,从0开始计数,你也可以直接给出列的名称,如下一行
Emp_name = m_pRecordset->GetCollect("Emp_name"); //取得姓名字段的值
Phone = m_pRecordset->GetCollect("Phone");
Department = m_pRecordset->GetCollect("Department");
//hire_date = m_pRecordset->GetCollect("hire_date");
cout <<"employee code is :"<<(_bstr_t)Emp_code <<" " <<"employee name is:" <<(_bstr_t)Emp_name << " " << "employee phone is :"<<(_bstr_t)Phone << " " << "department is :" << (_bstr_t)Department << endl;
m_pRecordset->MoveNext();
}//移到下一条记录
//m_pRecordset->MoveFirst(); //移到首条记录
//m_pRecordset->Delete(adAffectCurrent); //删除当前记录
/*for(int i=0;i<3;i++) //添加三条新记录并赋值
{
m_pRecordset->AddNew(); //添加新记录
m_pRecordset->PutCollect("ID",_variant_t((long)(i+10)));
m_pRecordset->PutCollect("Name",_variant_t("王斌年"));
m_pRecordset->PutCollect("Age",_variant_t((long)21));
m_pRecordset->PutCollect("Birthday",_variant_t("1930-3-15"));
} */
//m_pRecordset->Move(1); //从第一条记录往下移动一条记录,即移动到第二条记录处
//m_pRecordset->PutCollect(_variant_t("city"),_variant_t((long)45)); //修改其年龄
//m_pRecordset->MoveLast(); //移到最后
// m_pRecordset->Update(); //保存到库中
}
/*int Users::check_user()
{
ConnectionDB obj;
obj.OpenDB();
int z;
char users_code;
string users_name,password;
char sqlstr[1024];
cout<<"\t\t\t***进销存管理系统***"<<endl;
cout<<"\t\t\t 请先登录!"<<endl;
cout<<"请输入用户号:";
cin>>users_code;
cout<<"请输入用户名:";
cin>>Users_name;
cout<<"请输入用户密码:" ;
cin>>Password;
sprintf(sqlstr,"select Password,Users_name from Users where users_code='%s'",Users_code);
_RecordsetPtr x=obj.ExecuteSQL(sqlstr);
_variant_t vUsers_name,vPassword;
vUsers_name=x->GetCollect("Users_name");
vPassword=x->GetCollect("Password");
if((string)(_bstr_t)vUsers_name == users_name&&(string)(_bstr_t)vPassword== Password){
z=1;
cout<<"\t\t\t\t登录通过!";
}
else{
z=0;
cout<<"\t\t没有这个用户,请核对后再登录!";
}
obj.CloseDB();
return(z);
}*/
void Wage::insertWage()
{
cout << endl << "Please enter employee code:" << endl;
cin >> Emp_code;
cout<< "Please enter tax:" << endl;
cin >> Tax;
cout << endl << "Please enter ActualWage:" << endl;
cin >> ActualWage;
cout << endl << "Please enter DueWage:" << endl;
cin >> DueWage;
cout << endl << "Please enter HouseFund:" << endl;
cin >> HouseFund;
ConnectionDB con;
con.OpenDB();
char mystr[1024];
sprintf(mystr,"insert into Wage values(Emp_code='%s',Tax='%f',ActualWage='%f',DueWage='%f',HouseFund='%f')",Emp_code,Tax,ActualWage,DueWage,HouseFund);
cout << mystr;
con.ExecuteSQL(mystr);
con.CloseDB();
cout << endl << "插入成功" << endl;
}
void Wage::updateWage()
{
cout << endl << "Please enter employee code:" << endl;
cin >> Emp_code;
cout << endl << "Please enter tax:" << endl;
cin >> Tax;
cout << endl << "Please enter ActualWage:" << endl;
cin >> ActualWage;
cout << endl << "Please enter DueWage:" << endl;
cin >> DueWage;
cout << endl << "Please enter HouseFund:" << endl;
cin >> HouseFund;
ConnectionDB con;
char mystr[1024];
char number[5];
cout << endl << "Enter Emp_code:";
cin >> number;
sprintf(mystr,"update Wage set Emp_code='%s',Tax = '%f',ActualWage = '%f', DueWage = '%f',HouseFund = '%f', where Emp_code = '%s'",Emp_code,Tax,ActualWage,DueWage,HouseFund,number);
con.OpenDB();
con.ExecuteSQL(mystr);
没有合适的资源?快使用搜索试试~ 我知道了~
JSP+UseBean网上购书系统
共357个文件
jpg:78个
gif:70个
jsp:63个
4星 · 超过85%的资源 需积分: 9 75 下载量 14 浏览量
2008-03-03
22:41:10
上传
评论
收藏 4.56MB RAR 举报
温馨提示
这是一个我自己用JSP+USEBEAN写的系统,
资源推荐
资源详情
资源评论
收起资源包目录
JSP+UseBean网上购书系统 (357个子文件)
index_jsp.class 36KB
top_jsp.class 12KB
top1_jsp.class 11KB
center_jsp.class 10KB
foot_jsp.class 10KB
mlogin_jsp.class 9KB
BasketPage_jsp.class 8KB
ChooseJsp_jsp.class 8KB
left1_jsp.class 8KB
basket_jsp.class 8KB
left_jsp.class 8KB
BackManger_jsp.class 8KB
BookInf_jsp.class 8KB
left2_jsp.class 7KB
BookInfJsp_jsp.class 6KB
OperatManagerJsp_jsp.class 6KB
BookInfBean.class 6KB
CartChange_jsp.class 5KB
Registerbean_jsp.class 5KB
ManagerInf_jsp.class 5KB
Cart.class 5KB
BuyJudge_jsp.class 5KB
BookUpdateJsp_jsp.class 5KB
LoginJudge_jsp.class 5KB
index1_jsp.class 4KB
CartChange_jsp.class 4KB
ChoosePage_jsp.class 4KB
ManagerJsp_jsp.class 4KB
UserInf_jsp.class 4KB
SellInf_jsp.class 4KB
ChooseBean.class 4KB
InsertRegistration.class 3KB
OperatManagerInf.class 3KB
BookTypeBean.class 3KB
UserInfBean.class 3KB
ManagerBean.class 3KB
SellInfBean.class 3KB
AdminCheck.class 2KB
LoginCheck.class 2KB
Thumbs.db 189KB
Thumbs.db 178KB
Thumbs.db 147KB
2004101920857646.gif 63KB
tupic.gif 57KB
top.gif 29KB
p1.gif 25KB
0005.gif 19KB
0005.gif 19KB
dongkuaif.gif 15KB
dongkuaii.gif 14KB
1007.gif 13KB
001 (7).gif 13KB
001 (7).gif 13KB
1007.gif 13KB
top_r1_c1.gif 13KB
2003.gif 10KB
2007.gif 10KB
3003.gif 10KB
1008.gif 10KB
1002.gif 9KB
2004.gif 9KB
1001.gif 9KB
dongkuaid.gif 7KB
index.gif 5KB
biao.gif 5KB
tonew.gif 3KB
biaotou.gif 3KB
chuxiao.gif 3KB
link.gif 2KB
wutu.gif 2KB
chuxiao2.gif 2KB
wutu.gif 2KB
dongkuaih.gif 2KB
buy2.gif 2KB
top_r2_c3.gif 2KB
top_r2_c5.gif 2KB
top_r2_c7.gif 2KB
top_r2_c10.gif 2KB
top_r2_c9.gif 2KB
top_r2_c8.gif 2KB
baidu.gif 2KB
top_r2_c6.gif 1KB
top_r2_c4.gif 1KB
denglu.gif 1KB
top_r2_c2.gif 1KB
back16_005.gif 1KB
tonew3.gif 904B
buy_ico.gif 840B
login-55.gif 708B
top_r2_c1.gif 668B
tonew1.gif 576B
dongkuaig.gif 567B
lookbcar.gif 554B
login-80.gif 511B
top_r2_c11.gif 507B
login-79.gif 503B
relbcar.gif 489B
gobuy.gif 479B
buy.gif 317B
ok.gif 309B
共 357 条
- 1
- 2
- 3
- 4
资源评论
- lyking20012012-07-07基础学习的资料,不错
xierong_4568
- 粉丝: 2
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- mmqrcode1714153659780.png
- Screenshot_2024-04-27-06-08-58-486_com.baidu.xin.aiqicha.jpg
- 基于Javaweb+Tomcat+MySQL的大学生公寓管理系统+sql文件.zip
- 实训作业基于javaweb的订单管理系统源码+数据库+实训报告.zip
- 多机调度问题贪心算法基于最小堆和贪心算法求解多机调度问题.zip
- 基于同态加密技术的匿名电子投票系统源码.zip
- Pyqt5项目框架-PyQt项目开发实践
- 基于C通过MQTT的智能农业大棚管理系统(本科毕业设计)
- python+CNN的网络入侵检测算法源码.zip
- js 实现记住密码功能 js.cookie.min.js
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功