熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

.NET中三層構架開發實例-用戶注冊系統

2013-11-13 10:27:35  來源: .NET編程 
下面是用戶注冊系統開發的三層構架實例數據庫基類采用上面提供的代碼

用戶注冊模塊數據層開發
using System;
using SystemData;
using SystemDataSqlClient;
using HaiSkyHtJob;
using SystemXml;
namespace HaiSkyHtJobAccountsAccountsData
{
    public class User : HaiSkyHtJobHaiSkyDbObject
    {
        public User(string newConnectionString) : base(newConnectionString)
        {//直接路由連接字符串}
        public int Create(string user_nmstring user_pwd)
        {
            int rowsAffected;
            SqlParameter[] parameters = {new SqlParameter(@user_nmSqlDbTypeChar)
                                        new
SqlParameter(@user_pwdSqlDbTypeChar)};
            parameters[]Value = user_nm;
            parameters[]Value = user_pwd;
            parameters[]Direction = ParameterDirectionOutput;
            try
            {
                RunProcedure(IF_user_infoparametersout rowsAffected);
            }
            catch
            {    }
            return (int)parameters[]Value;
        }
    }
}

用戶注冊商務層開發
using System;
using SystemConfiguration;
using HaiSkyHtJobAccountsAccountsData;
namespace HaiSkyHtJobAccountsAccountBusiness
{
    public class User : HaiSkyHtJobHaiSkyBizObject
    {
        int userID;
        string userName;
        string userPwd;
        string strConn;
        public User()
        {
            strConn = ConfigurationSettingsAppSettings[strConn];
        }
        public int Careate()
        {
            AccountsDataUser dataUser = new AccountsDataUser(strConn);
            userID = dataUserCreate(userNameuserPwd);
            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;
            }
        }
    }
}

 用戶注冊表示層開發
using System;
using SystemCollections;
using SystemComponentModel;
using SystemData;
using SystemDrawing;
using SystemWeb;
using SystemWebSessionState;
using SystemWebUI;
using SystemWebUIWebControls;
using SystemWebUIHtmlControls;
using HaiSkyHtJobAccountsAccountBusiness;

namespace HaiSkyHtJobModulesAccounts
{
    public class Register : SystemWebUIPage
    {
        protected SystemWebUIWebControlsTextBox TextBox;
        protected SystemWebUIWebControlsTextBox TextBox;
        protected SystemWebUIWebControlsTable Table;
        protected SystemWebUIWebControlsButton Button;

        private void Page_Load(object sender SystemEventArgs e)
        {
            TableRows[]Cells[]Visible = false;
        }
        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            baseOnInit(e);
        }    
        private void InitializeComponent()
        {    
            thisButtonClick += new SystemEventHandler(thisButton_Click);
            thisLoad += new SystemEventHandler(thisPage_Load);
        }
        #endregion
        private void Button_Click(object sender SystemEventArgs e)
        {
            int i;
            HtJobAccountsAccountBusinessUser BusinessUser = new HtJobAccountsAccountBusinessUser();
            BusinessUserUserName = TextBoxText;
            BusinessUserUserPwd = TextBoxText;
            i = BusinessUserCareate();
            ResponseWrite (iToString());                         //這裡輸出返回值
        }
    }
}

該系統調用的存儲過程
CREATE PROCEDURE IF_user_info
(@user_nm char()@user_pwd char()@user_ID int output)
AS
    insert user_info(user_nmuser_pwd) values(@user_nm@user_pwd)
set @user_ID = @@identity
    IF @@ERROR >
        BEGIN
        RAISERROR (Insert of Article failed )

From:http://tw.wingwit.com/Article/program/net/201311/13704.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.