Esempio n. 1
0
        static void TestMultipleDatabases()
        {
            string readKey  = "readKey",
                   wirteKey = "wirteKey";

            ConnectionBuilder.ConfigRegist("Data Source=.;Initial Catalog = AdminLTE.Net.DB;User ID=sa;Password =mimashi123", DBType.SqlServer2012, readKey);
            ConnectionBuilder.ConfigRegist("Data Source=.;Initial Catalog = LoadDB;User ID=sa;Password =mimashi123", DBType.SqlServer2012, wirteKey);

            var userInfo_ReadRepo  = new Repository <UserInfo>(readKey);
            var userInfo_WirteRepo = new Repository <UserInfo>(wirteKey);

            CRUDbyRepo(userInfo_WirteRepo);
            CRUDbyRepo(userInfo_ReadRepo);
        }
Esempio n. 2
0
        /// <summary>
        /// SQLite
        /// </summary>
        static void TestSQLite()
        {
            //System.Data.SQLite.SQLiteConnection.CreateFile("SqliteDemo");
            ConnectionBuilder.ConfigRegist("Data Source=SqliteDemo;Version=3;", DBType.SQLite);

            var repoUserInfo = new Repository <UserInfo>();

            //repoUserInfo.Execute(@"CREATE TABLE T_User
            //                         (
            //                         Id Integer Primary Key Autoincrement,
            //                         UserName VARCHAR(50),
            //                         Password VARCHAR(50),
            //                         Name NVARCHAR(50),
            //                         Sex Integer,
            //                         Phone VARCHAR(20),
            //                         Enable Integer,
            //                         CreateTime DATETIME
            //                         )", null);
            //var datas = TestData();
            //repoUserInfo.Insert(datas);

            var list = repoUserInfo.QueryList();

            var page1 = repoUserInfo.QueryList(1, 5);
            var page2 = repoUserInfo.QueryList(2, 5);
            var page3 = repoUserInfo.QueryList(3, 5);

            var  model = repoUserInfo.Query(2);
            bool b     = repoUserInfo.Delete(model);

            list = repoUserInfo.QueryList();

            model       = repoUserInfo.Query(3);
            model.Phone = "1234567";
            bool ub = repoUserInfo.Update(model);

            list = repoUserInfo.QueryList(order: "order by id");
            UserInfo newUser = new UserInfo()
            {
                Name         = "Lio.Huang",
                UserNameFiel = "Lio.Huang",
                Phone        = "12346578",
                Enable       = 1,
                Password     = "******",
                Sex          = 1,
                CreateTime   = DateTime.Now
            };
            int id = (int)repoUserInfo.Insert(newUser);
        }
Esempio n. 3
0
        /// <summary>
        /// SQLServer
        /// </summary>
        static void TestSQLServer()
        {
            ConnectionBuilder.ConfigRegist("Data Source=.;Initial Catalog = AdminLTE.Net.DB;User ID=sa;Password =mimashi123", DBType.SqlServer2012);
            var repoUserInfo = new Repository <UserInfo>();

            //repoUserInfo.Execute(@"CREATE TABLE T_User
            //                         (
            //                         Id INT PRIMARY KEY IDENTITY(1,1),
            //                         UserName VARCHAR(50),
            //                         Password VARCHAR(50),
            //                         Name NVARCHAR(50),
            //                         Sex INT,
            //                         Phone VARCHAR(20),
            //                         Enable INT,
            //                         CreateTime DATETIME
            //                         )", null);
            //var datas = TestData();
            //repoUserInfo.Insert(datas);

            var list = repoUserInfo.QueryList();

            var page1 = repoUserInfo.QueryList(1, 5, "Id>@Id", new { Id = 6 });
            var page2 = repoUserInfo.QueryList(2, 5, "Id>@Id", new { Id = 6 });
            var page3 = repoUserInfo.QueryList(3, 5, "Id>@Id", new { Id = 6 });

            var  model = repoUserInfo.Query(list[0].Id);
            bool b     = repoUserInfo.Delete(model);

            list = repoUserInfo.QueryList();

            model       = repoUserInfo.Query(list[0].Id);
            model.Phone = "1234567";
            bool ub = repoUserInfo.Update(model);

            list = repoUserInfo.QueryList(order: "order by id");
            UserInfo newUser = new UserInfo()
            {
                Name         = "Lio.Huang",
                UserNameFiel = "Lio.Huang",
                Phone        = "12346578",
                Enable       = 1,
                Password     = "******",
                Sex          = 1,
                CreateTime   = DateTime.Now
            };
            int id = (int)repoUserInfo.Insert(newUser);
        }
