Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > ASP.NET > 自定义控件的使用例子
【标  题】:自定义控件的使用例子
【关键字】:控件
【来  源】:网络

自定义控件的使用例子

Your Ad Here


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-----------------------*/

    }
}

使用net classes访问其他网站内容:【上一篇】
Windows操作系统中的.NET Framework支持:【下一篇】
【相关文章】
  • 自己写的自定义Web的上传控件
  • ASP.NET DataGrid 控件深入研究
  • 从ASP.NET服务器控件插入客户端脚本
  • ASP.NET用户控件返回事件的方法
  • 动态生成asp.net控件
  • Html中使用M$控件系列之 TreeView 篇
  • 用JavaScript解决ASP.NET服务器控件造成的刷新问题
  • 自定义XML文件在TreeView控件中的使用
  • 两种添加数据到WEB DropDownList 控件的方法
  • 解决VFP的表格控件Grid变白等问题
  • 【随机文章】
  • SQL 语法参考
  • 高质量c c++编程一 文件结构 [转载来自林锐博士]
  • ActionScript3.0的新特性及新变化
  • 使用脚本自动压缩指定目标下的所有文件
  • 在线编辑器FCKeditor 2.0试用小记 zt
  • 局域网络的病毒防护—保护策略和安全级别
  • oracle概念和术语
  • Oracle中特殊的INSERT语句
  • 距离rhce考试还有17天
  • tomcat 虚拟主机 设置
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.