📄 frmaddrewpun.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 FrmAddRewPun : Form
{
private static XmlDocument Doc = new XmlDocument();
private static XmlDocument Info = new XmlDocument();
public static string _dept = "";
public static string _jop = "";
public static string _sex = "";
public FrmAddRewPun()
{
InitializeComponent();
}
/// <summary>
/// 获取所有员工编号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmAddRewPun_Load(object sender, EventArgs e)
{
Doc.Load("..\\..\\xmlAddEmp.xml");
Info.Load("..\\..\\xmlRewardsAndPun.xml");
XmlNodeList IdList = Doc.SelectNodes("//新员工");
foreach (XmlNode ID in IdList)
{
this.cmbId.Items.Add(ID.Attributes["员工编号"].Value);
}
}
private void cmbId_SelectedIndexChanged(object sender, EventArgs e)
{
XmlNode Name = Doc.SelectSingleNode("//新员工[@员工编号='" + cmbId.Text + "']");
lblName.Text = Name.ChildNodes[0].InnerText;
_sex = Name.ChildNodes[1].InnerText;
_dept = Name.ChildNodes[15].InnerText;
_jop = Name.ChildNodes[18].InnerText;
}
private void btnSave_Click(object sender, EventArgs e)
{
//获得具有[员工编号流水号]属性的[添加员工]节点
XmlNode MynodeId = Info.SelectSingleNode("//员工奖惩信息[@条数流水号]");
//获取当前[员工编号流水号]的值
int PunIds = int.Parse(MynodeId.Attributes["条数流水号"].Value);
PunIds++;
MynodeId.Attributes["条数流水号"].Value = PunIds.ToString();
XmlDocumentFragment Pun = Info.CreateDocumentFragment();
XmlElement PunEmp = Info.CreateElement("员工");
XmlAttribute MyAtt = Info.CreateAttribute("员工编号");
MyAtt.Value = cmbId.Text + PunIds.ToString();
PunEmp.SetAttributeNode(MyAtt);
//创建一个<姓名>节点
XmlElement Name = Info.CreateElement("姓名");
Name.InnerText = lblName.Text;
//创建一个<性别>节点
XmlElement Sex = Info.CreateElement("性别");
Sex.InnerText = _sex;
//创建一个<部门>节点
XmlElement Dept = Info.CreateElement("部门");
Dept.InnerText = _dept;
//创建一个<职位>节点
XmlElement Jop = Info.CreateElement("职位");
Jop.InnerText = _jop;
//创建一个<奖惩日期>节点
XmlElement PunDate = Info.CreateElement("奖惩日期");
PunDate.InnerText = dateTime.Text;
//创建一个<奖惩类别>节点
XmlElement PunSort = Info.CreateElement("奖惩类别");
PunSort.InnerText = cmbSort.Text;
//创建一个<奖惩分数>节点
XmlElement PunMark = Info.CreateElement("奖惩分数");
PunMark.InnerText = txtMarks.Text;
//创建一个<奖惩原因>节点
XmlElement PunWhy = Info.CreateElement("奖惩原因");
PunWhy.InnerText = cmbWhy.Text;
//创建一个<备注信息>节点
XmlElement PunInfo = Info.CreateElement("备注信息");
PunInfo.InnerText = txtInfo.Text;
PunEmp.AppendChild(Name);
PunEmp.AppendChild(Sex);
PunEmp.AppendChild(Dept);
PunEmp.AppendChild(Jop);
PunEmp.AppendChild(PunDate);
PunEmp.AppendChild(PunSort);
PunEmp.AppendChild(PunMark);
PunEmp.AppendChild(PunWhy);
PunEmp.AppendChild(PunInfo);
Pun.AppendChild(PunEmp);
XmlNode Node = Info.SelectSingleNode("//员工奖惩信息[@条数流水号]");
Node.AppendChild(Pun);
Info.Save("..\\..\\xmlRewardsAndPun.xml");
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -