庞大资源库的计算机教程网站!
设为首页
加入收藏
总编信箱
投稿或申请专栏请先 [登 陆]
首页 操作系统 程序设计 图形图像 媒体动画 机械电子 WEB开发 数 据 库 办公系列 路由技术 网络原理 网络应用
认证考试 安全技术
首页>WEB开发>ASP.NET>开发实例>正文
资料搜索
Google搜索
Google
返回上级列表

推荐文章

快速保存网页中所有图片的方法
Windows中让光驱巧妙“隐身”技
防范非法用户入侵Win 2000/XP系
两款比较典型的ASP木马防范方法
有关表格边框的css语法整理
Windows XP中可以被禁用的服务
SQL Server导出导入数据方法
Javascript所有对象的属性的获
网页(HTML)中的特殊字符
与篮球共舞,尽显模式本色
QQ病毒的手工清除方法
Photoshop为极品美女打造性感睫
天衣无缝:IIS与PHP水火也相容
SQL Server存储过程编写和优化

自定义控件的使用例子

 作者:本站收集   日期:2005-3-17
字号选择〖 〗/ 双击滚屏 单击停止   


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

    }
}

上一篇:图片上传的功能简介及web.config设置    下一篇:ASP.NET追捕休整版  
[发送给好友]  [关闭窗口]  [返回顶部]   转载请注明来源:www.it00.com   
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
责任编辑: 原点 投稿作者: 本站收集
信息来源: 网络 录入时间: 2005-3-17
关于我们 - 广告服务 - 版权申明 - 网站地图 - 联系方式 - 总编信箱 - 会员投稿