📄 frmaddemployee.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using PMS.PMSClass;
using System.Text.RegularExpressions;
namespace PMS
{
public partial class frmAddEmployee : Form
{
public frmAddEmployee()
{
InitializeComponent();
}
DBOperate operate = new DBOperate();
private void toolStripLabel4_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
operate.Read_Image(openFileDialog1, pictureBox1);
}
catch
{
MessageBox.Show("加载图片出错");
}
}
private void frmAddEmployee_Load(object sender, EventArgs e)
{
try
{
operate.BindDropdownlist("tb_department",cbbYGBumen,1);//绑定下拉列表
cbbYGHunyin.SelectedIndex = 0;
cbbYGSex.SelectedIndex = 0;
cbbYGBumen.SelectedIndex = 0;
txtYGminzu.SelectedIndex = 0;
string strg = Application.StartupPath.ToString();
strg = strg.Substring(0, strg.LastIndexOf("\\"));
strg = strg.Substring(0, strg.LastIndexOf("\\"));
strg += @"\PMSImage";
strg += @"\default.jpg";
openFileDialog1.FileName = strg;
operate.BindDropdownlist("tb_userJob",txtYGZhiwu, 1);//绑定所有的职务列表
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void toolStripLabel1_Click(object sender, EventArgs e)
{
if (txtYGBirthday.Text.Trim() == "" || txtYGJiuzhi.Text.Trim() == "" || txtYGminzu.Text.Trim() == "" || txtYGName.Text.Trim() == "" || txtYGNum.Text.Trim() == "" || txtYGPhone.Text.Trim() == "" || txtYGZhiwu.Text.Trim() == ""||txtYGPay.Text.Trim()=="")
{
MessageBox.Show("请将信息填写完整", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
if (txtYGPhone.Text.Length != 11)
{
MessageBox.Show("手机号码为11位");
return;
}
else
{
string str = "select count(*) from tb_employee where employeeID='" + txtYGNum.Text + "'";
int i = operate.HumanNum(str);
if (i > 0)
{
MessageBox.Show("该员工编号已经存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
string strSql = "insert into tb_employee(employeeID,employeeName,employeeSex,employeeDept,employeeBirthday,employeeNation,employeeMarriage,employeeDuty,employeePhone,employeeAccession,employeePay) values('" + txtYGNum.Text.Trim() + "','" + txtYGName.Text.Trim() + "','" + cbbYGSex.Text + "','" + cbbYGBumen.Text + "','" + txtYGBirthday.Text + "','" + txtYGminzu.Text.Trim() + "','" + cbbYGHunyin.Text + "','" + txtYGZhiwu.Text.Trim() + "','" + txtYGPhone.Text.Trim() + "','" + txtYGJiuzhi.Text + "','" + txtYGPay.Text.Trim() + "')";
int num = operate.OperateData(strSql);
operate.SaveImage(this.txtYGNum.Text.Trim(), openFileDialog1);
if (num > 0)
{
MessageBox.Show("员工信息添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
}
private void txtYGNum_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != 8 && !char.IsDigit(e.KeyChar))
{
MessageBox.Show("只能输入数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
e.Handled = true;
}
}
private void txtYGNum_TextChanged(object sender, EventArgs e)
{
string str = "select count(*) from tb_employee where employeeID='" + this.txtYGNum.Text.Trim() + "'";
int m = operate.HumanNum(str);
if (m > 0)
{
MessageBox.Show("员工编号存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
private void txtYGPhone_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != 8 && !char.IsDigit(e.KeyChar))
{
MessageBox.Show("只能输入数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
e.Handled = true;
}
}
private void txtYGPay_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != 8 && !char.IsDigit(e.KeyChar))
{
MessageBox.Show("只能输入数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
e.Handled = true;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -