private void gridViewModrecord_OnAddNew(object sender, EventArgs e) { var objXmlDoc = xmldicthelper.GetXmlDoc(); XmlNode objNode = objXmlDoc.SelectSingleNode("datatype/histories"); ModRecordInfo modrecoreInfo = new ModRecordInfo(); modrecoreInfo.GUID = Guid.NewGuid().ToString(); modrecoreInfo.ModDate = DateTimeHelper.GetServerDateTime2(); // 没有修改版本记录则默认使用1.0.0.0 开始 if (objNode.LastChild == null) { modrecoreInfo.ModVersion = new Version("1.0.0.0").ToString(); } else { Version lastVersion = new Version(objNode.LastChild.Attributes["modversion"].Value); modrecoreInfo.ModVersion = new Version(string.Format("{0}.{1}.{2}.{3}", lastVersion.Major, lastVersion.Minor, lastVersion.Build, lastVersion.Revision + 1)).ToString(); } modrecoreInfo.ModOrderId = string.Empty; modrecoreInfo.Proposer = string.Empty; modrecoreInfo.Programmer = string.Empty; modrecoreInfo.ModContent = string.Empty; modrecoreInfo.ModReason = string.Empty; modrecoreInfo.Remark = string.Empty; XmlElement objElement = objXmlDoc.CreateElement("item"); objElement.SetAttribute("guid", modrecoreInfo.GUID); objElement.SetAttribute("moddate", modrecoreInfo.ModDate.ToString("yyyy-MM-dd HH:mm:ss")); objElement.SetAttribute("modversion", modrecoreInfo.ModVersion.ToString()); objElement.SetAttribute("modorderId", modrecoreInfo.ModOrderId); objElement.SetAttribute("proposer", modrecoreInfo.Proposer); objElement.SetAttribute("programmer", modrecoreInfo.Programmer); objElement.SetAttribute("modcontent", modrecoreInfo.ModContent); objElement.SetAttribute("modreason", modrecoreInfo.ModReason); objElement.SetAttribute("remark", modrecoreInfo.Remark); objNode.AppendChild(objElement); xmldicthelper.Save(false); (gridViewModrecord.gridView1.DataSource as List <ModRecordInfo>).Insert(0, modrecoreInfo); gridViewModrecord.gridView1.RefreshData(); }
/// <summary> /// 绑定历史记录 /// </summary> private void BindRecord() { #region 添加别名解析 this.gridViewModrecord.DisplayColumns = "ModDate,ModVersion,ModOrderId,Proposer,Programmer,ModContent,ModReason,Remark"; this.gridViewModrecord.AddColumnAlias("GUID", "GUID"); this.gridViewModrecord.AddColumnAlias("ModDate", "修改日期"); this.gridViewModrecord.AddColumnAlias("ModVersion", "修改版本"); this.gridViewModrecord.AddColumnAlias("ModOrderId", "修改单号"); this.gridViewModrecord.AddColumnAlias("Proposer", "申请人"); this.gridViewModrecord.AddColumnAlias("Programmer", "修改人"); this.gridViewModrecord.AddColumnAlias("ModContent", "修改内容"); this.gridViewModrecord.AddColumnAlias("ModReason", "修改原因"); this.gridViewModrecord.AddColumnAlias("Remark", "备注"); #endregion XmlNodeList xmlNodeLst = xmldicthelper.Read("datatype/histories"); List <ModRecordInfo> modRecordInfoLst = new List <ModRecordInfo>(); foreach (XmlNode xn1 in xmlNodeLst) { ModRecordInfo modRecordInfo = new ModRecordInfo(); // 将节点转换为元素,便于得到节点的属性值 XmlElement xe = (XmlElement)xn1; // 得到Type和ISBN两个属性的属性值 modRecordInfo.GUID = xe.GetAttribute("guid").ToString(); modRecordInfo.ModDate = Convert.ToDateTime(xe.GetAttribute("moddate")); modRecordInfo.ModVersion = new Version(xe.GetAttribute("modversion")).ToString(); modRecordInfo.ModOrderId = xe.GetAttribute("modorderId"); modRecordInfo.Proposer = xe.GetAttribute("proposer"); modRecordInfo.Programmer = xe.GetAttribute("programmer"); modRecordInfo.ModContent = xe.GetAttribute("modcontent"); modRecordInfo.ModReason = xe.GetAttribute("modreason"); modRecordInfo.Remark = xe.GetAttribute("remark"); modRecordInfoLst.Add(modRecordInfo); } modRecordInfoLst.Sort(); gridViewModrecord.DataSource = modRecordInfoLst; gridViewModrecord.gridView1.Columns["GUID"].Visible = false; gridViewModrecord.gridView1.Columns["ModDate"].ColumnEdit = repositoryItemDateEdit1; }