zoukankan      html  css  js  c++  java
  • 三层架构源代码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using Model;
    using BLL;
    
    namespace UI
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private UserService us = new UserService();
            private void Form1_Load(object sender, EventArgs e)
            {
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                User user = new User();
                user.UserName = txtUserName.Text.Trim();
                user.Password = txtPassword.Text.Trim();
                if (us.CheckUser(user))
                {
                    MessageBox.Show("登录成功!");           //UI层
                }
                else
                {
                    MessageBox.Show("登录失败!");
                }
            }
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Model;
    using DAL;
    
    namespace BLL
    {
        public class UserService
        {
            private UserDAO dao = new UserDAO();
            public bool CheckUser(User user)
            {
                User u = dao.GetUserByUserName(user.UserName);
                if (u == null)
                {
                    return false;
                }
                else                              //bll层
                {
                    return user.Password == u.Password;
                }
            }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Model;
    using System.Data;
    using System.Data.SqlClient;
    
    namespace DAL
    {
        public class UserDAO
        {
           
            public User GetUserByUserName(string username)
            {
                string sql = "select * from users where username=@username";
                List<SqlParameter> paras=new List<SqlParameter>();
                paras.Add(new SqlParameter("@username",username));
                DataTable  dt= SqlHelper.ExecuteTable(sql,paras);           
                User user = null;
                if (dt.Rows.Count == 1)
                {                                              //dal层
                    user = new User();
                    DataRow row = dt.Rows[0];
                    user.UserId = Convert.ToInt32(row[0]);
                    user.UserName = row[1].ToString();
                    user.Password = row[2].ToString();
                }
                return user;
                
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Model
    {
        public class User                              //实体层
        {
            public int UserId { get; set; }
            public string UserName { get; set; }
            public string Password { get; set; }
        }
    }
    
    
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
        </startup>
      <connectionStrings>
        <add name="ConnStr" connectionString="server=.;database=schooldb;uid=sa;pwd=123"/>
      </connectionStrings>
    </configuration>
    
    添加引用 程序集  configuration 
    privarte static readonly string 名字=configrationmanager 
  • 相关阅读:
    仅Firefox中链接A无法实现模拟点击以触发其默认行为
    读jQuery之十二(删除事件核心方法)
    读jQuery之十(事件模块概述)
    读jQuery之十五
    事件模块的演变(9)
    Chrome(12)中使用getComputedStyle获取透明度(opacity)返回字符串不同于其它浏览器
    各浏览器对click方法的支持差异
    IE6/7 and IE8/9/10(IE7模式)依次隐藏具有absolute或relative的父元素和子元素后再显示父元素,子元素依然能显示bug
    Node.js: Python not found exception due to nodesass and nodegyp
    高等数学 工专 柳重堪
  • 原文地址:https://www.cnblogs.com/liyiyong/p/5134731.html
Copyright © 2011-2022 走看看