Пример #1
0
        public DB_ERROR AddNewUser(string name, string path, double principal)
        {
            if (name == "" || path == "")
            {
                return(DB_ERROR.DB_DATA_CANT_USE);
            }
            if (userdict.ContainsKey(name))
            {
                return(DB_ERROR.DB_USER_TABLE_EXISTS);
            }
            DBDataController DBC = new DBDataController(name, path);
            DB_ERROR         DBE = DBC.GetLastError();

            if (DBE == DB_ERROR.DB_DATA_NOT_EXISTS)
            {
                DBC.PrincipalCreate(principal);
                UsersEntity UE;
                UE.name = name;
                UE.path = dbPath;
                users.Insert(UE);
                userdict.Add(name, DBC);
                return(DB_ERROR.DB_OK);
            }
            else if (DBE == DB_ERROR.DB_OK)
            {
                return(DB_ERROR.DB_USER_EXISTS);
            }
            else
            {
                return(DBE);
            }
        }
Пример #2
0
 public DB_ERROR AddNewUser(string name, string path, double principal)
 {
     if (name == "" || path == "")
         return DB_ERROR.DB_DATA_CANT_USE;
     if (userdict.ContainsKey(name))
         return DB_ERROR.DB_USER_TABLE_EXISTS;
     DBDataController DBC = new DBDataController(name, path);
     DB_ERROR DBE = DBC.GetLastError();
     if (DBE == DB_ERROR.DB_DATA_NOT_EXISTS)
     {
         DBC.PrincipalCreate(principal);
         UsersEntity UE;
         UE.name = name;
         UE.path = dbPath;
         users.Insert(UE);
         userdict.Add(name, DBC);
         return DB_ERROR.DB_OK;
     }
     else if (DBE == DB_ERROR.DB_OK)
     {
         return DB_ERROR.DB_USER_EXISTS;
     }
     else
     {
         return DBE;
     }
 }
Пример #3
0
 public DBDelegateBridge(DBDataController DBC)
 {
     DBDataController.MoneyDelegate money = new DBDataController.MoneyDelegate(MoneyDelegate);
     DBC.SetMoneyDelegate(money);
     DBDataController.StockHoldDelegate stockhold = new DBDataController.StockHoldDelegate(StockHoldDelegate);
     DBC.SetStockHoldDelegate(stockhold);
 }
Пример #4
0
 public DBDelegateBridge(DBDataController DBC)
 {
     DBDataController.MoneyDelegate money = new DBDataController.MoneyDelegate(MoneyDelegate);
     DBC.SetMoneyDelegate(money);
     DBDataController.StockHoldDelegate stockhold = new DBDataController.StockHoldDelegate(StockHoldDelegate);
     DBC.SetStockHoldDelegate(stockhold);
 }
Пример #5
0
 //默认创建方式 检测数据库是否出现
 public void DBDataControllerCreateTest()
 {
     File.Delete(Environment.CurrentDirectory + "\\Stock.db");//先移除默认数据库
     DBDataController DBC = new DBDataController("user1", Environment.CurrentDirectory + "\\Stock.db");
     DB_ERROR DBE = DBC.GetLastError();
     Assert.AreEqual(DB_ERROR.DB_DATA_NOT_EXISTS, DBE);//正常返回数据不存在
     Assert.IsTrue(File.Exists(Environment.CurrentDirectory + "\\Stock.db"));//检测数据库是否生成
 }
Пример #6
0
 public void DelUser(string name, string path)
 {
     users.Delete(name);
     if (userdict.ContainsKey(name))
     {
         userdict[name].DeleteAll();
         userdict.Remove(name);
     }
     else
     {
         DBDataController DBC = new DBDataController(name, dbPath);
         DBC.DeleteAll();
     }
 }
Пример #7
0
 //数据库Principal读写测试
 public void DBDataControllerPrincipalTest()
 {
     File.Delete(Environment.CurrentDirectory + "\\Stock2.db");
     DBDataController DBC = new DBDataController("user7", Environment.CurrentDirectory + "\\Stock2.db");
     DB_ERROR DBE = DBC.GetLastError();
     DBC.PrincipalCreate(100000000000000.00);
     Assert.AreEqual(100000000000000.00, DBC.PrincipalRead());
     for (int i = 0; i < 100; i++)
     {
         double a = DBC.PrincipalRead();
         double m = 12.34 * i;
         DBC.PrincipalChange(m);
         Assert.AreEqual((a + m).ToString(), DBC.PrincipalRead().ToString());
     }
 }
Пример #8
0
 //数据库DealList读写测试
 public void DBDataControllerDealListTest()
 {
     File.Delete(Environment.CurrentDirectory + "\\Stock1.db");
     DBDataController DBC = new DBDataController("user6", Environment.CurrentDirectory + "\\Stock1.db");
     DB_ERROR DBE = DBC.GetLastError();
     DealListEntity DLE = new DealListEntity();
     DLE.id = "600001";
     DLE.name = "邯郸钢铁";
     DBC.DealListAdd(DLE);//存入一条数据
     List<DealListEntity> DLEL;
     DBC.DealListReadAll(out DLEL);//读取
     Assert.AreEqual(1, DLEL.Count);
     Assert.AreEqual(DLE.id, DLEL[0].id);//判断读取与存入的数据是否一致
     Assert.AreEqual(DLE.name, DLEL[0].name);
 }
