自定义控件的使用例子一
2024-07-21 02:16:45
供稿:网友
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;
}
}
}