using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace FrmManagement_System
{
public partial class FrmInsert : Form
{
DBHelper helper = new DBHelper();
public FrmInsert()
{
InitializeComponent();
}
#region 去登录
private void btnLogin1_Click(object sender, EventArgs e)
{
FrmLogin login = new FrmLogin();
login.Show();
this.Hide();
}
#endregion
private void btnSave_Click(object sender, EventArgs e)
{
if (Insert()==true)
{
InsertInto();
}
}
private void InsertInto()
{
try
{
helper.OpenConnection();
string sql = string.Format(@"INSERT INTO [Login]
([UserName]
,[passWord]
,[pwd]
,[Email])
VALUES
('{0}'
,'{1}'
,'{2}',
'{3}')", this.txtName.Text.Trim(), this.txtPass.Text.Trim(), this.txtPwd.Text.Trim(),this.txtEmail.Text.Trim());
SqlCommand comm = new SqlCommand(sql, helper.Connection);
int iRet=comm.ExecuteNonQuery();
if (iRet>0)
{
MessageBox.Show("添加成功");
}
else
{
MessageBox.Show("添加失败");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
helper.CloseConnection();
}
}
private bool Insert()
{
if (this.txtPass.Text.Trim()==string.Empty)
{
MessageBox.Show("密码不为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
if (this.txtName.Text.Trim() == string.Empty)
{
MessageBox.Show("用户名不为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
if (this.txtPwd.Text.Trim() == string.Empty)
{
MessageBox.Show("确认密码不为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
if (this.txtEmail.Text.Trim() == string.Empty)
{
MessageBox.Show("邮箱不为空", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
if (this.txtPwd.Text.Trim()!=this.txtPass.Text.Trim())
{
MessageBox.Show("两次密码不正确", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
return true;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace FrmManagement_System
{
public partial class FrmLogin : Form
{
DBHelper helper = new DBHelper();
public FrmLogin()
{
InitializeComponent();
}
#region 取消
private void btnclose_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确认取消登录吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result==DialogResult.Yes)
{
Application.Exit();
}
}
#endregion
#region 注册
private void btnenroll_Click(object sender, EventArgs e)
{
FrmInsert insert = new FrmInsert();
insert.Show();
this.Hide();
}
#endregion
#region 登录
private void btnLogin_Click(object sender, EventArgs e)
{
if (Login()==true)
{
LoginP();
}
}
private bool LoginP()
{
try
{
helper.OpenConnection();
String sql = string.Format(@"SELECT [id]
,[UserName]
,[passWord]
FROM [Login]
where UserName='{0}' and passWord='{1}'",this.txtName.Text.Trim(),this.txtPass.Text.Trim());
SqlCommand comm = new SqlCommand(sql, helper.Connection);
int iRet=Convert.ToInt32(comm.ExecuteScalar());
if (iRet>0)
{
MessageBox.Show("登录成功");
FrmMangment Mangment = new FrmMangment();
Mangment.User = this.txtName.Text.Trim();
Mangment.Pwd = this.txtPass.Text.Trim();
Mangment.Show();
this.Hide();
return true;
}
else
{
MessageBox.Show("登录失败");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
finally
{
helper.CloseConnection();
}
return true;
}
#endregion
#region 登录判断
private bool Login()
{
if (this.txtName.Text.Trim().Equals(string.Empty)&&this.txtPass.Text.Trim().Equals(string.Empty))
{
MessageBox.Show("请输入用户名密码", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (this.txtName.Text.Trim().Equals(string.Empty) && this.txtPass.Text.Trim()!=string.Empty)
{
MessageBox.Show("请输入用户名密码", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (this.txtPass.Text.Trim().Equals(string.Empty) && this.txtName.Text.Trim() != string.Empty)
{
MessageBox.Show("请输入用户名密码", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
return true;
}
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FrmManagement_System
{
public partial class FrmMangment : Form
{
public String User=String.Empty;
public String Pwd = string.Empty;
public FrmMangment()
{
InitializeComponent();
}
#region 关于
private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
{
concerning con = new concerning();
con.ShowDialog();
}
#endregion
#region 退出
private void 退出ZToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确认退出吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
Application.Exit();
}
}
#endregion
private void FrmMangment_Load(object sender, EventArgs e)
{
}
private void TsUpdate_Click(object sender, EventArgs e)
{
FrmUpdate update = new FrmUpdate();
update.pwd = this.Pwd;
update.name = this.User;
update.Show();
}
private void 添加教师IToolStripMenuItem_Click(object sender, EventArgs e)
{
InsertINto insert = new InsertINto();
insert.Show();
}
private void 减少教师DToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmDelete select = new FrmDelete();
select.Show();
}
private void 查询教师ToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmSelect select = new FrmSelect();
select.Show();
}
private void 查询工资YToolStripMenuItem_Click(object sender, EventArgs e)
{
Frmselectmoney money = new Frmselectmoney();
money.Show();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace FrmManagement_System
{
public partial class FrmSelect : Form
{
DBHelper helper = new DBHelper();
DataView dv = null;
DataSet ds = null;
SqlDataAdapter adapter = null;
public FrmSelect()
{
InitializeComponent();
}
private void TsDelete_Click(object sender, EventArgs e)
{
try
{
helper.OpenConnection();
string sql = String.Format(@"DELETE FROM [Teacher]
WHERE teacherNo={0}",this.dataGridView1.CurrentRow.Cells[0].Value);
SqlCommand comm = new SqlCommand(sql,helper.Connection);
int iRet = comm.ExecuteNonQuery();
if (iRet>0)
{
MessageBox.Show("删除成功");
this.Hide();
}
else
{
MessageBox.Show("删除失败");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
helper.CloseConnection();
}
}
private void FrmSelect_Load(object sender, EventArgs e)
{
this.cboGender.Text = "请选择";
string sql = string.Format(@"SELECT [teacherNo]as '教师编号'
,[departmentNo]as '部门编号'
,[name]as '教师姓名'
,[gender]as '性别'
,[age]as '年龄'
,stuStatusName as '学校名称'
,aducationName as '学历名称'
,[birthday]as '出生日期'
,[teachching]as '授课'
FROM [Teacher] inner join School on School.stuStatusNo=Teacher.stuStatusNo
inner join Aducation on Teacher.aducationNo=Aducation.aducationNo
");
adapter = new SqlDataAdapter(sql, helper.Connection);
ds = new DataSet();
if (ds.Tables["Teacher"] != null)
{
ds.Tables["Teacher"].Clear();
}
adapter.Fill(ds, "Teacher");
dv = new DataView(ds.Tables["Teacher"]);
this.dataGridView1.DataSource = dv;
}
private void btnExit_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确认退出吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result==DialogResult.Yes)
{
Application.Exit();
}
}
private void btnClear_Click(object sender, EventArgs e)
{
this.txtName.Clear();
this.txtNo.Clear();
this.txtteachching.Clear();
this.cboGender.Text="请选择";
}
private void btnselect_Click(object sender, EventArgs e)
{
if (this.txtNo.Text.Trim() != string.Empty && this.txtName.Text.Trim() == string.Empty && this.txtteachching.Text.Trim() == string.Empty && this.cboGender.Text == "请选择")
{
selectNo();
}else
if (this.txtNo.Text.Trim() == string.Empty && this.txtName.Text.Trim() != string.Empty && this.txtteachching.Text.Trim() == string.Empty && this.cboGender.Text == "请选择")
{
selectName();
}else
if (this.txtNo.Text.Trim() == string.Empty && this.txtName.Text.Trim() == string.Empty && this.txtteachching.Text.Trim() != string.Empty && this.cboGender.Text == "请选择")
{
selectteachching();
}else
if (this.txtNo.Text.Trim() == string.Empty && this.txtName.Text.Trim() == string.Empty && this.txtteachching.Text.Trim() == string.Empty && this.cboGender.Text != "请选择")
{
selectCbo();
}
else
{
this.FrmSelect_Load(sender, e);
}
}
private void selectCbo()
{
string sql = string.Format(@"SELECT [teacherNo]as '教师编号'
,[departmentNo]as '部门编号'
,[name]as '教师姓名'
,[gender]as '性别'
,[age]as '年龄'
,stuStatusName as '学校名称'
,aducationName as '学历名称'
,[birthday]as '出生日期'
,[teachching]as '授课'
FROM [Teacher] inner join School on School.stuStatusNo=Teacher.stuStatusNo
inner join Aducation on Teacher.aducationNo=Aducation.aducationNo
where gender ='{0}'", this.cboGender.Text.Trim());
adapter = new SqlDataAdapter(sql, helper.Connection);
ds = new DataSet();
adapter.Fill(ds, "Teacher");
dv = new DataView(ds.Tables["Teacher"]);
this.dataGridView1.DataSource = dv;
}
private void selectName()
{
string sql = string.Format(@"SELECT [teacherNo]as '教师编号'
,[departmentNo]as '部门编号'
,[name]as '教师姓名'
,[gender]as '性别'
,[age]as '年龄'
,stuStatusName as '学校名称'
,aducationName as '学历名称'
,[birthday]as '出生日期'
,[teachching]as '授课'
FROM [Teacher] inner join School on School.stuStatusNo=Teacher.stuStatusNo
inner join Aducation on Teacher.aducationNo=Aducation.aducationNo
where name='{0}'", this.txtName.Text.Trim());
adapter = new SqlDataAdapter(sql, helper.Connection);
ds = new DataSet();
adapter.Fill(ds, "Teacher");
dv = new DataView(ds.Tables["Teacher"]);
this.dataGridView1.DataSource = dv; ;
}
private void selectteachching()
{
string sql = string.Format(@"SELECT [teacherNo]as '教师编号'
,[departmentNo]as '部门编号'
,[name]as '教师姓名'
,[gender]as '性别'
,[age]as '年龄'
,stuStatusName as '学校名称'
,aducationName as '学历名称'
,[birthday]as '出生日期'
,[teachching]as '授课'
FROM [Teacher] inner join School on School.stuStatusNo=Teacher.stuStatusNo
inner join Aducation on Teacher.aducationNo=Aducation.aducationNo
where teachching='{0}'
", this.txtteachching.Text.Trim());
adapter = new SqlDataAdapter(sql, helper.Connection);
ds = new DataSet();
adapter.Fill(ds, "Teacher");
dv = new DataView(ds.Tables["Teacher"]);
this.dataGridView1.DataSource = dv;
}
private void selectNo()
{
string sql =string.Format(@"SELECT [teacherNo]as '教师编号'
,[departmentNo]as '部门编号'
,[name]as '教师姓名'
,[gender]as '性别'
,[age]as '年龄'
,stuStatusName as '学校名称'
,aducationName as '学历名称'
,[birthday]as '出生日期'
,[teachching]as '授课'
FROM [Teacher] inner join School on School.stuStatusNo=Teacher.stuStatusNo
inner join Aducation on Teacher.aducationNo=Aducation.aducationNo
where teacherNo={0}",this.txtNo.Text.Trim());
adapter = new SqlDataAdapter(sql, helper.Connection);
ds = new DataSet();
adapter.Fill(ds, "Teacher");
dv = new DataView(ds.Tables["Teacher"]);
this.dataGridView1.DataSource = dv;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace FrmManagement_System
{
public partial class FrmUpdate : Form
{
DBHelper helper = new DBHelper();
public String name=string.Empty;
public String pwd = string.Empty;
public FrmUpdate()
{
InitializeComponent();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
if (Update1()==true)
{
if (Updatpwd()==true)
{
}
}
}
private bool Update1()
{
if (this.txtPwd.Text.Trim()==string.Empty)
{
MessageBox.Show("请输入原密码?", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
if (this.txtpass.Text.Trim() == string.Empty)
{
MessageBox.Show("请输入新密码?", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
if (this.txtlblPassWord.Text.Trim() == string.Empty)
{
MessageBox.Show("请输入确认新密码?", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
if (this.txtPwd.Text.Trim() !=this.pwd)
{
MessageBox.Show("原密码不正确", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
if (this.txtpass.Text.Trim() != this.txtlblPassWord.Text.Trim())
{
MessageBox.Show("两次新密码不相等?", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
return true;
}
private bool Updatpwd()
{
try
{
helper.OpenConnection();
string sql = string.Format(@"UPDATE [Login]
SET [UserName] = '{0}'
,[passWord] ='{1}'
WHERE id=1",this.name,this.txtpass.Text.Trim());
SqlCommand comm = new SqlCommand(sql, helper.Connection);
int iRet = comm.ExecuteNonQuery();
if (iRet>0)
{
MessageBox.Show("修改成功");
this.Hide();
}
else
{
MessageBox.Show("修改失败");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
helper.CloseConnection();
}
return true;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace FrmManagement_System
{
public partial class InsertINto : Form
{
DBHelper helper=new DBHelper();
DataView dv = null;
DataView cbo = null;
DataSet ds = null;
SqlDataAdapter adapter = null;
public InsertINto()
{
InitializeComponent();
}
private void btnClear_Click(object sender, EventArgs e)
{
this.txtage.Clear();
this.txtdepartmentNo.Clear();
this.txtName.Clear();
this.txtteachching.Clear();
this.txtteacherNo.Clear();
this.cboaducation.Text = "请选择";
this.cbogender.Text = "请选择";
this.cbostuStatusName.Text = "请选择";
}
private void InsertINto_Load(object sender, EventArgs e)
{
this.cbogender.Text = "请选择";
cboBand();
cboBand1();
}
private void cboBand1()
{
//SQL语句
String sql = @"SELECT [aducationNo]
,[aducationName]
FROM [Aducation]";
//填充
adapter = new SqlDataAdapter(sql, helper.Connection);
ds = new DataSet();
adapter.Fill(ds, "Aducation");
//创建新行
DataRow row = ds.Tables["Aducation"].NewRow();
row[0] = "-1";
row[1] = "请选择";
ds.Tables["Aducation"].Rows.InsertAt(row, 0);
//创建视图
dv = new DataView(ds.Tables["Aducation"]);
//绑定视图
cboaducation.DataSource = dv;
cboaducation.DisplayMember = "aducationName";
cboaducation.ValueMember = "aducationNo";
}
private void cboBand()
{
//SQL语句
String sql = @"SELECT [stuStatusNo]
,[stuStatusName]
FROM [School]";
//填充
adapter = new SqlDataAdapter(sql, helper.Connection);
ds = new DataSet();
adapter.Fill(ds, "School");
//创建新行
DataRow row = ds.Tables["School"].NewRow();
row[0] = "-1";
row[1] = "请选择";
ds.Tables["School"].Rows.InsertAt(row, 0);
//创建视图
dv = new DataView(ds.Tables["School"]);
//绑定视图
cbostuStatusName.DataSource = dv;
cbostuStatusName.DisplayMember = "stuStatusName";
cbostuStatusName.ValueMember = "stuStatusNo";
}
private void btnInsert_Click(object sender, EventArgs e)
{
String lblteacherNo=this.txtteacherNo.Text.Trim();
string lbldepartmentNo=this.txtdepartmentNo.Text.Trim();
string lblName=this.txtName.Text.Trim();
string lblgender=this.cbogender.Text.ToString();
int lblstuStatusName=Convert.ToInt32(this.cbostuStatusName.SelectedValue.ToString());
int lbladucation= Convert.ToInt32(this.cboaducation.SelectedValue.ToString());
//时间类型获取
DateTime date = this.dateTimePicker1.Value;
string birthday = String.Format("{0}-{1}-{2}", date.Year, date.Month, date.Day);//拼接字符串
string lblteachching=this.txtteachching.Text.Trim();
int lblage=Convert.ToInt32(this.txtage.Text.Trim());
try
{
helper.OpenConnection();
string sql = string.Format(@"INSERT INTO [Management System].[dbo].[Teacher]
([teacherNo]
,[departmentNo]
,[name]
,[gender]
,[age]
,[stuStatusNo]
,[aducationNo]
,[birthday]
,[teachching])
VALUES
('{0}'
,'{1}'
,'{2}'
,'{3}'
,{4}
,{5}
,{6}
,'{7}'
,'{8}')", lblteacherNo, lbldepartmentNo,lblName,lblgender,lblage,lblstuStatusName,lbladucation,birthday,lblteachching);
SqlCommand comm = new SqlCommand(sql, helper.Connection);
int iRet = comm.ExecuteNonQuery();
if (iRet>0)
{
MessageBox.Show("添加成功");
this.Hide();
}
else
{
MessageBox.Show("添加失败");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
helper.CloseConnection();
}
}
}
}
C#高校人力管理系统
最新推荐文章于 2025-05-31 11:17:57 发布
本文探讨了如何使用C#编程语言开发高效的高校人力管理系统。内容涉及系统设计、功能实现以及C#相较于Java的独特优势。通过实例,展示了C#在数据处理、界面交互等方面的高效性能。

2103

被折叠的 条评论
为什么被折叠?



