Beispiel #1
0
 public void DatabaseRead()
 {
     DatabaseCreate();
     DatabaseEntity modelD = new DatabaseEntity { MasterFile = new DataFileEntity { FilePath = Config.DataFilePath } };
     DatabaseManage.Read(modelD);
     DatabaseManage.Close(modelD);
 }
Beispiel #2
0
 /// <summary>
 /// 移除数据库
 /// </summary>
 /// <param name="modelDB"></param>
 public static void DBRemove(DatabaseEntity modelDB)
 {
     DataTableEntity modelDT = new DataTableEntity { Name = "Database" };
     modelDT = DataTableManage.Read(DBMaster.DB, modelDT);
     DataRowManage.Delete(modelDT, new DataWhereEntity[] { new DataWhereEntity { ColumnName = "ID", Predicate = info => Convert.ToInt32(info) == modelDB.ID } });
     ListDB.Remove(modelDB);
     modelDB.MasterFile.FileStream.Close();
 }
Beispiel #3
0
 /// <summary>
 /// 打开数据库
 /// </summary>
 public static void DatabaseOpen()
 {
     modelD = new DatabaseEntity
     {
         MasterFile = new DataFileEntity { FilePath = Config.DataFilePath }
     };
     DatabaseManage.Read(modelD);
 }
Beispiel #4
0
 /// <summary>
 /// 附加数据库
 /// </summary>
 /// <param name="modelDB"></param>
 public static void DBAdd(DatabaseEntity modelDB)
 {
     DataTableEntity modelDT = new DataTableEntity { Name = "Database" };
     modelDT = DataTableManage.Read(DBMaster.DB, modelDT);
     Manage.ListDB.Add(modelDB);
     List<DataRowEntity> listDR = DataRowManage.Read(modelDT, new string[] { "ID" });
     modelDB.ID = (listDR.Count == 0) ? 1 : listDR.Max(info => Convert.ToInt32(info.Contents[0])) + 1;
     DataRowManage.Create(modelDT, new DataRowEntity { Columns = new string[] { "ID", "Name", "Path" }, Contents = new object[] { modelDB.ID, modelDB.Name, modelDB.MasterFile.FilePath } });
 }
Beispiel #5
0
 /// <summary>
 /// 数据库初始化
 /// </summary>
 public static void DatabaseInit()
 {
     modelD = new DatabaseEntity
     {
         Name = Config.DatabaseName,
         MasterFile = new DataFileEntity { FilePath = Config.DataFilePath }
     };
     DatabaseManage.Delete(modelD);
     DatabaseManage.Create(modelD);
 }
 /// <summary>
 /// 读取
 /// </summary>
 public static void Read(DatabaseEntity model)
 {
     model.MasterFile.Database = model;
     //读主文件
     DataFileManage.Read(model.MasterFile);
     //读数据库信息
     DataPageEntity modelD = new DataPageEntity { DataFile = model.MasterFile, ID = Config.DATABASE_PAGE_ID };
     DataPageManage.Read(modelD);
     model.FromBytes(modelD.Content);
 }
Beispiel #7
0
        public void DatabaseUpdate()
        {
            DatabaseCreate();
            DatabaseEntity modelD = new DatabaseEntity { MasterFile = new DataFileEntity { FilePath = Config.DataFilePath } };
            DatabaseManage.Read(modelD);
            modelD.Name = "TestUpdate";
            DatabaseManage.Update(modelD);
            DatabaseManage.Close(modelD);

            modelD = new DatabaseEntity { MasterFile = new DataFileEntity { FilePath = Config.DataFilePath } };
            DatabaseManage.Read(modelD);
            Assert.AreEqual(modelD.Name, "TestUpdate");
            DatabaseManage.Close(modelD);
        }
Beispiel #8
0
 /// <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);
 }
Beispiel #10
0
 /// <summary>
 /// 附加库
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnAdd_Click(object sender, EventArgs e)
 {
     string strPath = txtPath.Text;
     if (string.IsNullOrEmpty(strPath))
     {
         JScript.ShowMessage(this, "请填写路径");
         return;
     }
     //打开数据库
     DatabaseEntity modelD = new DatabaseEntity
     {
         MasterFile = new DataFileEntity { FilePath = strPath }
     };
     DatabaseManage.Read(modelD);
     if (Manage.ListDB.Where(info => info.Name == modelD.Name).Count() > 0)
     {
         JScript.ShowMessage(this, "数据库名已存在");
         return;
     }
     //添加到主库中
     Manage.DBAdd(modelD);
     JScript.ResponseScript(this, "alert('数据库附加成功!');window.top.menu.location=window.top.menu.location.href;");
 }
