private void 除用户ToolStripMenuItem_Click(object sender, EventArgs e) { try { if (dataGridView1.SelectedRows != null) { DialogResult dialogResult = MessageBox.Show("是否删除用户" + dataGridView1.SelectedRows[0].Cells[1].Value.ToString() + "?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dialogResult == DialogResult.OK) { if (dataGridView1.SelectedRows[0].Cells[3].Value.ToString() == "管理员") { MessageBox.Show("无法删除管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { Sqloperate sqloperate = new Sqloperate(); //sqloperate.SqlCommands("delete from tb_user where UserName='******' and where UserPwd='"+dataGridView1.SelectedRows[0].Cells[1].Value.ToString()+"' and where LoginTime='"+dataGridView1.SelectedRows[0].Cells[2].Value.ToString()+"' and where UserPower='"+dataGridView1.SelectedRows[0].Cells[3].Value.ToString()+"'"); sqloperate.SqlCommands("delete from tb_user where UserId='" + dataGridView1.SelectedRows[0].Cells[0].Value + "'"); UpdateGrid ug = new UpdateGrid(UpDateGridView); ug.Invoke(); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// 密码登录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void passwordbtn_Click(object sender, EventArgs e) { try { if (txtUserName.Text == "" || txtPassWord.Text == "") { MessageBox.Show("用户名或密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { //输入用户名 username = txtUserName.Text.Trim(); //输入密码 userpwd = txtPassWord.Text.Trim(); //定义连接数据库的字符串 string conStr = "Data Source='101.200.210.193'; Initial Catalog=db_WMS;User ID=sa;Password=1010"; SqlConnection conn = new SqlConnection(conStr); conn.Open(); //创建数据库命令对象 SqlCommand command = new SqlCommand("select * from tb_user where UserName='******' and UserPwd='" + userpwd + "'",conn); //创建数据库读取器对象 SqlDataReader reader = command.ExecuteReader(); //读取一条记录 reader.Read(); if (reader.HasRows)//判断是否包含数据 { string time = DateTime.Now.ToString(); string sql = "update tb_user set LoginTime='" + time + "' where UserName='******'"; Sqloperate sqloperate = new Sqloperate(); sqloperate.SqlCommands(sql); conn.Close(); this.Hide(); UserCenter userCenter = new UserCenter(); UserCenter.userCenter.Show(); } else { txtUserName.Text = ""; txtPassWord.Text = ""; MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }