房屋交易系统(winForm)之登陆界面

UIL界面层代码

 1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.Data.SqlClient;
10
11 namespace FangWuJiaoYi
12 {
13 public partial class frm_Login : Form
14 {
15 public frm_Login()
16 {
17 InitializeComponent();
18 }
19 public string YongHu;
20 public string YongHu_ID;
21 public string PassWord;
22 DataTable dt;
23 private void btn_DengLu_Click(object sender, EventArgs e)
24 {
25 YongHu = txt_YongHu.Text.ToString().Trim();//获取用户名
26 PassWord = txt_PassWord.Text.ToString().Trim();//获取密码
27 if (YongHu == "")//判断用户名是否为空
28 {
29 MessageBox.Show("请填写用户名!!", "温馨提示:");
30 }
31 else
32 {
33 //链接数据库,查看是否存在该用户
34 dt = new DataTable();
35 dt = BLL_MainProject.Login.Select_YongHu(YongHu);
36 if (dt.Rows.Count == 0)
37 {
38 MessageBox.Show("不存在该用户名,请检查!!", "温馨提示:");
39 txt_YongHu.Clear();
40 txt_PassWord.Clear();
41 }
42 else
43 {
44 //链接数据库,查看用户和密码是否正确
45 dt = new DataTable();
46 dt = BLL_MainProject.Login.Select_YongHu_MiMa(YongHu, PassWord);
47 if (PassWord == "")
48 {
49 MessageBox.Show("请填写用户密码!!", "温馨提示:");
50 }
51 else if (dt.Rows.Count == 0)
52 {
53 MessageBox.Show("密码错误!!请重新输入!");
54 txt_PassWord.Clear();
55 txt_PassWord.Focus();
56 }
57 else
58 {
59 YongHu_ID = dt.Rows[0][2].ToString().Trim();//获取登陆用户的ID号
60 frm_Main myfrm_Main = new frm_Main();
61 myfrm_Main.YongHuMing = this.YongHu;//传递用户名给主界面
62 myfrm_Main.YuanGong_ID = this.YongHu_ID;//传递用户ID给主界面
63 myfrm_Main.Show();
64 this.Hide();
65 }
66
67 }
68 }
69
70
71 }
72
73 }
74 }

BLL逻辑层代码

 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Data;
6 using System.Data.SqlClient;
7
8 namespace BLL_MainProject
9 {
10 public class Login
11 {
12 //初始化cbo控件
13 public static DataTable Select_YongHu(string YongHu)
14 {
15 //准备调用DAL层方法的对应参数
16 SqlParameter[] SQlCMDpas ={
17 new SqlParameter("@type",SqlDbType.Char),
18 new SqlParameter("@YongHu",SqlDbType.Char),
19 };
20 SQlCMDpas[0].Value = "Select_YongHu";
21 SQlCMDpas[1].Value = YongHu;
22 //实例化DAL层对应的类,调用DAL类,传入参数
23 DataTable dt = DAL.PublicMethod.DAL_SelectDB_Par("DengLu", SQlCMDpas);
24 return dt;
25 }
26
27 public static DataTable Select_YongHu_MiMa(string YongHu,string PassWord)
28 {
29 //准备调用DAL层方法的对应参数
30 SqlParameter[] SQlCMDpas ={
31 new SqlParameter("@type",SqlDbType.Char),
32 new SqlParameter("@YongHu",SqlDbType.Char),
33 new SqlParameter("@MiMa",SqlDbType.Char)
34 };
35 SQlCMDpas[0].Value = "Select_YongHu_MiMa";
36 SQlCMDpas[1].Value = YongHu;
37 SQlCMDpas[2].Value = PassWord;
38 //实例化DAL层对应的类,调用DAL类,传入参数
39 DataTable dt = DAL.PublicMethod.DAL_SelectDB_Par("DengLu", SQlCMDpas);
40 return dt;
41 }
42 }
43 }

DAL数据层代码(PublicMethod)

 1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Data.SqlClient;
