📄 frmoperator.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using PMS.PMSClass;
namespace PMS
{
public partial class frmOperator : Form
{
public frmOperator()
{
InitializeComponent();
}
DBOperate operate = new DBOperate();
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void frmOperator_Load(object sender, EventArgs e)
{
string getUser = "select UserName as '用户名',UserPwd as '密码',UserPower as '权限' from tb_User";
operate.BindDataGridView(dataGridView1,getUser);
dataGridView1.Columns[0].Width = 88;
dataGridView1.Columns[1].Width = 85;
dataGridView1.Columns[2].Width = 88;
comboBox1.SelectedIndex = 0;
}
private void 增加ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
txtOUser.Enabled = true;
txtOPwd.Enabled = true;
comboBox1.Enabled = true;
string str = "select count(*) from tb_User where UserName='"+txtOUser.Text.Trim()+"'";
int i = operate.HumanNum(str);
if (i > 0)
{
MessageBox.Show("操作员存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
if (txtOUser.Text.Trim() == "" || txtOPwd.Text.Trim() == "")
{
MessageBox.Show("信息不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
string InsertSql = "insert into tb_User(UserName,UserPwd,UserPower) values('" + txtOUser.Text.Trim() + "','" + txtOPwd.Text.Trim() + "','" + comboBox1.Text + "')";
operate.OperateData(InsertSql);
txtOPwd.Text = "";
txtOUser.Text = "";
MessageBox.Show("增加操作员成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch
{
MessageBox.Show("增加操作员失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
string name=dataGridView1.SelectedCells[0].Value.ToString();
string str = "select * from tb_User where UserName='"+name+"'";
DataSet ds = operate.GetTable(str);
ds.Dispose();
txtOUser.Text = ds.Tables[0].Rows[0][1].ToString();
txtOPwd.Text = ds.Tables[0].Rows[0][2].ToString();
comboBox1.SelectedItem = ds.Tables[0].Rows[0][3].ToString();
}
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedCells.Count == 0)
{
MessageBox.Show("请选择要删除的管理员", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
string username = dataGridView1.SelectedCells[0].Value.ToString();
string strsql = "delete from tb_User where UserName='"+username+"'";
operate.OperateData(strsql);
MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void frmOperator_Activated(object sender, EventArgs e)
{
frmOperator_Load(sender, e);
}
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (txtOUser.Text.Trim() == "" || txtOPwd.Text.Trim() == "")
{
MessageBox.Show("信息不完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
string str = "select count(*) from tb_User where UserName='" + txtOUser.Text.Trim() + "'";
int i = operate.HumanNum(str);
if (i > 0)
{
string updatestr = "update tb_User set UserPwd='" + txtOPwd.Text.Trim() + "',UserPower='" + comboBox1.Text + "' where UserName='" + txtOUser.Text.Trim() + "'";
operate.OperateData(updatestr);
MessageBox.Show("信息修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtOPwd.Text = "";
txtOUser.Text = "";
}
else
{
MessageBox.Show("指定用户不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -