自訂控制項的使用例子一

來源:互聯網
上載者:User
控制項 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;
        }


    }
}
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.