前面介绍了三层的知识内容,这里介绍一下三层的代码内容,就以登陆窗体(C#语言)为例:
UI层
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LoginUI
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnLogin_Click(object sender, EventArgs e)
{
//IDbConnection conn = new SqlConnection("");
//IDbCommand cmd = conn.CreateCommand();
//cmd.CommandText = "Select UserName From USER WHERE...";
//cmd.ExecuteReader();
string userName = txtUserName.Text .Trim();
string password = txtPassword.Text;
Login.BLL.LoginManager mgr = new Login.BLL.LoginManager();
Login.Model.UserInfo user= mgr.UserLogin(userName, password);
MessageBox.Show("UserName:" + user.UserName);
}
private void btnExit_Closing(object sender, EventArgs e)
{
if(MessageBox.Show ("确定退出?","退出登录",MessageBoxButtons.OKCancel ,MessageBoxIcon.Question ,MessageBoxDefaultButton.Button2)==DialogResult.OK)
{
this.Close();
}
}
}
}