C# WindowsForm 员工管理系统三【注册】
上一章已经完成了删除用户的功能,现在来完成用户注册功能。
因为是员工管理系统,也就是公司内部使用的,所以应该由公司的管理员为新员工注册账号。
在这之前先创建一个MainForm窗体用来管理系统的所以功能
新建MainForm窗体
将工具栏中ToolStrip控件拖入新建的MainForm窗体,添加五个按钮如图:
更改Form1中跳转程序
MessageBox.Show("系统登录成功,正在跳转主页面...");
MainForm mainForm = new MainForm();
mainForm.Show();
this.Hide();
双击“管理界面”添加
ManagerForm managerForm = new ManagerForm();managerForm.Show();
双击“退出系统”添加
Application.Exit();
新建AddUserForm
包含控件Lable,TextBox,Button,GroupBox,RadioButton,ComboBox
注意:前四个TextBox控件后Lable控件,用来提示用户输入了错误信息
控件Name属性(txtUserName,txtPassword,txtPwdConfirm,txtName,txtAge,cmboxSex,cmboxOffice,rbtNormalUser,rbtAdmin)
编辑cmboxSex,cmboxOffice如图:
这里我们希望ComboBox不可编辑,这样可以避免用户输入一些错误的值造成程序崩溃。解决的方法是将其DropDownStyle属性设置为DropDownList。
双击“注册”按钮,添加事件代码
注意:因为StaffInfo.ID为主键,StaffAccount.ID为外键,所有应先将记录添加到StaffInfo表中,再添加到StaffAccount表中
private void button1_Click(object sender, EventArgs e){string sql = "select Name from StaffAccount where Name='" + txtUserName + "'";string connstr = ConfigurationManager.ConnectionStrings["WindowsFormsApplication6.Properties.Settings.staffConnectionString"].ConnectionString;SqlConnection conn = new SqlConnection(connstr);SqlCommand cmd = new SqlCommand(sql, conn);conn.Open();SqlDataReader sdr = cmd.ExecuteReader();if (sdr.Read()){lblUserMsg.Text = "用户名已存在,请重新输入!";}else if (txtUserName.Text.Trim() == ""){lblUserMsg.Text = "用户名不能为空!";}else if (txtPassword.Text.Trim() == ""){lblPwd.Text = "密码不能为空!";lblPwd.Text = "";}else if (txtPwdConfirm.Text.Trim() == ""){lblPswConfirm.Text = "验证密码不能为空!";lblUserMsg.Text = "";lblPwd.Text = "";}else if (txtPassword.Text.Trim() != txtPwdConfirm.Text.Trim()){lblPwd.Text = "2次密码必须一样!";lblPswConfirm.Text = "请重新输入!";}else if (txtName.Text.Trim() == "" | txtAge.Text.Trim() == "" | cmboxSex.Text == "" | cmboxOffice.Text == ""){lblBaseInfo.Text = "基本信息不完整!";}else {lblUserMsg.Text = "";lblPwd.Text = "";lblPswConfirm.Text = "";lblBaseInfo.Text = "";string uType = "";if (rbtAdmin.Checked)uType = "Administrator";else if (rbtNormalUser.Checked)uType = "NormalUser";elseuType = "NormalUser";conn.Close();string sqlInsert = "insert into StaffAccount(Name,Password,UserType) values(@UserName,@UserPwd,@UserType)";string sqlInsertInfo = "insert into StaffInfo(Name,Sex,Age,Office) values(@Name,@Sex,@Age,@Office)";SqlParameter[] param = {new SqlParameter("@UserName",txtUserName.Text),new SqlParameter("@UserPwd",txtPassword.Text),new SqlParameter("@UserType",uType)};SqlParameter[] paramInfo = {new SqlParameter("@Name",txtName.Text),new SqlParameter("@Age",txtAge.Text),new SqlParameter("@Sex",cmboxSex.Text),new SqlParameter("@Office",cmboxOffice.Text)};SqlConnection connInsert = new SqlConnection(connstr);SqlCommand cmdInsertInfo = new SqlCommand(sqlInsertInfo, connInsert);SqlCommand cmdInsert = new SqlCommand(sqlInsert, connInsert); connInsert.Open();cmdInsertInfo.Parameters.AddRange(paramInfo);cmdInsert.Parameters.AddRange(param);int m = cmdInsertInfo.ExecuteNonQuery();int n = cmdInsert.ExecuteNonQuery();if (n == 0||m==0){MessageBox.Show("注册失败!,请重新输入");return;}else{MainForm mainForm = new MainForm();mainForm.Show();this.Close();MessageBox.Show("注册成功!");}connInsert.Close();}}
双击“返回”按钮
private void button2_Click(object sender, EventArgs e){this.Close();}
运行结果:
C# WindowsForm 员工管理系统三【注册】相关推荐
- 企业员工管理系统 三:工具类
工具类 GlobalConst.java public interface GlobalConst {String DB_NAME="eems.db";String DEPT_TA ...
- 基于springboot+thymeleaf+mybatis的员工管理系统 —— 登录与注册
员工管理系统 - 登录与注册功能 创建项目 pom.xml 数据库表设计和环境准备 建表SQL application.properties 用户注册与登录功能 entity dao service ...
- 狂神Spring Boot 员工管理系统 超详细完整实现教程(小白轻松上手~)
[SpringBoot-web系列]前文: SpringBoot-web开发(一): 静态资源的导入(源码分析) SpringBoot-web开发(二): 页面和图标定制(源码分析) SpringBo ...
- 狂神Spring Boot 员工管理系统 【源码 + 笔记 + web素材】 超详细整理
目录 员工管理系统 1.准备工作 1.1.导入资源 1.2.编写pojo层 1.3.编写dao层 2.首页实现 2.1.引入Thymeleaf 2.2.编写MyMvcConfig 2.3.测试首页 3 ...
- 项目——员工管理系统
开发环境:vmware ubuntu18.04 实现功能:基本功能包括管理者和普通员工用户的登录,管理者拥有操作所有员工信息的最高权限,可以进行增删改 查等操作,普通用户仅拥有查看.修改个人部分信 ...
- Java-SpringBoot:员工管理系统
Java:SpringBoot-员工管理系统 参考的代码和资源链接:https://blog.csdn.net/qq_45173404/article/details/108934414?spm=10 ...
- (附源码)springboot员工管理系统 毕业设计 021430
员工管理系统的设计与实现 摘 要 由于数据库和数据仓库技术的快速发展,企业员工管理系统建设越来越向模块化.智能化.自我服务和管理科学化的方向发展.员工管理系统对处理对象和服务对象,自身的系统结构,处理 ...
- (附源码)ssm物流公司员工管理系统 毕业设计 261625
基于ssm物流公司员工管理系统 摘 要 随着互联网大趋势的到来,社会的方方面面,各行各业都在考虑利用互联网作为媒介将自己的信息更及时有效地推广出去,而其中最好的方式就是建立网络管理系统,并对其进行信 ...
- SpringBoot简易员工管理系统
SpringBoot简易员工管理系统 这里是一个简单的员工管理系统,实现了员工的增删改查,项目的完整讲解视频 请跳转至狂神老师的课程查看https://www.bilibili.com/video/a ...
最新文章
- pandas.read_csv()跳过读取文件报错行
- 一本冷门书:以色列闪盘之父的创业故事
- 利用迁移助手从Oracle迁移到SQL Server
- Nessus更新到8.3.0
- 10. 解析XML文件(SAX/DOM/ElementTre)
- 9月往后推6个月是几月_成考每年一般几月份颁发毕业证书
- 数据库外键的使用原则
- 使用PYTORCH复现ALEXNET实现MNIST手写数字识别
- 文献读的越多,离原创越远
- 使用jemalloc优化java_Jemalloc优化MySQL和Nginx
- 使用动态数据进行数据分页
- Fence Repair (poj3253)
- pytorch之BatchNorm
- ui分离的进程 如何查找窗口句柄_如何使用 Linux screen
- 塔米狗热门项目:杭州北鸿置业有限公司100%股权转让
- 利用计算机名称共享打印机步骤,如何连接共享打印机汇总教程
- NVIDIA SPADE 风景合成
- 毛球科技细说隔离见证
- 浏览器-网页标题的图标
- 2022建筑设计企业申报建筑设计资质流程