Пример #9
0
 //增加到dict中
 public DB_ERROR AddUser(string name, string path)
 {
     if (userdict.ContainsKey(name))
         return DB_ERROR.DB_USER_TABLE_EXISTS;
     DBDataController DBC = new DBDataController(name, path);
     DB_ERROR DBE = DBC.GetLastError();
     if (DBE == DB_ERROR.DB_OK)
     {
         userdict.Add(name, DBC);
         return DB_ERROR.DB_OK;
     }
     else
     {
         DBC.DeleteAll();
         return DBE;
     }
 }
Пример #10
0
        //增加到dict中
        public DB_ERROR AddUser(string name, string path)
        {
            if (userdict.ContainsKey(name))
            {
                return(DB_ERROR.DB_USER_TABLE_EXISTS);
            }
            DBDataController DBC = new DBDataController(name, path);
            DB_ERROR         DBE = DBC.GetLastError();

            if (DBE == DB_ERROR.DB_OK)
            {
                userdict.Add(name, DBC);
                return(DB_ERROR.DB_OK);
            }
            else
            {
                DBC.DeleteAll();
                return(DBE);
            }
        }
Пример #11
0
 public static void setDBDataController(ref DBDataController DBC_)
 {
     DBC = DBC_;
 }
Пример #12
0
 public static DBDataThreadController DBDataThreadControllerHandler(DBDataController DBC)
 {
     return new DBDataThreadController(DBC);
 }
Пример #13
0
 private DBDataThreadController(DBDataController DBC)
 {
     this.DBC = DBC;
 }
Пример #14
0
 public static DBDataThreadController DBDataThreadControllerHandler(DBDataController DBC)
 {
     return(new DBDataThreadController(DBC));
 }
Пример #15
0
 private DBDataThreadController(DBDataController DBC)
 {
     this.DBC = DBC;
 }
Пример #16
0
 //crack数据库测试
 public void DBDataControllerCheckCrackTest()
 {
     DBDataController DBC = new DBDataController("user3", Environment.CurrentDirectory + "\\TestDB\\crack.db");
     DB_ERROR DBE = DBC.GetLastError();
     Assert.AreEqual(DB_ERROR.DB_TABLE_CRACK_FIX, DBE);//返回损坏并修复状态
 }
Пример #17
0
 //数据库Log读写测试
 public void DBDataControllerLogTest()
 {
     File.Delete(Environment.CurrentDirectory + "\\Stock3.db");
     DBDataController DBC = new DBDataController("user8", Environment.CurrentDirectory + "\\Stock3.db");
     DB_ERROR DBE = DBC.GetLastError();
     LogEntity LE = new LogEntity();
     LE.state = "状态";
     LE.context = "错误内容";
     DBC.LogSave(LE);//存入一条数据
     List<LogEntity> LEL;
     DBC.LogRead(out LEL);//读取
     Assert.AreEqual(1, LEL.Count);
     Assert.AreEqual(LE.state, LEL[0].state);//判断读取与存入的数据是否一致
     Assert.AreEqual(LE.context, LEL[0].context);
 }
Пример #18
0
 //没表数据库测试
 public void DBDataControllerCheckTableTest()
 {
     DBDataController DBC = new DBDataController("user5", Environment.CurrentDirectory + "\\TestDB\\noTable.db");
     DB_ERROR DBE = DBC.GetLastError();
     Assert.AreEqual(DB_ERROR.DB_DATA_NOT_EXISTS, DBE);//返回数据不存在
 }
Пример #19
0
 public void DelUser(string name, string path)
 {
     users.Delete(name);
     if (userdict.ContainsKey(name))
     {
         userdict[name].DeleteAll();
         userdict.Remove(name);
     }
     else
     {
         DBDataController DBC = new DBDataController(name, dbPath);
         DBC.DeleteAll();
     }
 }
Пример #20
0
 //错误路径的构造方式
 public void DBDataControllerCheckConnectTest()
 {
     DBDataController DBC = new DBDataController("user2", "/r/n");
     DB_ERROR DBE = DBC.GetLastError();
     Assert.AreEqual(DB_ERROR.DB_CANT_CONNECT, DBE);//数据库无法连接
 }
Пример #21
0
 private void user_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     string u = ((ComboBoxItem)(((ComboBox)sender).SelectedItem)).Content.ToString();
     DBC = UserPanelController.Handler().DBControllerByName(u);
 }
Пример #22
0
 //数据库StockHold读测试
 public void DBDataControllerStockHoldTest()
 {
     File.Delete(Environment.CurrentDirectory + "\\Stock4.db");
     DBDataController DBC = new DBDataController("user9", Environment.CurrentDirectory + "\\Stock4.db");
     DB_ERROR DBE = DBC.GetLastError();
     DealListEntity DLE = new DealListEntity();
     DLE.id = "600001";
     DLE.name = "邯郸钢铁";
     DLE.money = 10.11;
     DLE.number = 400;
     DLE.type = "买入";
     DBC.DealListAdd(DLE);//存入一条数据
     DLE.id = "600001";
     DLE.name = "邯郸钢铁";
     DLE.money = 5.11;
     DLE.number = 200;
     DLE.type = "卖出";
     DBC.DealListAdd(DLE);//再存入一条数据
     List<StockHoldEntity> SHEL;
     DBC.StockHoldReadAll(out SHEL);
     Assert.AreEqual(1, SHEL.Count);
     Assert.AreEqual(DLE.id, SHEL[0].id);//判断读取与存入的数据是否一致
     Assert.AreEqual(DLE.name, SHEL[0].name);
     Assert.AreEqual(200, SHEL[0].hold);//运算结果
     Assert.AreEqual(3022, SHEL[0].money);//运算结果
 }