Beispiel #11
0
 /// <summary>
 /// 新建库
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnNew_Click(object sender, EventArgs e)
 {
     string strName = txtName.Text;
     string strPath = txtPath.Text;
     if (string.IsNullOrEmpty(strName))
     {
         JScript.ShowMessage(this, "请填写名称");
         return;
     }
     if (string.IsNullOrEmpty(strPath))
     {
         strPath = Path.GetDirectoryName(DBMaster.DB.MasterFile.FilePath) + "\\" + strName + ".whqdata";
     }
     //判断是否重复
     DataTableEntity modelDT = new DataTableEntity { Name = "Database" };
     modelDT = DataTableManage.Read(DBMaster.DB, modelDT);
     if (Manage.ListDB.Where(info => info.Name == strName).Count() > 0)
     {
         JScript.ShowMessage(this, "数据库名已存在");
         return;
     }
     //创建数据库
     DatabaseEntity modelD = new DatabaseEntity
     {
         Name = strName,
         MasterFile = new DataFileEntity { FilePath = strPath }
     };
     DatabaseManage.Create(modelD);
     //添加到主库中
     Manage.DBAdd(modelD);
     JScript.ResponseScript(this, "alert('数据库创建成功!');window.top.menu.location=window.top.menu.location.href;");
 }
 /// <summary>
 /// 修改
 /// </summary>
 public static void Update(DatabaseEntity model)
 {
     DataPageManage.Write(new DataPageEntity { DataFile = model.MasterFile, ID = Config.DATABASE_PAGE_ID, Content = model.ToBytes() });
     DataFileManage.Update(model.MasterFile);
 }
 /// <summary>
 /// 关闭
 /// </summary>
 /// <param name="model"></param>
 public static void Close(DatabaseEntity model)
 {
     model.MasterFile.FileStream.Close();
     model = null;
 }
Beispiel #14
0
 public void DatabaseDelete()
 {
     DatabaseEntity modelD = new DatabaseEntity { MasterFile = new DataFileEntity { FilePath = Config.DataFilePath } };
     DatabaseManage.Delete(modelD);
 }
Beispiel #15
0
 /// <summary>
 /// 打开数据库
 /// </summary>
 public static void Open()
 {
     DB = new DatabaseEntity
     {
         MasterFile = new DataFileEntity { FilePath = Config.DBMasterPath }
     };
     DatabaseManage.Read(DB);
     DB.ID = DBMASTER_ID;
 }
Beispiel #16
0
 /// <summary>
 /// 启动
 /// </summary>
 public static void Start()
 {
     if (!File.Exists(Config.DBMasterPath))
     {
         DBMaster.Create();
     }
     //打开主数据库
     DBMaster.Open();
     ListDB = new List<DatabaseEntity>();
     ListDB.Add(DBMaster.DB);
     //寻找其他数据库
     DataTableEntity modelDT = new DataTableEntity { Name = "Database" };
     modelDT = DataTableManage.Read(DBMaster.DB, modelDT);
     string[] listColumn = new string[] { "Name" };
     List<DataRowEntity> listDR = DataRowManage.Read(modelDT,
         new string[] { "ID", "Name", "Path" } ,
         new DataWhereEntity[] { new DataWhereEntity { ColumnName = "ID", Predicate = info => Convert.ToInt32(info) != 1 } });
     //逐个打开
     foreach (DataRowEntity modelDR in listDR)
     {
         DatabaseEntity modelDB = new DatabaseEntity
         {
             MasterFile = new DataFileEntity { FilePath = modelDR.Contents[2].ToString() }
         };
         DatabaseManage.Read(modelDB);
         modelDB.ID = Convert.ToInt32(modelDR.Contents[0]);
         ListDB.Add(modelDB);
     }
     IsRun = true;
 }
 /// <summary>
 /// 读取
 /// </summary>
 public static DataTableEntity Read(DatabaseEntity modelD, DataTableEntity modelDT)
 {
     foreach(DataTableEntity modelTemp in modelD.Tables.Where(info=>info.Name==modelDT.Name))
     {
         return modelTemp;
     }
     return null;
 }
 /// <summary>
 /// 创建
 /// </summary>
 public static void Create(DatabaseEntity model)
 {
     model.MasterFile.Database = model;
     DataFileManage.Create(model.MasterFile);
 }
 /// <summary>
 /// 页面初始化
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Page_Init(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(Request.QueryString["DatabaseID"]))
     {
         DB = Manage.ListDB.First(info => info.ID == Convert.ToInt32(Request.QueryString["DatabaseID"]));
     }
 }
 /// <summary>
 /// 删除
 /// </summary>
 public static void Delete(DatabaseEntity model)
 {
     DataFileManage.Delete(model.MasterFile);
 }