📄 frmaddpay.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.Xml;
namespace HumanManage.HumanManage
{
public partial class FrmAddPay : Form
{
public static string empSex = "";
public static string empJop = "";
public static string empDept = "";
private static XmlDocument AddPay = new XmlDocument();
private static XmlDocument EmpInfo = new XmlDocument();
public FrmAddPay()
{
InitializeComponent();
}
private void FrmAddPay_Load(object sender, EventArgs e)
{
EmpInfo.Load("..\\..\\xmlAddEmp.xml");
AddPay.Load("..\\..\\xmlRedressalPay.xml");
XmlNodeList IdList = EmpInfo.SelectNodes("//新员工");
foreach (XmlNode ID in IdList)
{
this.cmbId.Items.Add(ID.Attributes["员工编号"].Value);
}
}
private void btnSave_Click(object sender, EventArgs e)
{
//获得具有[员工编号]属性的[员工]节点
XmlNode MyEmpPay = AddPay.SelectSingleNode("//员工调薪[@员工编号='" + cmbId.Text + "']");
if (MyEmpPay == null)
{
XmlDocumentFragment GOGO = AddPay.CreateDocumentFragment();
XmlElement GOEmp = AddPay.CreateElement("员工调薪");
XmlAttribute MyAtt = AddPay.CreateAttribute("员工编号");
MyAtt.Value = cmbId.Text;
GOEmp.SetAttributeNode(MyAtt);
//创建一个<姓名>节点
XmlElement Name = AddPay.CreateElement("姓名");
Name.InnerText = lblName.Text;
//创建一个<性别>节点
XmlElement Sex = AddPay.CreateElement("性别");
Sex.InnerText = empSex;
//创建一个<部门>节点
XmlElement Dept = AddPay.CreateElement("部门");
Dept.InnerText = empDept;
//创建一个<职位>节点
XmlElement Jop = AddPay.CreateElement("职位");
Jop.InnerText = empJop;
//创建一个<调前薪资>节点
XmlElement OldPay = AddPay.CreateElement("调前薪资");
OldPay.InnerText = lblOldPay.Text;
//创建一个<调后薪资>节点
XmlElement NewPay = AddPay.CreateElement("调后薪资");
NewPay.InnerText = txtNewPay.Text;
//创建一个<调动日期>节点
XmlElement NewTime = AddPay.CreateElement("调薪日期");
NewTime.InnerText = dateTimeNewPay.Text;
//创建一个<调动原因>节点
XmlElement PayWhy = AddPay.CreateElement("调动原因");
PayWhy.InnerText = txtWhy.Text;
//创建一个<备注信息>节点
XmlElement PayInfo = AddPay.CreateElement("备注信息");
PayInfo.InnerText = txtPayInfo.Text;
GOEmp.AppendChild(Name);
GOEmp.AppendChild(Sex);
GOEmp.AppendChild(Dept);
GOEmp.AppendChild(Jop);
GOEmp.AppendChild(OldPay);//4
GOEmp.AppendChild(NewPay);
GOEmp.AppendChild(NewTime);
GOEmp.AppendChild(PayWhy);
GOEmp.AppendChild(PayInfo);
GOGO.AppendChild(GOEmp);
XmlNode Manage = AddPay.SelectSingleNode("//人事管理");
Manage.AppendChild(GOGO);
}
else
{
MyEmpPay.ChildNodes[4].InnerText = lblOldPay.Text;
MyEmpPay.ChildNodes[5].InnerText = txtNewPay.Text;
MyEmpPay.ChildNodes[6].InnerText = dateTimeNewPay.Text;
MyEmpPay.ChildNodes[7].InnerText = txtWhy.Text;
MyEmpPay.ChildNodes[8].InnerText = txtPayInfo.Text;
}
//修改总信息的部门和职位
XmlNode Information = EmpInfo.SelectSingleNode("//新员工[@员工编号='" + cmbId.Text + "']");
Information.ChildNodes[19].InnerText = txtNewPay.Text;
EmpInfo.Save("..\\..\\xmlAddEmp.xml");
AddPay.Save("..\\..\\xmlRedressalPay.xml");
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
/// <summary>
/// 选择编号后显示员工信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cmbId_SelectedIndexChanged(object sender, EventArgs e)
{
XmlNode Name = EmpInfo.SelectSingleNode("//新员工[@员工编号='" + cmbId.Text + "']");
lblName.Text = Name.ChildNodes[0].InnerText;
empSex = Name.ChildNodes[1].InnerText;
lblOldPay.Text = Name.ChildNodes[19].InnerText;
empJop = Name.ChildNodes[18].InnerText;
empDept = Name.ChildNodes[15].InnerText;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -