/// <summary> /// 删除 /// </summary> public static void Delete(DataContentEntity modelDC) { modelDC.ContentPage.Contents.Remove(modelDC); //写入文件 modelDC.Table.DataFile.FileStream.Seek(modelDC.ContentPage.PageID * Config.PAGE_SIZE + ContentPageEntity.CONTENT_START + modelDC.ContentIndex * modelDC.Column.DataLength, SeekOrigin.Begin); modelDC.Table.DataFile.FileStream.Write(new byte[modelDC.Column.DataLength], 0, modelDC.Column.DataLength); }
/// <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 Update(DataContentEntity modelDC) { //写入文件 modelDC.Table.DataFile.FileStream.Seek(modelDC.ContentPage.PageID * Config.PAGE_SIZE + ContentPageEntity.CONTENT_START + modelDC.ContentIndex * modelDC.Column.DataLength, SeekOrigin.Begin); modelDC.Table.DataFile.FileStream.Write(modelDC.ToBytes(), 0, modelDC.Column.DataLength); }
/// <summary> /// 从byte[]中读取 /// </summary> /// <param name="arr"></param> public void FromBytes(byte[] arr) { NextPageID = BitConverter.ToInt64(arr, NEXTPAGEID_START); Contents = new List<DataContentEntity>(); if (Column.Type == EColumnType.RowIndex) { for (int i = 0; i < (Config.PAGE_SIZE - CONTENT_START) / Column.DataLength; i++) { byte[] temp = new byte[Column.DataLength]; temp = ByteUtil.ReadBytes(arr, i * Column.DataLength + CONTENT_START, Column.DataLength); if (ByteUtil.IsNotZero(temp)) { DataContentEntity modelDT = new DataContentEntity(); modelDT.ContentPage = this; modelDT.ContentIndex = i; modelDT.Column = Column; modelDT.FromBytes(temp); Contents.Add(modelDT); } } } else { //获取行索引 List<int> listRowIndex = DataTableManage.GetRowIndexList(Table); for (int i = 0; i < Column.PageMaxCount; i++) { if (listRowIndex.Contains(PageIndex * Column.PageMaxCount + i)) { byte[] temp = new byte[Column.DataLength]; temp = ByteUtil.ReadBytes(arr, i * Column.DataLength + CONTENT_START, Column.DataLength); DataContentEntity modelDT = new DataContentEntity(); modelDT.ContentPage = this; modelDT.ContentIndex = i; modelDT.Column = Column; modelDT.FromBytes(temp); Contents.Add(modelDT); } } } }