C# winfrom人事管理系统带源码和文档
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/983ef20054554754ba773604ca196c7c.png)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 人事管理系统
{
public partial class Admin : Form
{
private string mID = "";
public string ID
{
get
{
return mID;
}
set
{
mID = value;
}
}
public Admin()
{
InitializeComponent();
}
private void Admin_Load(object sender, EventArgs e)
{
if (mID != "")
{
DataTable dt = new DataTable();
dt = DBHelper.GetDataSet("select * from TB_Admin where ID='" + mID + "'").Tables[0];
if (dt.Rows.Count > 0)
{
this.textBox1.Text = dt.Rows[0]["UserName"].ToString();
this.textBox2.Text = dt.Rows[0]["PassWord"].ToString();
this.textBox1.ReadOnly = true;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
if (mID == "")
{
if (this.textBox1.Text == "")
{
MessageBox.Show("编号不能为空");
return;
}
if (DBHelper.GetDataSet("select * from TB_YuanGong where UserName='" + textBox1.Text + "'").Tables[0].Rows.Count > 0)
{
MessageBox.Show("用户名重复");
return;
}
DBHelper.ExecSql("INSERT INTO TB_YuanGong (UserName ,PassWord ) VALUES ('" + textBox1.Text + "','" + textBox2.Text + "')"); MessageBox.Show("操作成功");
}
else
{
//修改
DBHelper.ExecSql("UPDATE TB_YuanGong set UserName = '" + textBox1.Text + "',PassWord = '" + textBox2.Text + "' WHERE ID='" + mID + "' ");
this.Close();
}
}
}
}