private void btn_login_Click(object sender, EventArgs e) { objectclass.userinfo.username = txt_user.Text; objectclass.userinfo.password = txt_pwd.Text; string mysql = ""; mysql = string.Format("select * from user where username='******' and password='******'", objectclass.userinfo.username, objectclass.userinfo.password); try { int i = mydb.Rownum(mysql); if (i == 0) { MessageBox.Show("您输入的用户名或密码错误!请重试", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txt_pwd.Text = ""; return; } else { mysql = "select degree from user where username='******'"; objectclass.userinfo.degree = mydb.Returnafield(mysql); this.Hide(); Form myform = new mainform(); myform.Show(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } }
private void mainform_Load(object sender, EventArgs e) { commondb mydb = new commondb(); string mysql = ""; string name = ""; mysql = "select name from worker where worker_num='" + username + "'"; int count = 0; try { count = mydb.Rownum(mysql); if (count > 0) { name = mydb.Returnafield(mysql); lbl_user_num.Text = username; lbl_user_name.Text = name; lbl_admin.Visible = false; } if (degree == "管理员") { lbl_user_num.Text = username; lbl_user_name.Text = ""; lbl_admin.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } }