private void WFSession_Load() { if (FileOP.IsExist(this.filePath, FileOPMethod.File)) { // 文件存在,将当前 XML 文件中的数据读入到 DataSet 中 // ds.ReadXml(this.filePath, XmlReadMode.DiffGram); DataTable dt = ConvertXmlToDataTable(this.rootName); for (int i = 0; i < dt.Columns.Count; i++) { DataTable dd = ConvertXmlToDataTable("//" + this.rootName + "/" + dt.Columns[i].ColumnName); dd.TableName = dt.Columns[i].ColumnName; this.SessionDs.Tables.Add(dd); } WFGlobal.writeLine.Append("公有表 " + dt.Columns.Count + " 个\r\n"); } else { // 文件不存在,开始创建 OperateXml oXml = new OperateXml(); oXml.filePath = this.filePath; oXml.CreateXml(this.rootName); DataTable dt = new DataTable(this.tableName); DataRow dr; dr = dt.NewRow(); dt.Rows.Add(dr); this.SessionDs.Tables.Add(dt); oXml.xPath = this.rootName; oXml.CreateNode(this.tableName, dt); } if (this.SessionDs.Tables.Contains(this.tableName)) { } else { // 当前操作的表不存在,创建该表 DataTable dt = new DataTable(this.tableName); DataRow dr; dr = dt.NewRow(); dt.Rows.Add(dr); this.SessionDs.Tables.Add(dt); OperateXml oXml = new OperateXml(); oXml.filePath = this.filePath; oXml.xPath = this.rootName; oXml.CreateNode(this.tableName, dt); } }
/// <summary> /// 处理或接受信息的变更 /// </summary> public void AcceptChanges() { #region 处理添加 if (this.IsAddedCollection.Count > 0) { foreach (string Name in this.IsAddedCollection.Keys) { DataTable dt = new DataTable(); // 开始添加 OperateXml oXml = new OperateXml(); oXml.filePath = this.filePath; oXml.xPath = "//" + this.rootName + "/" + this.tableName; oXml.CreateNode(Name, dt); this.IsChangedCollection.Add(Name, this.IsAddedCollection[Name]); } this.IsAddedCollection.Clear(); } #endregion #region 处理修改 if (this.IsChangedCollection.Count > 0) { DataTable dt = new DataTable(); DataRow dr; dr = dt.NewRow(); foreach (string Name in this.IsChangedCollection.Keys) { dt.Columns.Add(Name); dr[Name] = this.IsChangedCollection[Name]; } dt.Rows.Add(dr); // 开始修改 OperateXml oXml = new OperateXml(); oXml.filePath = this.filePath; oXml.xPath = "//" + this.rootName + "/" + this.tableName; oXml.ChangeNode(dt); #if DEBUG WFGlobal.writeLine.Append("改写当前自定义 Session 信息,路径: " + this.filePath + ",表名: " + this.tableName + "。\r\n"); #endif this.IsChangedCollection.Clear(); } #endregion }