日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

.net三层架构开发步骤

發布時間:2023/12/3 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 .net三层架构开发步骤 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

City城市表,id ,name,password,address,phone;
1.新建一個windows窗體應用程序,CitySys
2.文件–》添加–》新建項目–》類庫(CitySysModel)–》重命名class1.cs的類(CityModel)。
3.根據數據表里面的字段,在Model里面創建字段。prop+tab
+tab.

eg:public int Id{get;set;}public string Name{get;set;}public string Password{get;set;}public string Address{get;set;}public string Phone{get;set;}

4.創建DLL層,CitySysDLL。–>重命名Class1.cs,CityDLL。
5.創建BLL層,CitySysBLL。–》重命名Class1.cs,CityBLL。
6.添加引用:表示層引用–》Model層和BLL層
BLL層引用DLL層和MOdel層
DLL層引用Model層
7.去DLL層里面寫兩個方法(登陸[Login]和AddCity[添加])。
8.DLL層里面的代碼:

public string constr = "數據庫連接字符串"; //登陸 public bool Login(string name,string password){string sql = "select * from city where name = @name and password = @password";SqlParameter [] param = new Sqlparameter[]{new Sqlparameter("@name",name),new SqlParameter("@password",password)};using(SqlConnection conn = new SqlConnection(constr)){SqlCommand cmd = new SqlCommand (sql,conn);cmd.Parameters.AddRange(param);conn.Open();SqlDataReader dr = cmd.ExecuteReader();if(dr.Read()){dr.Close();conn.Close();return true;}else{dr.Close();conn.Close();return false;}} } //添加的方法 public int AddCity(City city ){string sql="insert into city values(@name,@password,@address,@phone)";SqlParameter [] param = new Sqlparameter[]{ new Sqlparameter("@name",city.name), new SqlParameter("@password",city.password), new SqlParameter("@address",city.address), new SqlParameter("@phone",city.phone)};using(SqlConnection conn = new SqlConnection(constr)){SqlCommand cmd = new SqlCommand(sql,conn);cmd.Parameters.AddRange(param );conn.Open();return cmd.ExecuteNonQuery();} }

9.寫BLL層。給BLL層里面寫登陸的方法和添加的方法

public CityDLL cdll = new CityDLL(); //登陸 public bool Login(string name ,string password){return cdll.Login(name,password); } //添加 public int AddCity(City city){return cdll.AddCity(city); }

10.開始在默認的窗體里面拉幾個lable和button
label = 歡迎進入某某系統
lable2 = 名稱 textbox = Name
lable3 = 密碼 textbox = Password
button1 = 登陸 button2 = 取消
11.雙擊登陸進去。寫登陸的方法

public CityBLL cbll = new CityBLL();//獲取值 string name = this.Name.Text; string password = this.Password.Text; if(cbll.Login(name,password)){MessageBox.Show("登陸成功");FrmMain fm = new FrmMain();fm.Show();this.Hide(); } else{MessageBox.Show("登陸失敗"); }

12.創建一個主窗體,右擊–》添加–》windows窗體–》FrmMain.–》拉四個Button,分別是添加信息,查詢信息,修改信息,刪除信息
13.雙擊添加信息進去,寫代碼:
//打開添加的窗體
addCity ac = new addcity();
ac.Show();
this.Hide();
14.拉一個添加的窗體。雙擊添加按鈕進去寫代碼:

//獲取值City city = new City();city.Name = this.name.Text;city.Password = this.Password.Text;city.Address = this.Address.Text;city.Phone = this.Phone.Text;//調用bll里面添加方法int rel = cbll.AddCity(city);if(rel>0){MessageBox.Show("添加成功");}else{MessageBox.Show("添加失敗");}

總結

以上是生活随笔為你收集整理的.net三层架构开发步骤的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。