public void ContentCreate() { WhqHelper.DatabaseInit(); DataTableEntity modelDT = new DataTableEntity { Name = "TestTable" }; DataTableManage.Create(WhqHelper.modelD, modelDT); DataColumnEntity modelDC2 = new DataColumnEntity { Name = "ID", Type = EColumnType.User, DataType = EContentType.Int, DataLength = 4 }; DataColumnEntity modelDC3 = new DataColumnEntity { Name = "Name", Type = EColumnType.User, DataType = EContentType.String, DataLength = 0x100 }; DataColumnManage.Create(modelDT, modelDC2); DataColumnManage.Create(modelDT, modelDC3); //添加内容 int RowIndex = DataContentManage.GetFirstEmpty(modelDT).GetRowIndex(); DataContentManage.Create(modelDT.Columns[0], new DataContentEntity { Content = 1 }, RowIndex); DataContentManage.Create(modelDC2, new DataContentEntity { Content = 1 },RowIndex); DataContentManage.Create(modelDC3, new DataContentEntity { Content = "whq" }, RowIndex); RowIndex = DataContentManage.GetFirstEmpty(modelDT).GetRowIndex(); DataContentManage.Create(modelDT.Columns[0], new DataContentEntity { Content = 1 }, RowIndex); DataContentManage.Create(modelDC2, new DataContentEntity { Content = 2 }, RowIndex); DataContentManage.Create(modelDC3, new DataContentEntity { Content = "zyp" }, RowIndex); RowIndex = DataContentManage.GetFirstEmpty(modelDT).GetRowIndex(); DataContentManage.Create(modelDT.Columns[0], new DataContentEntity { Content = 1 }, RowIndex); DataContentManage.Create(modelDC2, new DataContentEntity { Content = 3 }, RowIndex); DataContentManage.Create(modelDC3, new DataContentEntity { Content = "xxx" }, RowIndex); Assert.AreEqual(DataContentManage.GetFirstEmpty(modelDT).GetRowIndex(), 3); WhqHelper.DatabaseClose(); }
/// <summary> /// 创建 /// </summary> public static void Create(DataTableEntity modelDT, DataColumnEntity modelDC) { //赋值 modelDC.ColumnPage = modelDT.ColumnPage; modelDC.Table = modelDT; //生成编号 if (modelDC.Type == EColumnType.RowIndex) { modelDC.ID = 0; } else { modelDC.ID = modelDT.Columns.Max(info => info.ID) + 1; } //列信息编号 modelDC.ContentPageID = DataFileManage.GetEmptyPageID(modelDT.DataFile); //写入列 modelDC.ColumnPage.Columns.Add(modelDC); modelDC.ColumnPage.DataPage.Content = modelDC.ColumnPage.ToBytes(); DataPageManage.Write(modelDC.ColumnPage.DataPage); //表用户列 if (modelDC.Type == EColumnType.User) { modelDT.UserColumns.Add(modelDC); } //创建数据分页 byte[] array = new byte[Config.PAGE_SIZE]; array[0] = Convert.ToByte(EPageType.DataContent); DataPageManage.Write(new DataPageEntity { DataFile = modelDT.DataFile, ID = modelDC.ContentPageID, Content = array }); //更新文件 DataFileManage.Update(modelDT.DataFile); }
/// <summary> /// 提交 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmit_Click(object sender, EventArgs e) { //建表 DataTableEntity modelDT = new DataTableEntity { Name = txtName.Text }; DataTableManage.Create(DB, modelDT); string[] arrName= Request.Form.GetValues("txtColumnName"); string[] arrType=Request.Form.GetValues("ddlType"); string[] arrLength=Request.Form.GetValues("txtLength"); for (int i = 0; i < arrName.Length; i++) { if (!string.IsNullOrEmpty(arrName[i])) { DataColumnEntity modelDC = new DataColumnEntity { Name = arrName[i], Type = EColumnType.User, DataType = WhqDatabase.Kernel.DataContent.ContentType.GetType(Convert.ToInt32(arrType[i])), DataLength = Convert.ToInt32(arrLength[i]) }; //重复判断 if (modelDT.UserColumns.Count(info => arrName[i] == info.Name) > 0) { JScript.ShowMessage(this, "存在重名列"); DataTableManage.Delete(modelDT); return; } DataColumnManage.Create(modelDT, modelDC); } } JScript.ResponseScript(this, "alert('建表成功!');location='DatabaseInfo.aspx?DatabaseID=" + DB.ID + "'"); }
public void ContentCreateSome() { WhqHelper.DatabaseInit(); DataTableEntity modelDT = new DataTableEntity { Name = "TestTable" }; DataTableManage.Create(WhqHelper.modelD, modelDT); DataColumnEntity modelDC2 = new DataColumnEntity { Name = "ID", Type = EColumnType.User, DataType = EContentType.Int, DataLength = 4 }; DataColumnEntity modelDC3 = new DataColumnEntity { Name = "Name", Type = EColumnType.User, DataType = EContentType.String, DataLength = 0x100 }; DataColumnEntity modelDC4 = new DataColumnEntity { Name = "Content", Type = EColumnType.User, DataType = EContentType.String, DataLength = 0x100 }; DataColumnManage.Create(modelDT, modelDC2); DataColumnManage.Create(modelDT, modelDC3); DataColumnManage.Create(modelDT, modelDC4); //添加内容 int RowIndex = DataContentManage.GetFirstEmpty(modelDT).GetRowIndex(); for (int i = 0; i < 50; i++) { DataContentManage.Create(modelDT.Columns[0], new DataContentEntity { Content = 1 }, RowIndex); DataContentManage.Create(modelDC2, new DataContentEntity { Content = i }, RowIndex); DataContentManage.Create(modelDC3, new DataContentEntity { Content = "whq" }, RowIndex); DataContentManage.Create(modelDC4, new DataContentEntity { Content = "whq is Good!" }, RowIndex); RowIndex++; } Assert.AreEqual(DataContentManage.Read(modelDT.Columns[0], info => true).Count(), 50); WhqHelper.DatabaseClose(); }
/// <summary> /// 提交 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmit_Click(object sender, EventArgs e) { //建表 string[] arrName = Request.Form.GetValues("txtColumnName"); string[] arrType = Request.Form.GetValues("ddlType"); string[] arrLength = Request.Form.GetValues("txtLength"); for (int i = 0; i < arrName.Length; i++) { if (!string.IsNullOrEmpty(arrName[i])) { DataColumnEntity modelDC = new DataColumnEntity { Name = arrName[i], Type = EColumnType.User, DataType = WhqDatabase.Kernel.DataContent.ContentType.GetType(Convert.ToInt32(arrType[i])), DataLength = Convert.ToInt32(arrLength[i]) }; //重复判断 if (Table.UserColumns.Count(info => arrName[i] == info.Name) > 0) { JScript.ShowMessage(this, "存在重名列"); ColumnBind(); return; } DataColumnManage.Create(Table, modelDC); } } JScript.ShowMessage(this, "修改表成功"); ColumnBind(); }
/// <summary> /// 页面初始化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Init(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request.QueryString["DatabaseID"]) && !string.IsNullOrEmpty(Request.QueryString["DataTableID"]) && !string.IsNullOrEmpty(Request.QueryString["DataColumnID"])) { Column = Manage.ListDB.First(info => info.ID == Convert.ToInt32(Request.QueryString["DatabaseID"])).Tables.First(info => info.ID == Convert.ToInt32(Request.QueryString["DataTableID"])).Columns.First(info => info.ID == Convert.ToInt32(Request.QueryString["DataColumnID"])); } }
public void DataColumnCreate() { WhqHelper.DatabaseInit(); DataTableEntity modelDT = new DataTableEntity { Name = "TestTable" }; DataTableManage.Create(WhqHelper.modelD, modelDT); DataColumnEntity modelDC1 = new DataColumnEntity { Name = "ID", DataType = EContentType.Int, DataLength = 4 }; DataColumnEntity modelDC2 = new DataColumnEntity { Name = "Column", DataType = EContentType.String, DataLength = 32 }; DataColumnManage.Create(modelDT, modelDC1); DataColumnManage.Create(modelDT, modelDC2); WhqHelper.DatabaseClose(); }
/// <summary> /// 创建 /// </summary> public static void Create(DataColumnEntity modelDT, DataContentEntity modelDC, int RowIndex) { //赋值 modelDC.ContentPage = GetPage(modelDT, RowIndex); modelDC.ContentIndex = RowIndex % ((Config.PAGE_SIZE - ContentPageEntity.CONTENT_START) / modelDT.DataLength); modelDC.Column = modelDT; //写入列 modelDC.ContentPage.Contents.Add(modelDC); //写入文件 modelDT.Table.DataFile.FileStream.Seek(modelDC.ContentPage.PageID * Config.PAGE_SIZE+ ContentPageEntity.CONTENT_START + modelDC.ContentIndex * modelDT.DataLength, SeekOrigin.Begin); modelDT.Table.DataFile.FileStream.Write(modelDC.ToBytes(), 0, modelDT.DataLength); }
/// <summary> /// 删除 /// </summary> public static void Delete(DataColumnEntity modelDC) { //清空列的内容页 long ContentPageID = modelDC.ContentPageID; while (ContentPageID > 0) { DataPageEntity modelDP = new DataPageEntity { DataFile = modelDC.Table.DataFile, ID = ContentPageID }; ContentPageID = DataContentManage.ReadNextPageID(modelDP); DataPageManage.Clear(modelDP); } modelDC.ColumnPage.Columns.Remove(modelDC); modelDC.Table.UserColumns.Remove(modelDC); modelDC.ColumnPage.DataPage.Content = modelDC.ColumnPage.ToBytes(); DataPageManage.Write(modelDC.ColumnPage.DataPage); modelDC = null; }
public void DataRowCreateSome() { WhqHelper.DatabaseInit(); DataTableEntity modelDT = new DataTableEntity { Name = "TestTable" }; DataTableManage.Create(WhqHelper.modelD, modelDT); DataColumnEntity modelDC1 = new DataColumnEntity { Name = "ID", Type = EColumnType.User, DataType = EContentType.Int, DataLength = 4 }; DataColumnEntity modelDC2 = new DataColumnEntity { Name = "Name", Type = EColumnType.User, DataType = EContentType.String, DataLength = 0x100 }; DataColumnEntity modelDC3 = new DataColumnEntity { Name = "Content", Type = EColumnType.User, DataType = EContentType.String, DataLength = 0x100 }; DataColumnManage.Create(modelDT, modelDC1); DataColumnManage.Create(modelDT, modelDC2); DataColumnManage.Create(modelDT, modelDC3); string[] listColumn = new string[] { "ID", "Name", "Content" }; for (int i = 0; i < 50; i++) { DataRowManage.Create(modelDT, new DataRowEntity { Columns = listColumn, Contents = new object[] { i + 1, "name", (i + 1) + "Content" } }); } Assert.AreEqual(DataRowManage.ReadCount(modelDT), 50); WhqHelper.DatabaseClose(); }
/// <summary> /// 创建 /// </summary> public static void Create() { DB = new DatabaseEntity { Name = Config.DBMasterName, MasterFile = new DataFileEntity { FilePath = Config.DBMasterPath } }; DatabaseManage.Create(DB); //建表 DataTableEntity modelDT = new DataTableEntity { Name = "Database" }; DataTableManage.Create(DB, modelDT); DataColumnEntity modelDC1 = new DataColumnEntity { Name = "ID", Type = EColumnType.User, DataType = EContentType.Int, DataLength = 4 }; DataColumnEntity modelDC2 = new DataColumnEntity { Name = "Name", Type = EColumnType.User, DataType = EContentType.String, DataLength = 0x100 }; DataColumnEntity modelDC3 = new DataColumnEntity { Name = "Path", Type = EColumnType.User, DataType = EContentType.String, DataLength = 1024 }; DataColumnManage.Create(modelDT, modelDC1); DataColumnManage.Create(modelDT, modelDC2); DataColumnManage.Create(modelDT, modelDC3); DataRowManage.Create(modelDT, new DataRowEntity { Columns = new string[] { "ID", "Name", "Path" }, Contents = new object[] { DBMASTER_ID, DB.Name, DB.MasterFile.FilePath } }); DatabaseManage.Close(DB); }
/// <summary> /// 创建 /// </summary> public static void Create(DatabaseEntity modelD,DataTableEntity modelDT) { modelDT.TablePage = modelD.MasterFile.TablePage; modelDT.ID = modelD.Tables.Count == 0 ? 1 : modelD.Tables.Max(info => info.ID) + 1; //列信息编号 modelDT.ColumnPageID = DataFileManage.GetEmptyPageID(modelD.MasterFile); //写入表 modelDT.TablePage.Tables.Add(modelDT); modelDT.TablePage.DataPage.Content = modelDT.TablePage.ToBytes(); DataPageManage.Write(modelDT.TablePage.DataPage); //创建列分页 ColumnPageEntity modelCP = new ColumnPageEntity { Columns = new List<DataColumnEntity>(), Table = modelDT }; DataPageEntity modelDP = new DataPageEntity { DataFile = modelD.MasterFile, ID = modelDT.ColumnPageID ,Content = modelCP.ToBytes()}; DataPageManage.Write(modelDP); //赋值 modelCP.DataPage = modelDP; modelDT.ColumnPage = modelCP; modelDT.UserColumns = new List<DataColumnEntity>(); //创建系统列 DataColumnEntity modelDC = new DataColumnEntity { Name = EColumnType.RowIndex.ToString(), Type = EColumnType.RowIndex, DataType = EContentType.Byte, DataLength = Config.ROWINDEX_LENGTH }; DataColumnManage.Create(modelDT, modelDC); }
public void DataRowCreate() { WhqHelper.DatabaseInit(); DataTableEntity modelDT = new DataTableEntity { Name = "TestTable" }; DataTableManage.Create(WhqHelper.modelD, modelDT); DataColumnEntity modelDC1 = new DataColumnEntity { Name = "ID", Type = EColumnType.User, DataType = EContentType.Int, DataLength = 4 }; DataColumnEntity modelDC2 = new DataColumnEntity { Name = "Name", Type = EColumnType.User, DataType = EContentType.String, DataLength = 0x100 }; DataColumnEntity modelDC3 = new DataColumnEntity { Name = "Content", Type = EColumnType.User, DataType = EContentType.String, DataLength = 0x100 }; DataColumnManage.Create(modelDT, modelDC1); DataColumnManage.Create(modelDT, modelDC2); DataColumnManage.Create(modelDT, modelDC3); string[] listColumn = new string[] { "ID", "Name","Content" }; DataRowManage.Create(modelDT, new DataRowEntity { Columns = listColumn, Contents = new object[] { 1, "whq", "Conten123t" } }); DataRowManage.Create(modelDT, new DataRowEntity { Columns = listColumn, Contents = new object[] { 2, "zyp", "11111111b" } }); DataRowManage.Create(modelDT, new DataRowEntity { Columns = listColumn, Contents = new object[] { 3, "z423yp", "Cosdfntent" } }); DataRowManage.Create(modelDT, new DataRowEntity { Columns = listColumn, Contents = new object[] { 4, "sdf4", "Contsdfent" } }); DataRowManage.Create(modelDT, new DataRowEntity { Columns = listColumn, Contents = new object[] { 5, "z423yp", "Co3entent" } }); DataRowManage.Create(modelDT, new DataRowEntity { Columns = listColumn, Contents = new object[] { 6, "sdf4", "Con4213tent" } }); DataRowManage.Create(modelDT, new DataRowEntity { Columns = listColumn, Contents = new object[] { 7, "z423yp", "Cosdafntent" } }); DataRowManage.Create(modelDT, new DataRowEntity { Columns = listColumn, Contents = new object[] { 8, "zyp", "22222222a" } }); DataRowManage.Create(modelDT, new DataRowEntity { Columns = listColumn, Contents = new object[] { 9, "z423yp", "Contentsdf" } }); DataRowManage.Create(modelDT, new DataRowEntity { Columns = listColumn, Contents = new object[] { 10, "sdf4", "234Content" } }); WhqHelper.DatabaseClose(); }
public void ContentRead() { ContentCreate(); WhqHelper.DatabaseOpen(); DataTableEntity modelDT = new DataTableEntity { Name = "TestTable" }; modelDT=DataTableManage.Read(WhqHelper.modelD, modelDT); DataColumnEntity modelDC1 = new DataColumnEntity { Name = "ID"}; modelDC1 = DataColumnManage.Read(modelDT, modelDC1); IEnumerable<DataContentEntity> result = DataContentManage.Read(modelDC1, info => Convert.ToInt32(info.Content) == 2); Assert.AreEqual(result.First().ContentIndex, 1); result = DataContentManage.Read(modelDC1, info => Convert.ToInt32(info.Content) > 1); Assert.AreEqual(result.Count(), 2); Assert.AreEqual(DataContentManage.Read(modelDT.Columns[0], info => true).Count(),3); WhqHelper.DatabaseClose(); }
/// <summary> /// 读取 /// </summary> public static DataColumnEntity Read(DataTableEntity modelDT, DataColumnEntity modelDC) { foreach (DataColumnEntity modelTemp in modelDT.Columns.Where(info => info.Name == modelDC.Name)) { return modelTemp; } return null; }
public void DataColumnUpdateTypeWithData() { WhqHelper.DatabaseInit(); DataTableEntity modelDT = new DataTableEntity { Name = "TestTable" }; DataTableManage.Create(WhqHelper.modelD, modelDT); DataColumnEntity modelDC1 = new DataColumnEntity { Name = "ID", DataType = EContentType.Int, DataLength = 4 }; DataColumnEntity modelDC2 = new DataColumnEntity { Name = "Column", DataType = EContentType.Int, DataLength = 4 }; DataColumnManage.Create(modelDT, modelDC1); DataColumnManage.Create(modelDT, modelDC2); string[] listColumn = new string[] { "ID", "Column"}; DataRowManage.Create(modelDT, new DataRowEntity { Columns = listColumn, Contents = new object[] { 1, 1 } }); DataRowManage.Create(modelDT, new DataRowEntity { Columns = listColumn, Contents = new object[] { 2, 2 } }); DataRowManage.Create(modelDT, new DataRowEntity { Columns = listColumn, Contents = new object[] { 3, 3 } }); DataColumnManage.Update(modelDC2, new DataColumnEntity { Name = "TestColumn2", DataType = EContentType.String, DataLength = 32 }); DataColumnManage.Read(modelDT, modelDC2); Assert.AreEqual(modelDC2.Name, "TestColumn2"); Assert.AreEqual(modelDC2.DataType, EContentType.String); Assert.AreEqual(DataRowManage.ReadCount(modelDT), 3); WhqHelper.DatabaseClose(); }
public void DataColumnUpdateType() { WhqHelper.DatabaseInit(); DataTableEntity modelDT = new DataTableEntity { Name = "TestTable" }; DataTableManage.Create(WhqHelper.modelD, modelDT); DataColumnEntity modelDC1 = new DataColumnEntity { Name = "ID", DataType = EContentType.Int, DataLength = 4 }; DataColumnEntity modelDC2 = new DataColumnEntity { Name = "Column", DataType = EContentType.Int, DataLength = 4 }; DataColumnManage.Create(modelDT, modelDC1); DataColumnManage.Create(modelDT, modelDC2); DataColumnManage.Update(modelDC2, new DataColumnEntity { Name = "TestColumn2", DataType = EContentType.String, DataLength = 32 }); DataColumnManage.Read(modelDT, modelDC2); Assert.AreEqual(modelDC2.Name, "TestColumn2"); Assert.AreEqual(modelDC2.DataType, EContentType.String); WhqHelper.DatabaseClose(); }
/// <summary> /// 从byte[]中读取 /// </summary> /// <param name="arr"></param> public void FromBytes(byte[] arr) { NextPageID = BitConverter.ToInt64(arr, NEXTPAGEID_START); Columns = new List<DataColumnEntity>(); for (int i = 1; i < Config.PAGE_SIZE / DataColumnEntity.DATA_SIZE; i++) { byte[] temp = new byte[DataColumnEntity.DATA_SIZE]; temp = ByteUtil.ReadBytes(arr, i * DataColumnEntity.DATA_SIZE, DataColumnEntity.DATA_SIZE); if (ByteUtil.IsNotZero(temp)) { DataColumnEntity modelDT = new DataColumnEntity(); modelDT.ColumnPage = this; modelDT.Table = Table; modelDT.FromBytes(temp); Columns.Add(modelDT); } } }
/// <summary> /// 根据行号获取某数据分页 /// </summary> /// <param name="modelDC"></param> /// <param name="index"></param> /// <returns></returns> public static ContentPageEntity GetPage(DataColumnEntity modelDC, int RowIndex) { long ContentPageID = modelDC.ContentPageID; int PageIndex = 0; ContentPageEntity modelCP = new ContentPageEntity(); if (RowIndex / modelDC.PageMaxCount == 0)//第一页 { modelCP = ReadContentPage(new DataPageEntity { DataFile = modelDC.Table.DataFile, ID = ContentPageID },new ContentPageEntity { Column = modelDC, PageIndex = PageIndex }); } else//不是第一页 { //遍历寻找前一页编号 for (int i = 0; i <= RowIndex / modelDC.PageMaxCount - 2; i++) { ContentPageID = ReadNextPageID(new DataPageEntity { DataFile = modelDC.Table.DataFile, ID = ContentPageID }); PageIndex++; } long NextPageID = ReadNextPageID(new DataPageEntity { DataFile = modelDC.Table.DataFile, ID = ContentPageID }); if (NextPageID > 0)//有当前页 { ContentPageID = NextPageID; modelCP = ReadContentPage(new DataPageEntity { DataFile = modelDC.Table.DataFile, ID = ContentPageID }, new ContentPageEntity { Column = modelDC, PageIndex = PageIndex }); } else//页不存在创建新页 { modelCP = NewContentPage(modelDC, ContentPageID, PageIndex); } } return modelCP; }
/// <summary> /// 新建内容页 /// </summary> /// <param name="modelDC">所在列</param> /// <param name="PageID">前一页页编号</param> /// <param name="PageIndex">页号</param> /// <returns></returns> public static ContentPageEntity NewContentPage(DataColumnEntity modelDC, long PageID, int PageIndex) { long NextPageID = DataFileManage.GetEmptyPageID(modelDC.Table.DataFile); //修改前一页 WriteNextPageID(new DataPageEntity { DataFile = modelDC.Table.DataFile, ID = PageID }, NextPageID); //创建数据分页 byte[] array = new byte[Config.PAGE_SIZE]; array[0] = Convert.ToByte(EPageType.DataContent); DataPageEntity modelDP = new DataPageEntity { DataFile = modelDC.Table.DataFile, ID = NextPageID, Content = array }; DataPageManage.Write(modelDP); modelDP.Content = null; //创建实体 ContentPageEntity modelCP = new ContentPageEntity { Column = modelDC, DataPage=modelDP, PageIndex = PageIndex, Contents = new List<DataContentEntity>() }; return modelCP; }
public void GetFirstEmpty() { WhqHelper.DatabaseInit(); DataTableEntity modelDT = new DataTableEntity { Name = "TestTable" }; DataTableManage.Create(WhqHelper.modelD, modelDT); DataColumnEntity modelDC1 = new DataColumnEntity { Name = "ID", Type = EColumnType.User, DataType = EContentType.Byte, DataLength = 1 }; DataColumnEntity modelDC2 = new DataColumnEntity { Name = "Column", Type = EColumnType.User, DataType = EContentType.String, DataLength = 32 }; DataColumnManage.Create(modelDT, modelDC1); DataColumnManage.Create(modelDT, modelDC2); ContentPoint cp= DataContentManage.GetFirstEmpty(modelDT); Assert.AreEqual(cp.ContentPageID, 4); Assert.AreEqual(cp.ContentIndex, 0); Assert.AreEqual(cp.PageIndex, 0); WhqHelper.DatabaseClose(); }
/// <summary> /// 读取 /// </summary> /// <param name="modelDT">列</param> /// <param name="predicate">是否满足条件的函数</param> /// <returns></returns> public static List<DataContentEntity> Read(DataColumnEntity modelDC, Func<DataContentEntity, bool> predicate) { List<DataContentEntity> listDC = new List<DataContentEntity>(); int PageIndex = 0; ContentPageEntity modelCP = ReadContentPage(new DataPageEntity { DataFile = modelDC.Table.DataFile, ID = modelDC.ContentPageID }, new ContentPageEntity { Column = modelDC, PageIndex = PageIndex }); //遍历找 listDC.AddRange(modelCP.Contents.Where(predicate)); //去下一页找 while (modelCP.NextPageID > 0) { PageIndex++; modelCP = ReadContentPage(new DataPageEntity { DataFile = modelDC.Table.DataFile, ID = modelCP.NextPageID }, new ContentPageEntity { Column = modelDC, PageIndex = PageIndex }); //遍历找 listDC.AddRange(modelCP.Contents.Where(predicate)); } return listDC; }
public void ContentDelete() { ContentCreate(); WhqHelper.DatabaseOpen(); DataTableEntity modelDT = new DataTableEntity { Name = "TestTable" }; modelDT = DataTableManage.Read(WhqHelper.modelD, modelDT); DataColumnEntity modelDC1 = new DataColumnEntity { Name = "Name" }; modelDC1 = DataColumnManage.Read(modelDT, modelDC1); IEnumerable<int> listDC = DataContentManage.Read(modelDC1, info => info.Content.ToString() == "whq").Select(info => info.RowIndex); //删除行 foreach (DataContentEntity modelDC in DataContentManage.Read(modelDT.Columns[0], info => listDC.Contains(info.RowIndex))) { DataContentManage.Delete(modelDC); } Assert.AreEqual(DataContentManage.GetFirstEmpty(modelDT).GetRowIndex(), 0); Assert.AreEqual(DataContentManage.Read(modelDC1, info => info.Content.ToString() == "whq").Count(), 0); WhqHelper.DatabaseClose(); }
/// <summary> /// 根据行号获取某数据内容 /// </summary> /// <param name="modelDC"></param> /// <param name="index"></param> /// <returns></returns> public static DataContentEntity GetContent(DataColumnEntity modelDC, int RowIndex) { ContentPageEntity modelCP = GetPage(modelDC, RowIndex); return modelCP.Contents.Where(info => info.ContentIndex == RowIndex % modelDC.PageMaxCount).First(); }
public void ContentUpdate() { ContentCreate(); WhqHelper.DatabaseOpen(); DataTableEntity modelDT = new DataTableEntity { Name = "TestTable" }; modelDT = DataTableManage.Read(WhqHelper.modelD, modelDT); DataColumnEntity modelDC1 = new DataColumnEntity { Name = "Name" }; modelDC1 = DataColumnManage.Read(modelDT, modelDC1); DataContentEntity modelDContent = DataContentManage.Read(modelDC1, info => info.Content.ToString() == "xxx").First(); modelDContent.Content = "xxxxx"; DataContentManage.Update(modelDContent); IEnumerable<DataContentEntity> result = DataContentManage.Read(modelDC1, info => info.Content.ToString() == "xxx"); Assert.AreEqual(result.Count(), 0); result = DataContentManage.Read(modelDC1, info => info.Content.ToString() == "xxxxx"); Assert.AreEqual(result.Count(), 1); WhqHelper.DatabaseClose(); }
/// <summary> /// 修改 /// </summary> public static void Update(DataColumnEntity modelDC,DataColumnEntity newDC) { if (modelDC.DataLength!= newDC.DataLength || modelDC.DataType!=newDC.DataType)//改变列类型或长度 { List<DataContentEntity> listDC = DataContentManage.Read(modelDC, info => true); //清空列的内容页 long ContentPageID = modelDC.ContentPageID; while (ContentPageID > 0) { DataPageEntity modelDP = new DataPageEntity { DataFile = modelDC.Table.DataFile, ID = ContentPageID }; ContentPageID = DataContentManage.ReadNextPageID(modelDP); DataPageManage.Clear(modelDP); } //创建数据分页 byte[] array = new byte[Config.PAGE_SIZE]; array[0] = Convert.ToByte(EPageType.DataContent); DataPageManage.Write(new DataPageEntity { DataFile = modelDC.Table.DataFile, ID = modelDC.ContentPageID, Content = array }); //改变列 modelDC.Name = newDC.Name; modelDC.DataType = newDC.DataType; modelDC.DataLength = newDC.DataLength; modelDC.ColumnPage.DataPage.Content = modelDC.ColumnPage.ToBytes(); DataPageManage.Write(modelDC.ColumnPage.DataPage); //写入数据 for (int i = 0; i < listDC.Count; i++) { DataContentManage.Create(modelDC, listDC[i], i); } } else if (modelDC.Name != newDC.Name)//只改变列名 { modelDC.Name = newDC.Name; modelDC.ColumnPage.DataPage.Content = modelDC.ColumnPage.ToBytes(); DataPageManage.Write(modelDC.ColumnPage.DataPage); } }