Esempio n. 4
0
        /// <summary>
        /// MySQL
        /// </summary>
        static void TestMySQL()
        {
            ConnectionBuilder.ConfigRegist("server=192.168.23.129;port=3306;database=tempdb;user=root;password=mimashi123;", DBType.MySQL);

            var repoUserInfo = new Repository <UserInfo>();
            //repoUserInfo.Execute(@"CREATE TABLE IF NOT EXISTS `T_User`(
            //                           `Id` int auto_increment primary key ,
            //                           `UserName` VARCHAR(100) NOT NULL,
            //                           `Password` VARCHAR(40) NOT NULL,
            //                           `Name` VARCHAR(20),
            //                           `Sex` int,
            //                           `Phone` VARCHAR(20),
            //                           `Enable` INT,
            //                           `CreateTime` DATETIME
            //                        )  CHARSET=utf8;", null);
            //var datas = TestData();
            //repoUserInfo.Insert(datas);
            var list = repoUserInfo.QueryList();

            var page1 = repoUserInfo.QueryList(1, 5, "Phone is not null", order: "ID", asc: true);
            var page2 = repoUserInfo.QueryList(2, 5);
            var page3 = repoUserInfo.QueryList(3, 5);

            var  model = repoUserInfo.Query(2);
            bool b     = repoUserInfo.Delete(model);

            list = repoUserInfo.QueryList();

            model       = repoUserInfo.Query(3);
            model.Phone = "1234567";
            bool ub = repoUserInfo.Update(model);

            list = repoUserInfo.QueryList(order: "order by id");
            UserInfo newUser = new UserInfo()
            {
                Name         = "Lio.Huang",
                UserNameFiel = "Lio.Huang",
                Phone        = "12346578",
                Enable       = 1,
                Password     = "******",
                Sex          = 1,
                CreateTime   = DateTime.Now
            };
            int id = (int)repoUserInfo.Insert(newUser);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            if (File.Exists("LocadDB.Sqlite"))
            {
                File.Delete("LocadDB.Sqlite");
            }
            SQLiteConnection.CreateFile(@"LocadDB.Sqlite");

            ConnectionBuilder.ConfigRegist("Data Source=LocadDB.Sqlite;Version=3;", Banana.Uow.Models.DBType.SQLite);
            int idx = 1;

            Show(ref idx, "初始化");
            InitDb();

            Show(ref idx, "分类表");
            CreateTestData_Category();
            Show(ref idx, "导航表");
            CreateTestData_NavigationInfo();
            Show(ref idx, "友情链接表");
            CreateTestData_FriendlyLinkInfo();
            Show(ref idx, "图片轮播表");
            CreateTestData_ImagePlay();
            Show(ref idx, "新闻表");
            CreateTestData_NewsInfo();
            Show(ref idx, "网站主体表");
            CreateTestData_OwnerInfo();
            Show(ref idx, "内容表");
            CreateTestData_PageContentInfo();
            Show(ref idx, "招聘表");
            CreateTestData_RecruitmentInfo();
            Show(ref idx, "其他配置表");
            CreateTestData_SystemConfig();
            Show(ref idx, "用户表");
            CreateTestData_User();
            Show(ref idx, "测试数据加入完成");

            Show(ref idx, "请把【LocadDB.Sqlite】数据库文件复制到【GeneralCMS.Admin】和【GeneralCMS.Web】下以便测试效果");
            System.Threading.Thread.Sleep(5000);
        }
Esempio n. 6
0
        static void TestExplicitKey()
        {
            ConnectionBuilder.ConfigRegist("Data Source=.;Initial Catalog = AdminLTE.Net.DB;User ID=sa;Password =mimashi123", DBType.SqlServer);
            var repoStudent = new Repository <Student>();

            var t  = repoStudent.DBConnection.GetType();
            var s1 = new Student()
            {
                Id         = Guid.NewGuid().ToString("N"),
                Name       = "Lio.Huang",
                LinkPhone  = "15522223333",
                Sex        = 1,
                CreateTime = Convert.ToDateTime("2019-01-03")
            };
            var bIn = repoStudent.Insert(s1);

            var model = repoStudent.Query(s1.Id);

            var list = repoStudent.QueryList();

            list[0].Name = "Banana";
            var b = repoStudent.Update(list[0]);
        }
Esempio n. 7
0
        /// <summary>
        /// Oracle
        /// </summary>
        static void TestOracle()
        {
            string conn = string.Concat(
                @"Data Source=",
                @"    (DESCRIPTION=",
                @"        (ADDRESS_LIST=",
                @"            (ADDRESS=",
                @"                (PROTOCOL=TCP)",
                @"                (HOST=172.16.3.62)",
                @"                (PORT=1521)",
                @"            )",
                @"        )",
                @"        (CONNECT_DATA=",
                @"            (SERVICE_NAME=orcl.oracle.com)",
                @"        )",
                @"    );",
                @"Persist Security Info=True;",
                @"User Id=system;",
                @"Password=manager;"
                );

            ConnectionBuilder.ConfigRegist(conn, DBType.Oracle);

            var repoUserInfo = new Repository <UserModel_Oracle>();
            //create table
            //repoUserInfo.Execute(@"CREATE TABLE T_User
            //                         (
            //                         Id number primary key,
            //                         UserName varchar2(50),
            //                         Password varchar2(50),
            //                         Name varchar2(50),
            //                         Sex INTEGER,
            //                         Phone varchar2(20),
            //                         Enable INTEGER,
            //                         CreateTime DATE
            //                         )", null);
            //create sequence
            //repoUserInfo.Execute(@"CREATE SEQUENCE user_sequence
            //                        INCREMENT BY 1
            //                        START WITH 1
            //                        NOMAXVALUE
            //                        NOCYCLE
            //                        NOCACHE", null);

            //datas
            //var datas = ModelConvertUtil<UserInfo, UserModel_Oracle>.ModelCopy(TestData());
            //repoUserInfo.Insert(datas);

            var list = repoUserInfo.QueryList();

            var page1 = repoUserInfo.QueryList(1, 5);
            var page2 = repoUserInfo.QueryList(2, 5);
            var page3 = repoUserInfo.QueryList(3, 5);

            var  model = repoUserInfo.Query(2);
            bool b     = repoUserInfo.Delete(model);

            list = repoUserInfo.QueryList();

            model       = repoUserInfo.Query(3);
            model.Phone = "1234567";
            bool ub = repoUserInfo.Update(model);

            list = repoUserInfo.QueryList(order: "order by id");
            UserModel_Oracle newUser = new UserModel_Oracle()
            {
                Name       = "Lio.Huang",
                UserName   = "******",
                Phone      = "12346578",
                Enable     = 1,
                Password   = "******",
                Sex        = 1,
                CreateTime = DateTime.Now
            };
            int id = (int)repoUserInfo.Insert(newUser);

            list = repoUserInfo.QueryList();
        }