<WinForm :TNS学生管理系统源码》

当前路径:StudentManage/frmEnroll.cs
2    using System;
3    using System.Collections.Generic;
4    using System.ComponentModel;
5    using System.Data;
6    using System.Drawing;
7    using System.Linq;
8    using System.Text;
9    using System.Windows.Forms;
10    using System.Data.SqlClient;
11    using BLL;
12    using Model;
13    
14    namespace StudentManage
15    {
16        public partial class frmEnroll : Form
17        {
18            public frmEnroll()
19            {
20                InitializeComponent();
21            }
22            UsersBLL ubll = new UsersBLL();
23            Users us = new Users();
24            private void frmEnroll_Load(object sender, EventArgs e)
25            {
26                string path = Application.StartupPath + "\\EmeraldColor1.ssk";
27                skinEngine1.SkinFile = path;
28                cboquestion.Text = "";
29            }
30            private void btnEnroll_Click(object sender, EventArgs e)
31            {
32                if (txtname.Text == "")
33                {
34                    MessageBox.Show("用户名不能为空,请您输入!");
35                    tabControl1.SelectedTab = this.tabPage1;
36                    txtname.Focus();
37                }
38                else if (txtpwd.Text == string.Empty)
39                {
40                    MessageBox.Show("请输入密码!");
41                    tabControl1.SelectedTab = this.tabPage1;
42                    txtpwd.Focus();
43                }
44                else if (txtRepwd.Text == "")
45                {
46                    MessageBox.Show("确认密码不能为空!");
47                    tabControl1.SelectedTab = this.tabPage1;
48                    txtRepwd.Focus();
49                }
50                else if (cboquestion.Text == string.Empty)
51                {
52                    MessageBox.Show("请您选择一个密保问题,以方便为您找回密码!");
53                    tabControl1.SelectedTab = this.tabPage2;
54                }
55                else if (txtanswer.Text == string.Empty)
56                {
57                    MessageBox.Show("请您写出问题答案!");
58                    tabControl1.SelectedTab = this.tabPage2;
59                    txtanswer.Focus();
60                }
61                else
62                {
63                    Enroll();
64                }
65            }
66            private void txtname_Leave(object sender, EventArgs e)
67            {
68                if (txtname.Text != string.Empty)
69                {
70                    JianCe();
71                }
72            }
73    
74            private void txtpwd_Leave(object sender, EventArgs e)
75            {
76                if (isfond1 == true && isfond2 == true)
77                {
78                    label6.Visible = true;
79                    label6.Text = "";
80                }
81                else if (isfond1 == false && isfond2 == true)
82                {
83                    label6.Visible = true;
84                    label6.Text = "";
85                }
86                else
87                {
88                    label6.Visible = true;
89                    label6.Text = "";
90                }
91                isfond1 = false;
92                isfond2 = false;
93            }
94    
95            private void txtRepwd_Leave(object sender, EventArgs e)
96            {
97                if (txtpwd.Text != txtRepwd.Text)
98                {
99                    tabControl1.SelectedTab = this.tabPage1;
100                    MessageBox.Show("对不起,您输入的两次密码不相同,请重新输入!");
101                    label6.Visible = false;
102                    txtpwd.Text = "";
103                    txtRepwd.Text = "";
104                    txtpwd.Focus();
105                }
106            }
107            private void checkBox1_CheckedChanged(object sender, EventArgs e)
108            {
109                if (checkBox1.Checked)
110                {
111                    btnEnroll.Enabled = true;
112                }
113                else
114                {
115                    btnEnroll.Enabled = false;
116                }
117            }
118            bool isfond1 = false;//控制数字
119            bool isfond2 = false;//控制字母
120            private void txtpwd_KeyPress(object sender, KeyPressEventArgs e)
121            {
122                if (char.IsDigit(e.KeyChar))
123                {
124                    isfond1 = true;
125                }
126                else if (char.IsLetter(e.KeyChar))
127                {
128                    isfond2 = true;
129                }
130                else if (e.KeyChar == 8)
131                {
132                    e.Handled = false;
133                }
134                else
135                {
136                    e.Handled = true;
137                }
138            }
139            /// <summary>
140            /// 注册
141            /// </summary>
142            private void Enroll()
143            {
144                try
145                {
146                    us.Name = txtname.Text;
147                    us.Password = txtpwd.Text;
148                    us.Question = cboquestion.Text;
149                    us.Answer = txtanswer.Text;
150                    ubll.InsertUsers(us);
151                    DialogResult result = MessageBox.Show("(*^__^*) 恭喜您!注册成功,是否关闭该窗口?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
152                    if (result == DialogResult.Yes)
153                    {
154                        this.Close();
155                    }
156                    else
157                    {
158                        tabControl1.SelectedTab = this.tabPage1;
159                        txtname.Text = "";
160                        txtpwd.Text = "";
161                        txtRepwd.Text = "";
162                        cboquestion.Text = "";
163                        txtanswer.Text = "";
164                        txtname.Focus();
165                    }
166                }
167                catch (Exception ee) { MessageBox.Show("错误信息为:" + ee.Message); }
168            }
169            /// <summary>
170            /// 检测是否含有该用户名
171            /// </summary>
172            private void JianCe()
173            {
174                if (ubll.SelUserName(txtname.Text) == 0)
175                {
176                    this.pictureBox1.Visible = true;
177                }
178                else
179                {
180                    MessageBox.Show("对不起!您输入的用户名已存在,请重新输入!");
181                    txtname.Text = "";
182                    txtname.Focus();
183                }
184            }
185        }
186    }
187    

 

posted @ 2013-05-25 22:17  博斯芮网络科技  阅读(259)  评论(0编辑  收藏  举报