在录入form的shown()事件里
1连接数据库,
2取出数据,
3赋值给文本框,
4设置文本框的readonly=true;
将这个登录表文件,用一条链表来管理,实现功能:
bool chk_people(string id)
bool chk_people(string id,string pwd)
bool add_people(string id,string pwd)
bool del_people(string id)
bool read_file(string filename)
bool write_file(string filename)
链表中的数据可以手动添加几个,也可以从文件读入,总之先初始化链表,然后让用户 *** 作。
每一次将用户的 *** 作都先保存在链表里,在用户退出时就把链表中的数据全部写入到外部文件,将文件覆盖就行了,以后读入时就是新的内容了。
答应过你,把源码贴上来,调试运行过,得到预期结果
#include <iostream>
#include <fstream>
#include <string>
using namespace std
struct guest{
string id
string pwd
guest(string i,string p):id(i),pwd(p){next = NULL}
guest* next
}
class guest_mgr{
private:
guest* head
public:
guest_mgr()
bool chk_people(string id)
bool chk_people(string id,string pwd)
bool add_people(string id,string pwd)
bool del_people(string id)
bool read_file(string filename)
bool write_file(string filename)
void print_people()
~guest_mgr()
}
guest_mgr::guest_mgr(){
head = new guest("admin","123")
head->next = NULL
}
bool guest_mgr::read_file(string filename){
ifstream inobj(filename.c_str())
if(!inobj){
cout<<"open file failed.\n"
return false
}
guest *t,*p
string sid,spwd
p = head
while(!inobj.eof()){
inobj>>sid>>spwd
t = new guest(sid,spwd)
p->next = t
p = t
}
t->next = NULL
return true
}
bool guest_mgr::write_file(string filename){
ofstream outobj(filename.c_str())
if(!outobj){
cout<<"file open failed."
return false
}
guest* p = head
while(NULL!=p){
outobj<<p->id<<" "<<p->pwd<<"\n"
p=p->next
}
return true
}
bool guest_mgr::add_people(string id,string pwd){
if(NULL==head)
return false
guest* p = head
while(NULL!=p->next){
p = p->next
}
guest* newguest = new guest(id,pwd)
p->next = newguest
newguest->next = NULL
return true
}
bool guest_mgr::chk_people(string id){
if(NULL==head)
return false
guest *p = head
while(NULL!=p->next&&id!=p->id){
p = p->next
}
if(NULL!=p->next){
return true
}
else if(NULL==p->next&&id==p->id)
return true
return false
}
bool guest_mgr::chk_people(string id,string pwd){
if(NULL==head)
return false
guest *p = head
while(NULL!=p->next&&id!=p->id){
p = p->next
}
if(NULL!=p->next){
if(pwd==p->pwd)
return true
}
else if(NULL==p->next&&id==p->id)
if(pwd==p->pwd)
return true
return false
}
bool guest_mgr::del_people(string id){
if(chk_people(id)){
guest *p = head
guest *pre = p
while(NULL!=p->next&&id!=p->id){
pre = p
p = p->next
}
if(NULL!=p->next){
pre->next = p->next
delete p
return true
}
else if(NULL==p->next&&id==p->id){
if(p!=head){
pre->next = NULL
delete p
return true
}
}
}
return false
}
void guest_mgr::print_people(){
if(NULL==head){
cout<<"no guest in the list.\n"
return
}
guest* p = head
while(NULL!=p){
cout<<p->id<<" "<<p->pwd<<"\n"
p=p->next
}
cout<<endl
}
///////////////////////////////菜单//////////////////////////////
guest_mgr* mylist//在菜单函数中要用到,不要移动它
string fn = "data.txt"//同上
void login(){
cout<<"\n-------------------Login----------------------\n"
string id,pwd
cout<<"ID:"
cin>>id
if(mylist->chk_people(id)){
cout<<"\nPassword:"
cin>>pwd
if(mylist->chk_people(id,pwd)){
cout<<"\nlogin successful.\n"
}
else{
cout<<"sorry,your password is wrong.\n"
}
}
else{
cout<<"the id is not exsit.\n"
}
cout<<"\n-------------------Login----------------------\n"
}
void add(){
cout<<"\n-------------------Add Guest----------------------\n"
string id,pwd
cout<<"ID:"
cin>>id
cout<<"\nPassword:"
cin>>pwd
if(mylist->add_people(id,pwd)){
cout<<"\nadd guest successful.\n"
}
else{
cout<<"sorry,the system is wrong.\n"
}
cout<<"\n-------------------Add Guest----------------------\n"
}
void del(){
cout<<"\n-----------------Delete Guest--------------------\n"
string id
cout<<"ID:"
cin>>id
if(mylist->chk_people(id)){
char c
cout<<"\nare you sure to delete the guest with ID "<<id<<" .(Y/N)"<<endl
cin>>c
if(c=='y'||c=='Y'){
if(mylist->del_people(id))
cout<<"delete guest successful.\n"
else
cout<<"sorry,the system is wrong.\n"
}
}
else{
cout<<"\nsorry,the guest "<<id<<" is not exsit.\n"
}
cout<<"\n-----------------Delete Guest--------------------\n"
}
void menu(){
int c
cout<<"\n****************************Main Menu****************************\n"
cout<<"1.登录\t2.添加用户\t3.删除用户\t4.打印用户清单\t5.退出"
cout<<"\n****************************Main Menu****************************\n"
cin>>c
switch(c){
case 1:login()break
case 2:add()break
case 3:del()break
case 4:mylist->print_people()break
default:mylist->write_file(fn)exit(0)
}
}
void main(){
mylist = new guest_mgr()
mylist->read_file(fn)
while(1)
menu()
cout<<endl
}
如果说select * from userinfo里面有int类型的账号列(userid),string类型的密码列(userpass)。你想获取其账号和密码。\x0d\x0a你用sqldatacommand对象cmd.executeScalar()方法肯定是不行的。\x0d\x0a要用cmd.executereader()方法才行。再用read对象接收。\x0d\x0a连起来就是sqldataread read=cmd.executereader()\x0d\x0a然后if(read.Read()) \x0d\x0a{\x0d\x0a int id=convert.toint32(read["userid"]) //获取账号赋值给id。\x0d\x0astring pass=read["userpass"].tostring() //获取密码赋值给pass.\x0d\x0a}欢迎分享,转载请注明来源:内存溢出
评论列表(0条)