复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126using 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 System.Data.SqlClient; namespace WindowsFormsApplication2 { public partial class Form1 : Form { // public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { MessageBox.Show("确定取消登陆吗"); this.Close(); } private void Form1_Click(object sender, EventArgs e) { if (this.BackColor == Color.Red) { this.BackColor = Color.Yellow; } else if (this.BackColor == Color.Yellow) { this.BackColor = Color.Green; } else { this.BackColor = Color.Red; } } public const string CAPTION = "输入提示"; public const string ADMIN = "管理员"; private void button1_Click(object sender, EventArgs e) { //用户名 密码和用户类型都不为空 if (CheckInput()) { if (this.comboBox1.Text.Equals(ADMIN)) { guanliyuan d = new guanliyuan(); d.name = textBox1.Text; d.Show(); } this.Hide(); } } //用户名为空 public bool CheckInput() { if (this.textBox1.Text.Trim().Equals(string.Empty)) { MessageBox.Show("请输入用户名", CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); this.label1.Focus(); return false; } //密码为空 else if (this.textBox2.Text.Trim().Equals(string.Empty)) { MessageBox.Show("请输入密码", CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtpwd.Focus(); return false; } //用户类型为空 else if (this.comboBox1.Text.Trim().Equals(string.Empty)) { MessageBox.Show("请选择登录类型", CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); this.cboLoginType.Focus(); return false; } else { guanliyuan d = new guanliyuan(); d.name = textBox1.Text; return true; } } public bool CheckUser(ref string message) { bool i = false; string name = this.textBox1.Text.Trim(); string mima = textBox2.Text.Trim(); StringBuilder sb = new StringBuilder(); if (txtpwd.Equals(ADMIN)) { sb.AppendFormat("SELECT COUNT(*) FROM [Table_1]" + " WHERE [name]= '" + name + "' AND [mima]='" + mima + "'"); } int count = 0; DEHelper dbhelper = new DEHelper(); try { SqlCommand comm = new SqlCommand(sb.ToString(), dbhelper.Connection); dbhelper.OpenConnection(); count = (int)comm.ExecuteScalar(); if (count > 0) { i = true; } else { message = "用户名或密码不存在"; i = false; } } catch (Exception) { message = "系统发生错误,请稍后再试"; i = false; } finally { dbhelper.CloseConnection(); } return i; } } }
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.SqlClient; using System.Data; namespace WindowsFormsApplication2 { class DEHelper { private string connString = "Data Source=.;Initial Catalog=MySchool;Integrated Security=True"; private SqlConnection connection; public SqlConnection Connection { get { if (connection == null) { connection = new SqlConnection(connString); } return connection; } } public void OpenConnection() { if (Connection.State == ConnectionState.Closed ) { Connection.Open(); } else if (Connection.State == ConnectionState.Broken) { Connection.Close(); Connection.Open(); } } public void CloseConnection() { if (Connection.State == ConnectionState.Open || Connection.State == ConnectionState.Broken) { Connection.Close(); } } } }
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26using 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; namespace WindowsFormsApplication2 { public partial class guanliyuan : Form { public string name = ""; public guanliyuan() { InitializeComponent(); } private void guanliyuan_Load(object sender, EventArgs e) { this.aa.Text = name; } } }
最后
以上就是傲娇长颈鹿最近收集整理的关于数据库 第一章Windows程序的全部内容,更多相关数据库内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复