考勤系统的登录与录入
登录界面
image.png1)登录界面代码
// 点击“登录”按钮则登录系统
private void bt_Login_Click(object sender, EventArgs e)
{
String connStr = ConfigurationManager.ConnectionStrings["Attendance"].ConnectionString;
SqlConnection sqlConn = new SqlConnection(connStr);
try
{
// 连接数据库
sqlConn.Open();
// 构造命令发送给数据库
String sqlStr = "select * from EMPLOYEE where ID=@id and PASSWORD=@pwd";
SqlCommand cmd = new SqlCommand(sqlStr, sqlConn);
// 注意是用用户ID登录,而不是用户名,用户名可能会重复
cmd.Parameters.Add(new SqlParameter("@id", this.tb_User.Text.Trim()));
cmd.Parameters.Add(new SqlParameter("@pwd", this.tb_Password.Text.Trim()));
SqlDataReader dr = cmd.ExecuteReader();
录入界面
image.png1)录入界面代码
private void RecordForm_Load(object sender, EventArgs e)
{
tb_gender.SelectedIndex = 0;
// tb_department.SelectedIndex = 0;
tb_role.SelectedIndex = 0;
String connStr = ConfigurationManager.ConnectionStrings["Attendance"].ConnectionString;
SqlConnection sqlConn = new SqlConnection(connStr);
sqlConn.Open();
String sqlStr0 = "select MAX(id+1) as id from employee";
SqlCommand cmd = new SqlCommand(sqlStr0, sqlConn);
SqlDataReader co = cmd.ExecuteReader();
if (co.HasRows)
{
co.Read();
tb_id.Text = co["ID"].ToString();
}
sqlConn.Close();
sqlConn.Open();
String sqlStr1 = "select distinct (department) from employee";
SqlCommand com = new SqlCommand(sqlStr1, sqlConn);
SqlDataReader xo = com.ExecuteReader();
if (xo.HasRows)
{
while (xo.Read())
tb_department.Items.Add(xo["department"].ToString());
}
tb_department.SelectedIndex = 0;
sqlConn.Close();
}
private void tb_department_SelectedIndexChanged(object sender, EventArgs e)
{
注册界面
image.png1)注册信息代码
private void 注册员工信息ToolStripMenuItem_Click(object sender, EventArgs e)
{
RecordForm coco = new RecordForm();
coco.MdiParent = this;
coco.Show();
}
1)数据库
image.png
2)数据库查询界面
image.png
网友评论