.NET中三層構架開發執行個體-使用者註冊系統

來源:互聯網
上載者:User
使用者註冊    下面是使用者註冊系統開發的三層構架執行個體:資料庫基類採用上面提供的代碼。

1、使用者註冊模組資料層開發:
using System;
using System.Data;
using System.Data.SqlClient;
using HaiSky.HtJob;
using System.Xml;
namespace HaiSky.HtJob.Accounts.AccountsData
{
    public class User : HaiSky.HtJob.HaiSkyDbObject
    {
        public User(string newConnectionString) : base(newConnectionString)
        {//直接路由連接字串}
        public int Create(string user_nm,string user_pwd)
        {
            int rowsAffected;
            SqlParameter[] parameters = {new SqlParameter("@user_nm",SqlDbType.Char,16),
                                        new
SqlParameter("@user_pwd",SqlDbType.Char,16)};
            parameters[0].Value = user_nm;
            parameters[1].Value = user_pwd;
            parameters[2].Direction = ParameterDirection.Output;
            try
            {
                RunProcedure("IF_user_info",parameters,out rowsAffected);
            }
            catch
            {    }
            return (int)parameters[2].Value;
        }
    }
}

2、使用者註冊商務層開發:
using System;
using System.Configuration;
using HaiSky.HtJob.Accounts.AccountsData;
namespace HaiSky.HtJob.Accounts.AccountBusiness
{
    public class User : HaiSky.HtJob.HaiSkyBizObject
    {
        int userID;
        string userName;
        string userPwd;
        string strConn;
        public User()
        {
            strConn = ConfigurationSettings.AppSettings["strConn"];
        }
        public int Careate()
        {
            AccountsData.User dataUser = new AccountsData.User(strConn);
            userID = dataUser.Create(userName,userPwd);
            return userID;
        }
        public int UserID
        {
            get
            {
                return userID;
            }
            set
            {
                userID = value;
            }
        }
        public string UserName
        {
            get
            {
                return userName;
            }
            set
            {
                userName = value;
            }
        }
        public string UserPwd
        {
            get
            {
                return userPwd;
            }
            set
            {
                userPwd = value;
            }
        }
    }
}

3、 使用者註冊展示層開發:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using HaiSky.HtJob.Accounts.AccountBusiness;

namespace HaiSky.HtJob.Modules.Accounts
{
    public class Register : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.TextBox TextBox1;
        protected System.Web.UI.WebControls.TextBox TextBox2;
        protected System.Web.UI.WebControls.Table Table1;
        protected System.Web.UI.WebControls.Button Button1;

        private void Page_Load(object sender, System.EventArgs e)
        {
            Table1.Rows[0].Cells[0].Visible = false;
        }
        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }    
        private void InitializeComponent()
        {    
            this.Button1.Click += new System.EventHandler(this.Button1_Click);
            this.Load += new System.EventHandler(this.Page_Load);
        }
        #endregion
        private void Button1_Click(object sender, System.EventArgs e)
        {
            int i;
            HtJob.Accounts.AccountBusiness.User BusinessUser = new HtJob.Accounts.AccountBusiness.User();
            BusinessUser.UserName = TextBox1.Text;
            BusinessUser.UserPwd = TextBox2.Text;
            i = BusinessUser.Careate();
            Response.Write (i.ToString());                         //這裡輸出傳回值
        }
    }
}

4、該系統調用的預存程序:
CREATE PROCEDURE IF_user_info
(@user_nm char(16),@user_pwd char(16),@user_ID int output)
AS
    insert user_info(user_nm,user_pwd) values(@user_nm,@user_pwd)
set @user_ID = @@identity
    IF @@ERROR > 0
        BEGIN
        RAISERROR ('Insert of Article failed', 16, 1)

相關文章

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

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

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