6 using System.Linq;
7 using System.Text;
8
9
10 namespace DAL
11 {
12 public class PublicMethod
13 {
14 //提取数据库中的数据
15 public static DataTable DAL_SelectDB_Par(string sqlstr, SqlParameter[] SQlCMDpas)
16 {
17 //创建链接对象
18 DataPublicVar.sqlcn = new SqlConnection(DataPublicVar.jcglstr.ToString());
19 DataPublicVar.sqlcn.Open();
20 //创建cmd
21 DataPublicVar.sqlstr = sqlstr;
22 DataPublicVar.sqlcmd = new SqlCommand(DataPublicVar.sqlstr, DataPublicVar.sqlcn);
23 DataPublicVar.sqlcmd.CommandType = CommandType.StoredProcedure;
24 //利用数组动态参数化存储过程的参数
25 foreach (SqlParameter var in SQlCMDpas)
26 {
27 DataPublicVar.sqlcmd.Parameters.Add(var);
28 }
29
30 SqlDataReader dr = DataPublicVar.sqlcmd.ExecuteReader();
31 DataTable dt = new DataTable();
32 dt.Load(dr);
33 DataPublicVar.sqlcn.Close();
34 dr.Close();
35 return dt;
36 //创建链接对象
37
38 //DataPublicVar.sqlcn = new SqlConnection(DataPublicVar.jcglstr.ToString());
39 ////创建cmd
40 //DataPublicVar.sqlstr = sqlstr;
41 //DataPublicVar.sqlcmd = new SqlCommand(DataPublicVar.sqlstr, DataPublicVar.sqlcn);
42 //DataPublicVar.sqlcmd.CommandType = CommandType.StoredProcedure;
43 //// //利用数组动态参数化存储过程的参数
44 //foreach (SqlParameter var in SQlCMDpas)
45 //{
46 // DataPublicVar.sqlcmd.Parameters.Add(var);
47 //}
48
49 //DataTable dt = new DataTable();
50 ////执行SqlDataAdapter
51 //DataPublicVar.sqlda = new SqlDataAdapter(DataPublicVar.sqlcmd);
52 ////填充数据到dt,并返回
53 //DataPublicVar.sqlda.Fill(dt);
54 // return dt;
55
56 }
57
58
59 //插入、更新、删除数据库中的数据
60 public static void DAL_OPTableDB_Par(string sqlstr, SqlParameter[] SQlCMDpas)
61 {
62 //创建链接对象
63 DataPublicVar.sqlcn = new SqlConnection(DataPublicVar.jcglstr.ToString());
64 DataPublicVar.sqlcn.Open();
65 //创建cmd
66
67 DataPublicVar.sqlstr = sqlstr;
68 DataPublicVar.sqlcmd = new SqlCommand(DataPublicVar.sqlstr, DataPublicVar.sqlcn);
69 DataPublicVar.sqlcmd.CommandType = CommandType.StoredProcedure;
70 //利用数组动态参数化存储过程的参数
71 foreach (SqlParameter var in SQlCMDpas)
72 {
73 DataPublicVar.sqlcmd.Parameters.Add(var);
74 }
75 DataPublicVar.sqlcmd.ExecuteNonQuery();
76 DataPublicVar.sqlcn.Close();
77 //return i;
78
79 }
80 }
81 }

DAL数据层代码(DataPublicVar)

 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Data;
6 using System.Data.SqlClient;
7
8 namespace DAL
9 {
10 class DataPublicVar
11 {
12 //定义连接字符
13 //public static string jcglstr = Properties.Settings.Default.Setting;
14 public static string jcglstr = @"Data Source=(local);Initial Catalog=房屋交易;Integrated Security=True";
15 public static SqlCommand sqlcmd;//定义命令语句
16 public static string sqlstr;
17 public static SqlDataAdapter sqlda;//定义识别器
18 public static DataSet ds = new DataSet();//定义数据集
19 public static SqlDataReader sqldr;//定义只读器
20 public static DataTable dt;//定义数据表
21 public static DataRow dr;//定义行
22 public static SqlConnection sqlcn;
23 }
24 }


效果图




 

posted @ 2012-03-02 23:17  Ghost Soar  阅读(5227)  评论(0编辑  收藏  举报