Use example of a custom control

Source: Internet
Author: User
Tags dsn tostring
Control 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;
}


}
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.