Exemple #1
0
 public static void Show(DB_ERROR dbe)
 {
     if (dbe == DB_ERROR.DB_CANT_CONNECT)
     {
         MessageBox.Show("数据库无法连接");
     }
     else if (dbe == DB_ERROR.DB_TABLE_CRACK)
     {
         MessageBox.Show("数据库表损坏,无法重建");
     }
     else if (dbe == DB_ERROR.DB_DATA_NOT_EXISTS)
     {
         MessageBox.Show("数据不存在");
     }
     else if (dbe == DB_ERROR.DB_TABLE_CRACK_FIX)
     {
         MessageBox.Show("数据库损坏,已修复");
     }
     else if (dbe == DB_ERROR.DB_USER_TABLE_EXISTS)
     {
         MessageBox.Show("用户数据已经存在");
     }
     else if (dbe == DB_ERROR.DB_USER_EXISTS)
     {
         MessageBox.Show("用户已经存在");
     }
     else if (dbe == DB_ERROR.DB_DATA_CANT_USE)
     {
         MessageBox.Show("数据不可用");
     }
     else if (dbe == DB_ERROR.DB_OK)
     {
     }
 }
Exemple #2
0
 public static void Show(DB_ERROR dbe)
 {
     if (dbe == DB_ERROR.DB_CANT_CONNECT)
     {
         MessageBox.Show("数据库无法连接");
     }
     else if (dbe == DB_ERROR.DB_TABLE_CRACK)
     {
         MessageBox.Show("数据库表损坏,无法重建");
     }
     else if (dbe == DB_ERROR.DB_DATA_NOT_EXISTS)
     {
         MessageBox.Show("数据不存在");
     }
     else if (dbe == DB_ERROR.DB_TABLE_CRACK_FIX)
     {
         MessageBox.Show("数据库损坏,已修复");
     }
     else if (dbe == DB_ERROR.DB_USER_TABLE_EXISTS)
     {
         MessageBox.Show("用户数据已经存在");
     }
     else if (dbe == DB_ERROR.DB_USER_EXISTS)
     {
         MessageBox.Show("用户已经存在");
     }
     else if (dbe == DB_ERROR.DB_DATA_CANT_USE)
     {
         MessageBox.Show("数据不可用");
     } 
     else if (dbe == DB_ERROR.DB_OK) 
     {
     }
 }
Exemple #3
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);
            }
        }
Exemple #4
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); //运算结果
        }
Exemple #5
0
 //初始化检测
 private DB_ERROR Check()
 {
     if (DBConnection())                     //连接检测
     {
         DB_ERROR dbe = DBCheckTable();      //数据库表检测
         if (dbe == DB_ERROR.DB_TABLE_CRACK) //表损坏
         {
             file_conn.Close();
             try { File.Delete(dbPath); }//删除表
             catch (Exception)
             {
                 return(dbe);//表损坏
             }
             file_conn.Open();
             if (DBCheckTable() == DB_ERROR.DB_DATA_NOT_EXISTS) //重建表
             {
                 return(DB_ERROR.DB_TABLE_CRACK_FIX);           //表修复
             }
             else
             {
                 return(dbe);
             }
         }
         else
         {
             return(dbe);//数据库正常或者数据不存在
         }
     }
     else
     {
         return(DB_ERROR.DB_CANT_CONNECT);//数据库无法连接
     }
 }
        private UserPanelController(ref DBDelegateBridge.UIMoney uim, ref DBDelegateBridge.UIStockHold uis, ref InfoDelegate.SetWin setWin)
        {
            this.uim        = uim;
            this.uis        = uis;
            this.setWin     = setWin;
            usersController = new UsersController();
            DB_ERROR DBE = usersController.GetLastError();

            if (DBE == DB_ERROR.DB_DATA_NOT_EXISTS)
            {
                InputMoney dlg = new InputMoney();
                dlg.ShowDialog();
                if (dlg.m == 0)
                {
                    Application.Current.Shutdown();
                    return;
                }
                usersController.AddNewUser(dlg.n, dlg.m);
            }
            else if (DBE != DB_ERROR.DB_OK)
            {
                Adapter.ErrorAdapter.Show(DBE);
                Application.Current.Shutdown();
                return;
            }
            List <string> users = usersController.GetUserList();

            UserBoxController.Handler().setEventHandler(UserChange);
            foreach (string name in users)
            {
                //选择
                UserBoxController.Handler().Add(name, usersController.GetUserControler(name).PrincipalRead());
            }
            UserChange(users.First());
        }
Exemple #7
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);//返回数据不存在
        }
Exemple #8
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);//返回损坏并修复状态
        }
Exemple #9
0
        //错误路径的构造方式
        public void DBDataControllerCheckConnectTest()
        {
            DBDataController DBC = new DBDataController("user2", "/r/n");
            DB_ERROR         DBE = DBC.GetLastError();

            Assert.AreEqual(DB_ERROR.DB_CANT_CONNECT, DBE);//数据库无法连接
        }
Exemple #10
0
 ////默认路径数据库
 //public DBDataController()
 //{
 //    dbPath = Environment.CurrentDirectory + "\\Stock.db";
 //    user = "******";
 //    DBE = Check();
 //    delegateController = new DBDelegateBridge(this);
 //}
 ////指定用户名
 //public DBDataController(string name)
 //{
 //    dbPath = Environment.CurrentDirectory + "\\Stock.db";
 //    user = name;
 //    DBE = Check();
 //    delegateController = new DBDelegateBridge(this);
 //}
 //指定路径
 public DBDataController(string name,string path)
 {
     dbPath = path;
     user = name;
     money.name = name;
     DBE = Check();
     delegateController = new DBDelegateBridge(this);
 }
Exemple #11
0
 ////默认路径数据库
 //public DBDataController()
 //{
 //    dbPath = Environment.CurrentDirectory + "\\Stock.db";
 //    user = "******";
 //    DBE = Check();
 //    delegateController = new DBDelegateBridge(this);
 //}
 ////指定用户名
 //public DBDataController(string name)
 //{
 //    dbPath = Environment.CurrentDirectory + "\\Stock.db";
 //    user = name;
 //    DBE = Check();
 //    delegateController = new DBDelegateBridge(this);
 //}
 //指定路径
 public DBDataController(string name, string path)
 {
     dbPath             = path;
     user               = name;
     money.name         = name;
     DBE                = Check();
     delegateController = new DBDelegateBridge(this);
 }
Exemple #12
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")); //检测数据库是否生成
        }
Exemple #13
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());
            }
        }
Exemple #14
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);
        }
Exemple #15
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);
        }
Exemple #16
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);
            }
        }
Exemple #17
0
 //指定数据库
 public UsersController(string path)
 {
     dbPath = path;
     DBE    = Check();
 }
Exemple #18
0
 //默认数据库
 public UsersController()
 {
     dbPath = "Stock.db";
     DBE    = Check();
 }
Exemple #19
0
 //默认数据库
 public UsersController()
 {
     dbPath = "Stock.db";
     DBE = Check();
 }
Exemple #20
0
 //指定数据库
 public UsersController(string path)
 {
     dbPath = path;
     DBE = Check();
 }