📄 modify.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.Text.RegularExpressions;
using System.IO;
namespace renshiguanli
{
public partial class Modify : Form
{
private string pic_selected;
private bool isdate;
private bool issalary;
public Modify()
{
InitializeComponent();
initial();
}
private void initial()
{
Information.sql.set_combobox(comboBox_department);
comboBox_department.Text = Information.employee.DeptID.ToString();
textBox_loginname.Text = Information.employee.LoginName;
textBox_mail.Text = Information.employee.Email;
textBox_name.Text = Information.employee.Name;
textBox_onboardtime.Text = Information.employee.OnbordTime.ToString("yyyy-MM-dd");
textBox_phone.Text = Information.employee.Telephone;
textBox_salary.Text = Information.employee.BasicSalary.ToString();
textBox_title.Text = Information.employee.Title;
numericUpDown_level.Value = (int)Information.employee.EmployeeLevel;
byte[] buffer = (byte[])Information.employee.Image;
if (buffer.Length > 0)
{
MemoryStream ms = new MemoryStream(buffer, true);
ms.Write(buffer, 0, buffer.Length);
Bitmap image = new Bitmap(ms);
ms.Close();
//显示出来
picBox_pic.Image = new Bitmap(image);
}
}
private void button_cancle_Click(object sender, EventArgs e)
{
this.Close();
}
private void button_ok_Click(object sender, EventArgs e)
{
if (textBox_name.Text == "")
{
MessageBox.Show("请输入姓名");
}
else if (textBox_loginname.Text == "")
{
MessageBox.Show("请输入登录名");
}
else if (textBox_salary.Text == "")
{
MessageBox.Show("请输入基本薪资");
}
else if (textBox_title.Text == "")
{
MessageBox.Show("请输入职位");
}
else if (textBox_phone.Text == "")
{
MessageBox.Show("请输入电话号码");
}
else if (textBox_onboardtime.Text == "")
{
MessageBox.Show("请输入出生日期");
}
else if (numericUpDown_level.Value == 0)
{
MessageBox.Show("请输入员工级别");
}
else
{
Regex mail = new Regex(@"^\w{1,20}@\w{1,20}.\w{1,20}");
if (!mail.IsMatch(textBox_mail.Text)&&textBox_mail.Text!="")
{
MessageBox.Show("Email格式错误");
}
else
{
Regex date = new Regex(@"^(?<year>[1-9][0-9]{3})-(?<month>[0-9]{1,2})-(?<day>[0-9]{1,2})$");
if (!date.IsMatch(textBox_onboardtime.Text))
{
MessageBox.Show("出生日期格式错误");
}
else
{
try
{
isdate = true;
Information.employee.OnbordTime = Convert.ToDateTime(textBox_onboardtime.Text);
}
catch
{
isdate = false;
}
if (!isdate)
{
MessageBox.Show("出生日期错误");
}
else
{
try
{
issalary = true;
Information.employee.BasicSalary = Convert.ToInt32(textBox_salary.Text);
}
catch
{
issalary = false;
}
if (!issalary)
{
MessageBox.Show("薪资错误");
}
else
{
Information.employee.Name = textBox_name.Text;
Information.employee.LoginName = textBox_loginname.Text;
Information.employee.Email = textBox_mail.Text;
Information.employee.Title = textBox_title.Text;
Information.employee.DeptID = (int)comboBox_department.SelectedValue;
Information.employee.Telephone = textBox_phone.Text;
Information.employee.EmployeeLevel = (int)numericUpDown_level.Value;
MessageBox.Show("修改成功");
this.DialogResult = DialogResult.OK;
}
}
}
}
}
}
private void btn_pic_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
pic_selected = openFileDialog1.FileName;
picBox_pic.Image = Image.FromFile(pic_selected);
FileStream stream = new FileStream(pic_selected, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, (int)stream.Length);
stream.Close();
Information.employee.Image = buffer;
}
}
private void textBox_onboardtime_Enter(object sender, EventArgs e)
{
toolTip1.Show("输入格式: 2007-01-15", textBox_onboardtime);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -