Seven-storey landing

Source: Internet
Author: User
Preface

Fear comes from ignorance.

Especially in our study, you feel it difficult. Not because it's hard, but because you don't know it.

So seven-storey landing, started in three, gradually, not feel its difficult seven layers

The so-called seven-layer, in fact, only on the basis of the three layer and detailed division of the three layer, plus has been in the solid layer, a total of seven layers.

1. Display layer (UI)

 2. The appearance layer (façade)
     implements the appearance pattern, which, as a bridge between the UI and the BLL, relieves the coupling between them

 3. Logical layer (BLL)

 4. Interface Layer (Idall)
    at this level, Defines a unified interface that unlocks the coupling between the BLL layer and the DAL layer

 5. The Data Access Layer (DAL)
    has a sqlhelper layer in it that encapsulates some of the code that is invoked on the database, which improves the flexibility of our code.

 6. The factory layer (Factory)
    realizes the Factory mode + reflection, makes the modification of the database simpler, realizes the modification of the database by modifying the configuration file

 7. The entity layer (Entity)
    encapsulates some of the functional code primarily, Defines some entity types and entity collections for passing parameters at various levels
UML Diagrams


Code

Practice the truth, on the code. UI

private void Btnok_click (object sender, EventArgs e) {//judgment input cannot be empty if (TxtUserID.Text.Tri m () = = "") {MessageBox.Show ("") did not enter a user name.
            "," hint ", MessageBoxButtons.OK, messageboxicon.warning); } if (txtPassword.Text = = "") {MessageBox.Show ("") did not enter a password.
            "," hint ", MessageBoxButtons.OK, messageboxicon.warning); try {//Instantiate a look facade.loginfacade façade = new Facade.loginfaca
                De ();
                Instantiate a user Entity.userinfo = new Entity.userinfo (); The username information from the receiving control is user.
                UserID = Convert.ToInt32 (TxtUserID.Text.Trim ()); Receive password information from space user.


                PassWord = txtPassword.Text;    


                Boolean flag = false;//Defines the variable to be given a bool type Facade.loginfacade flogin = new Facade.loginfacade ();//materialized appearance Flag = flogin.selectuser (user);//Call the method of the skin, return to user if (flag!= false) {MessageBox.Show ("login succeeded.")
                    "); This.                     Hide (); Hides the current form this.
                    DialogResult = System.Windows.Forms.DialogResult.OK;                 Frmmain a = new Frmmain ();//Instantiate a Form a.show ();
                Displays the instantiated form} else {MessageBox.Show ("Password or username error");
            } catch (Exception) {throw; }
        }
Façade
Public Boolean selectuser (entity.userinfo user)
        {
            bool flag;
            Bll. LOGINBLL USERBLL = new BLL. LOGINBLL ();
            Flag = USERBLL.USERBLL (user);
            return flag;
        }
BLL
public bool Userbll (Entity.userinfo UserInfo)
        {
            //instance chemical plant 
            factory.loginfactory fact = new Factory.loginfactory ();
            Call the factory method to create an interface    
            Idal. Loginidal Idal = fact. CreateUser ();
            Accept the return value of the D-level  
            DataTable table = Idal.selectuser (UserInfo);  
            BOOL Flag;
            The type of DataTable returned, if its row number is equal to 0, the user if (table) that does not meet the password for the account 
            . Rows.Count = = 0)   
            {flag = false;}
            else
            {
                flag = true;
            }
            return flag;
        }
Idal
Public interface Loginidal
    {
        //define an abstract method for selecting a user
        DataTable selectuser (Entity.userinfo UserInfo);
        Define an abstract method for selecting students
        DataTable selectstudent (Entity.studentinfo studentinfo);
    }
DAL
Public DataTable Selectuser (entity.userinfo UserInfo)
        {
        //Instantiate an object for a data query
        SQLHelper SQLHelper = new SQLHelper ();
        Select the data to query
        sqlparameter[] sqlparams = {new SqlParameter ("@userID", Userinfo.userid), New SqlParameter ("@PassWord ", Userinfo.password)};
        SUSSU statement
        String sql = @ "SELECT * FROM [User_info] WHERE userid= @UserID and PassWord = @PassWord";
        Put the parameter into the statement
        DataTable table = sqlhelper.executequery (sql, Sqlparams, commandtype.text);
        Returns the return
        table value;
        
SQLHelper
public class SQLHelper
    {
        private SqlConnection conn = null;
        Private SqlCommand cmd = null;
        Private SqlDataReader SDR = null;

        Public DataTable executequery (string cmdtext, Sqlparameter[] paras, CommandType ct)
        {
            datatable dt = new DATATABL E ();
            cmd = new SqlCommand (Cmdtext, Getconn ());

            Cmd.commandtype = ct;
            Cmd. Parameters.addrange (paras);
            using (SDR = cmd.) ExecuteReader (commandbehavior.closeconnection))
            {
                dt. Load (SDR);
            }
            return dt;
        }
    }
Factory
public class Loginfactory
    {
        //Receive data string strDB from the configuration file    
        = system.configuration.configurationmanager.appsettings["DB"];

        Public Idal. Loginidal CreateUser ()
        {
            //dal layer's class name    
            string ClassName = strDB + "." + "Logindal";
            Application of reflective processing plant return     
            (idal. Loginidal) Assembly.Load (STRDB). CreateInstance (ClassName);            
        }
    
Entity
public class UserInfo
    {
        //define User ID field  
        private int userid;
        public int UserID
        {get
            {return UserID;}

            set {UserID = value;}
        }

        Define User name  field  
        private string userName;
        public string UserName
        {get
            {return UserName;}
            set {userName = value;}
        }

        Set Password field  
        private string password;
        public string PassWord
        {get
            {return PassWord;}
            set {password = value;}
        }

        Defines the Rank field  
        private string level;
        public string level
        {get {return level
            ;}
            set {level = value;}
        }

        Define Status  field  
        private bool stat;
        public bool State
        {get
            {stat;}
            set {stat = value;}
        }
app.config
<appSettings>
        <add key = "ConnStr" value= "Server=sql login name or use." means local (may not be possible); database= database name; user ID = sa; pwd= 123456 "/>
        <add key =" DB "value=" DAL "/>
      

Note: When calling a system function, be sure to call the namespace between the various levels of the reference must be clear, to prevent the occurrence of cyclic dependency classes and methods of naming must have their own rules, now the class and method less, and so many later, you will feel the benefits of the rules of the details of all good

Yes, you have to work hard, life is so beautiful.


I hope this article is helpful to you.
What's the problem? Please correct me.
It feels good to be praised.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.