//using BestHTTP.JSON; using System.Collections.Generic; using System.Diagnostics; using System.IO; namespace PublicTools.XMLDataBase { /// /// 表格代理 /// 一个表格的控制器,支持多表同时编辑,提高IO效率 /// public class XTable : TableInterface { /// /// 绝对路径 /// private TableInterface table; public XTable(int type) { if (type == 0) { table = new XMLDataEditor(); } else if (type == 1) { //table = new JsonDataEditor(); } } public XTable(string path) { //Open(path); string exten = Path.GetExtension(path); if (exten == ".xml") { table = new XMLDataEditor(path); } else if (exten == ".json") { //table = new JsonDataEditor(path); } if (table == null) { UnityEngine.Debug.LogError("Table is null!" + path); } } public XTable(DataType dataType) { //Open(path); if (dataType == DataType.Xml) { table = new XMLDataEditor(); } else if (dataType == DataType.Json) { //table = new JsonDataEditor(); } if (table == null) { UnityEngine.Debug.LogError("Table is null!" + dataType); } } public XTable() { } /// /// 打开表格 /// 支持xml,json文件的处理 /// 后续可能支持sqlite或者其他处理方式 /// /// public bool Open() { return table.Open(); } /// /// 打开表格 /// 支持xml,json文件的处理 /// 后续可能支持sqlite或者其他处理方式 /// /// public bool Open(string path) { return table.Open(path); } /// /// 关闭操作 /// public void Close() { table.Close(); } /// /// 插入一个对象 /// /// /// /// /// public bool InsertData(T data) { if (data != null) { return table.InsertData(data); } return false; } /// /// 查找对象 /// /// /// /// public T FindData(string key) { return table.FindData(key); } /// /// 查找所有对象 /// /// /// public List FindAllData() { return table.FindAllData(); } /// /// 查找所有对象 /// /// /// public List FindAllData(string data) { return table.FindAllData(data); } /// /// 更新数据 /// /// /// /// /// public bool UpdateData(T data) { if (data != null) { return table.UpdateData(data); } return false; } /// /// 删除元素 /// /// /// /// 默认使用xml,可以是其他文件如json /// public bool DeleteData(string key) { if (!string.IsNullOrEmpty(key)) { return table.DeleteData(key); } return false; } /// /// 删除所有元素 /// /// /// /// /// public bool DeleteAllData() { return table.DeleteAllData(); } public bool Create(string tableName) { return table.Create(tableName); } public void Save() { table.Save(); } public List FindAllData(byte[] data) { return table.FindAllData(data); } public bool InsertData(T data, string priKey) { return table.InsertData(data,priKey); } public bool UpdateData(T data, string key) { return table.InsertData(data,key); } } }