예제 #1
0
 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());
     }
 }