动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   .Net → 阅读文章

 自定义控件的使用例子

作者来源: 
阅读 数 166 人次 , 2006-3-29 4:33:00 


using system;
using com.joybase.db;
using com.oztime.workshop.codebase;
namespace com.oztime.workshop.codebase.db
{
/// <summary>
/// summary description for dbuser.
/// </summary>
public class dbuser:user
{
private int m_userid;
private string m_username;
private string m_password;
private sex m_usersex;
private string m_useremail;
private string m_usertitle;
public dbuser(string p_username)
{
this.m_useremail=p_username;
this.loadfromdb(0);

}
public dbuser(int p_userid)
{
this.m_userid=p_userid;
this.loadfromdb(1);
}
public dbuser(string p_username,string p_password)
{
this.m_username=p_username;
this.m_password=p_password;
this.loadfromdb(2);
}
public dbuser(string p_username,string p_password,sex p_usersex,string p_useremail,string p_usertitle)
{
this.m_password=p_password;
this.m_useremail=p_useremail;
this.m_username=p_username;
this.m_usersex=p_usersex;
this.m_usertitle=p_usertitle;
this.m_userid=this.inserintodb();
}
private int inserintodb()
{
int result=-1;
try
{
command command=new command(dbglobal.dsn);
command.commandtext=dbglobal.addnewuser;
command.parameter["username"]=this.m_username;
command.parameter["password"]=this.m_password;
command.parameter["usersex"]=(int)this.m_usersex;
command.parameter["useremail"]=this.m_useremail;
command.parameter["usertitle"]=this.m_usertitle;
command.returntype=resulttype.noresult;
command.execute();
command.commandtext=dbglobal.selectcurrentuserid;
command.returntype=resulttype.datareader;
system.data.idatareader dr=(system.data.idatareader)command.execute();
dr.read();
result=dr.getint32(0);
dr.close();
}
catch
{
throw new exception("cannot add new user");
}
return result;

}
private void loadfromdb(int p_type)
{

try
{
command command=new command(dbglobal.dsn);
switch(p_type)
{
case 0:
command.commandtext=dbglobal.selectuserbyname;
command.parameter["username"]=this.m_username;
break;
case 1:
command.commandtext=dbglobal.selectuserbyid;
command.parameter["userid"]=this.m_userid;
break;
case 2:
command.commandtext=dbglobal.selectuserbynameandpassword;
command.parameter["username"]=this.m_username;
command.parameter["password"]=this.m_password;
break;
default:
throw new exception("error invode loadfromdb() method!");
}


system.data.idatareader dr=(system.data.idatareader)command.execute();
if(dr.read())
{
this.m_password=dr["password"].tostring();
this.m_useremail=dr["useremail"].tostring();
this.m_userid=system.convert.toint32(dr["userid"].tostring());
this.m_username=dr["username"].tostring();
this.m_usersex=(sex)system.convert.toint32(dr["usersex"].tostring());
this.m_usertitle=dr["usertitle"].tostring();


}
else
{
throw new exception("error to read userinfo!");
}
dr.close();
}
catch
{
throw new exception("error when load user's info");
}
}
public int userid
{
get
{
return this.m_userid;
}
set
{
this.m_userid=value;
}
}
public string username
{
get
{
return this.m_username;
}
set
{
this.m_username=value;
}
}
public string password
{
get
{
return this.m_password;
}
set
{
this.m_password=value;
}
}
public sex usersex
{
get
{
return this.m_usersex;
}
set
{
this.m_usersex=value;
}
}
public string useremail
{
get
{
return this.m_useremail;
}
set
{
this.m_useremail=value;
}
}
public string usertitle
{
get
{
return this.m_usertitle;
}
set
{
this.m_usertitle=value;
}
}
public system.collections.arraylist getmycourse()
{
system.collections.arraylist result=null;
return result;
}


}
}

using system;

namespace com.oztime.workshop.codebase.db
{
/// <summary>
/// summary description for dbglobal.
/// </summary>
public class dbglobal
{
public dbglobal()
{
//
// todo: add constructor logic here
//
}
public static string dsn="dsn";
/*--------------以下内容与用户类相关----------*/
public static string selectuserbyid="select * from users where userid=@userid";
public static string selectuserbyname="select * from users where username=@username";
public static string addnewuser="insert into users(username,password,usersex,useremail,usertitle) values(@username,@password,@usersex,@useremail,@usertitle)";
public static string selectcurrentuserid="select max(userid) from users";
public static string selectuserbynameandpassword="select * from users where username=? and password=?";

/*-----------------end-----------------------*/

}
}

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:ASP.NET追捕休整版
· 下一篇:图片上传的功能简介及web.config设置
· ASP.NET2.0应用中定制安全凭证之实践篇
· 在ASP.NET中操作文件的例子(VB)
· 开始 .Net的旅程(二)
· 用c#写的asp+域名查询程序
· 挤压造型Extrusion的节点说明和应用实例


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077