Beispiel #1
0
        static void Test8()
        {
            XCode.Setting.Current.Debug = false;

            var dal = UserX.Meta.Session.Dal;
            var dt  = UserX.Meta.Table.DataTable;

            dal.Db.ShowSQL = false;

            var page = new PageParameter
            {
                RetrieveTotalCount = true,
                RetrieveState      = true,
                PageIndex          = 1,
                PageSize           = 20
            };
            var list = UserX.FindAll(UserX._.ID < 10000, page);

            dal.Backup(dt.TableName);

            //File.Delete("member2.db");
            DAL.AddConnStr("member2", "Server=.;Port=3306;Database=member2;Uid=root;Pwd=root;", null, "MySql");
            var dal2 = DAL.Create("member2");

            dal2.Db.ShowSQL = false;
            dal2.Restore("user.table", dt);

            //dal.BackupAll(null, "backup", true);
            //dal2.RestoreAll("backup");
        }
Beispiel #2
0
        static void Test2()
        {
            UserX.Meta.Session.Dal.Db.ShowSQL = true;
            Log.Meta.Session.Dal.Db.ShowSQL   = true;
            //var sb = new StringBuilder();
            //sb.Append("HelloWorld");
            //sb.Length--;
            //sb.Append("Stone");
            //Console.WriteLine(sb.ToString());

            //DAL.AddConnStr("Log", "Data Source=tcp://127.0.0.1/ORCL;User Id=scott;Password=tiger;UseParameter=true", null, "Oracle");
            //DAL.AddConnStr("Log", "Server=.;Port=3306;Database=Log;Uid=root;Pwd=root;", null, "MySql");
            //DAL.AddConnStr("Membership", "Server=.;Port=3306;Database=times;Uid=root;Pwd=Pass@word;TablePrefix=xx_", null, "MySql");
            //DAL.AddConnStr("Membership", @"Server=.\JSQL2008;User ID=sa;Password=sa;Database=Membership;", null, "sqlserver");
            //DAL.AddConnStr("Log", @"Server=.\JSQL2008;User ID=sa;Password=sa;Database=Log;", null, "sqlserver");

            var gs    = UserX.FindAll(null, null, null, 0, 10);
            var count = UserX.FindCount();

            Console.WriteLine("Count={0}", count);

            LogProvider.Provider.WriteLog("test", "新增", "学无先后达者为师");
            LogProvider.Provider.WriteLog("test", "新增", "学无先后达者为师");
            LogProvider.Provider.WriteLog("test", "新增", "学无先后达者为师");

            var list = new List <UserX>();

            for (var i = 0; i < 4; i++)
            {
                var entity = new UserX
                {
                    Name         = "Stone" + i,
                    DisplayName  = "大石头" + i,
                    Logins       = 1,
                    LastLogin    = DateTime.Now,
                    RegisterTime = DateTime.Now
                };
                list.Add(entity);
                entity.SaveAsync();
                //entity.InsertOrUpdate();
            }
            //list.Save();

            var user = gs.FirstOrDefault();

            if (user != null)
            {
                user.Logins++;
                user.SaveAsync();
            }

            Thread.Sleep(3000);

            count = UserX.FindCount();
            Console.WriteLine("Count={0}", count);
            //gs = UserX.FindAll(null, null, null, 0, 10);

            //gs.Delete(true);
        }
Beispiel #3
0
        static void Test2()
        {
            var sb = new StringBuilder();

            sb.Append("HelloWorld");
            sb.Length--;
            sb.Append("Stone");
            Console.WriteLine(sb.ToString());

            //DAL.AddConnStr("Log", "Data Source=tcp://127.0.0.1/ORCL;User Id=scott;Password=tiger;UseParameter=true", null, "Oracle");
            //DAL.AddConnStr("Log", "Server=.;Port=3306;Database=times;Uid=root;Pwd=Pass@word;", null, "MySql");
            //DAL.AddConnStr("Membership", "Server=.;Port=3306;Database=times;Uid=root;Pwd=Pass@word;TablePrefix=xx_", null, "MySql");

            var gs = UserX.FindAll(null, null, null, 0, 10);

            Console.WriteLine(gs.First().Logins);
            var count = UserX.FindCount();

            Console.WriteLine("Count={0}", count);

            LogProvider.Provider.WriteLog("test", "新增", "学无先后达者为师");
            LogProvider.Provider.WriteLog("test", "新增", "学无先后达者为师");
            LogProvider.Provider.WriteLog("test", "新增", "学无先后达者为师");

            var list = new List <UserX>();

            for (var i = 0; i < 4; i++)
            {
                var entity = new UserX
                {
                    Name         = "Stone",
                    DisplayName  = "大石头",
                    Logins       = 1,
                    LastLogin    = DateTime.Now,
                    RegisterTime = DateTime.Now
                };
                list.Add(entity);
                entity.SaveAsync();
                //entity.InsertOrUpdate();
            }
            //list.Save();

            var user = gs.First();

            user.Logins++;
            user.SaveAsync();

            count = UserX.FindCount();
            Console.WriteLine("Count={0}", count);
            gs = UserX.FindAll(null, null, null, 0, 10);
            Console.WriteLine(gs.First().Logins);
        }
Beispiel #4
0
        static void Test2()
        {
            //EntityBuilder.Build(@"E:\X\NewLife.CMX\Src\NewLife.CMX\\CMX.xml");

            //EntityAssembly.Debug = true;
            //var dal = DAL.Create("Membership");
            //var fact = dal.CreateOperate("User");
            //Console.WriteLine(fact.Count);

            var list = UserX.FindAll();

            Console.WriteLine(list?.Count);
        }
Beispiel #5
0
        static void Test4()
        {
            var pis = typeof(B).GetProperties();

            Console.WriteLine(pis);

            var user = UserX.FindAll()[0];

            //Console.WriteLine(user);
            user.RegisterTime = DateTime.Now;

            //var sb = new StringBuilder();

            //var json = new Json();
            //json.Log = XTrace.Log;
            //json.Write(sb, user);

            //Console.WriteLine(sb.ToString());

            //Console.WriteLine(user.ToJson(true));

            //var type = "JsonWriter".GetTypeEx();
            //var txt = (String)type.CreateInstance().Invoke("ToJson", user, true);
            //Console.WriteLine(txt);

            //JsonTest.Start();

            //// 为所有Json宿主创建实例
            //var hosts = typeof(IJsonHost).GetAllSubclasses().Select(e => e.CreateInstance() as IJsonHost).ToArray();

            //var json = hosts[2].Write(user);
            //Thread.Sleep(1000);
            //Console.Clear();

            //CodeTimer.ShowHeader("Json序列化性能测试");
            //foreach (var item in hosts)
            //{
            //    CodeTimer.TimeLine(item.GetType().Name, 100000, n => { item.Write(user); });
            //}

            //Console.WriteLine();
            //CodeTimer.ShowHeader("Json反序列化性能测试");
            //foreach (var item in hosts)
            //{
            //    CodeTimer.TimeLine(item.GetType().Name, 100000, n => { item.Read(json, user.GetType()); });
            //}
        }
Beispiel #6
0
        static void Test7()
        {
            var dal = UserX.Meta.Session.Dal;

            dal.Db.DataCache = 3;

            var list = UserX.FindAll();
            var u    = UserX.FindByID(1);
            var n    = UserX.FindCount();

            var sql = "select * from user";
            var ds  = dal.Select(sql);

            ds = dal.Select(sql, CommandType.Text);
            ds = dal.Select(sql, CommandType.Text, new Dictionary <String, Object>());
            var dt = dal.Query(sql, new Dictionary <String, Object>());

            n = dal.SelectCount(sql, CommandType.Text);

            var sb = SelectBuilder.Create("select roleid,count(*) from user group by roleid order by count(*) desc");

            ds = dal.Select(sb, 3, 5);
            dt = dal.Query(sb, 4, 6);
            n  = dal.SelectCount(sb);

            for (var i = 0; i < 10; i++)
            {
                Console.WriteLine(i);

                list = UserX.FindAll();
                u    = UserX.FindByKey(1);
                n    = UserX.FindCount();

                ds = dal.Select(sql);
                ds = dal.Select(sql, CommandType.Text);
                ds = dal.Select(sql, CommandType.Text, new Dictionary <String, Object>());
                dt = dal.Query(sql, new Dictionary <String, Object>());
                n  = dal.SelectCount(sql, CommandType.Text);

                ds = dal.Select(sb, 3, 5);
                dt = dal.Query(sb, 4, 6);
                n  = dal.SelectCount(sb);

                Thread.Sleep(1000);
            }
        }
Beispiel #7
0
        static void Test4()
        {
            //var list = Role.FindAll();
            //Console.WriteLine(list.Count);

            var gs = UserX.FindAll(null, null, null, 0, 10);

            Console.WriteLine(gs.First().Logins);
            var count = UserX.FindCount();

            Console.WriteLine("Count={0}", count);

            LogProvider.Provider.WriteLog("test", "新增", "学无先后达者为师");
            LogProvider.Provider.WriteLog("test", "新增", "学无先后达者为师");
            LogProvider.Provider.WriteLog("test", "新增", "学无先后达者为师");

            var list = new List <UserX>();

            for (var i = 0; i < 4; i++)
            {
                var entity = new UserX
                {
                    Name         = "Stone",
                    DisplayName  = "大石头",
                    Logins       = 1,
                    LastLogin    = DateTime.Now,
                    RegisterTime = DateTime.Now
                };
                list.Add(entity);
                entity.SaveAsync();
                //entity.InsertOrUpdate();
            }
            //list.Save();

            var user = gs.First();

            user.Logins++;
            user.SaveAsync();

            count = UserX.FindCount();
            Console.WriteLine("Count={0}", count);
            gs = UserX.FindAll(null, null, null, 0, 10);
            Console.WriteLine(gs.First().Logins);
        }
Beispiel #8
0
        /// <summary>用户搜索</summary>
        /// <param name="roleId"></param>
        /// <param name="departmentId"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public ActionResult UserSearch(Int32 roleId = 0, Int32 departmentId = 0, String key = null)
        {
            var exp = new WhereExpression();

            if (roleId > 0)
            {
                exp &= UserX._.RoleID == roleId;
            }
            if (departmentId > 0)
            {
                exp &= UserX._.DepartmentID == departmentId;
            }
            exp &= UserX._.Enable == true;
            if (!key.IsNullOrEmpty())
            {
                exp &= UserX._.Code.StartsWith(key) | UserX._.Name.StartsWith(key) | UserX._.DisplayName.StartsWith(key) | UserX._.Mobile.StartsWith(key);
            }

            var page = new PageParameter {
                PageSize = 20
            };

            // 默认排序
            if (page.Sort.IsNullOrEmpty())
            {
                page.Sort = UserX._.Name;
            }

            var list = UserX.FindAll(exp, page);

            return(Json(0, null, list.Select(e => new
            {
                e.ID,
                e.Code,
                e.Name,
                e.DisplayName,
                //e.DepartmentID,
                DepartmentName = e.Department?.ToString(),
            }).ToArray()));
        }
Beispiel #9
0
 private void navBarItem2_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
 {
     if (this.IsHandleCreated)
     {
         System.Diagnostics.Trace.WriteLine("navBarItem2_LinkClicked");
         System.Diagnostics.Debug.WriteLine("navBarItem2_LinkClicked");
         IList <UserX> listUser = UserX.FindAll();
         if (listUser.Count > 0)
         {
             if (bindingSourceMain.DataSource == null)
             {
                 bindingSourceMain.DataSource = new BindingSource(listUser, null);
             }
             else
             {
                 bindingSourceMain.Clear();
                 foreach (var eachvar in listUser)
                 {
                     bindingSourceMain.Add(eachvar);
                 }
             }
         }
     }
 }
Beispiel #10
0
        static void Test7()
        {
            var set = XCode.Setting.Current;

            //set.Debug = true;
            set.ShowSQL = false;

            //XCode.Cache.CacheBase.Debug = true;

            var dal = UserX.Meta.Session.Dal;

            dal.Db.DataCache = 3;

            var list = UserX.FindAll(null, null, null, 1, 20);
            var u    = UserX.FindByKey(1);
            var n    = UserX.FindCount();

            Console.WriteLine("总数据:{0:n0}", n);

            //using (var tr = UserX.Meta.CreateTrans())
            //{
            //    u = new UserX
            //    {
            //        Name = Rand.NextString(8),
            //        DisplayName = Rand.NextString(16)
            //    };
            //    u.Insert();

            //    if (Rand.Next(2) == 1) tr.Commit();
            //}
            Task.Run(() =>
            {
                var us = new List <UserX>();
                for (var i = 0; i < 1_000_000; i++)
                {
                    var entity = new UserX
                    {
                        Name        = Rand.NextString(8),
                        DisplayName = Rand.NextString(16)
                    };
                    us.Add(entity);
                }
                us.Insert(true);
            });

            var sql = "select * from user limit 20";
            var ds  = dal.Select(sql);

            ds = dal.Select(sql, CommandType.Text);
            ds = dal.Select(sql, CommandType.Text, new Dictionary <String, Object>());
            var dt = dal.Query(sql, new Dictionary <String, Object>());

            n = dal.SelectCount(sql, CommandType.Text);

            var sb = SelectBuilder.Create("select roleid,count(*) from user group by roleid order by count(*) desc");

            ds = dal.Select(sb, 3, 5);
            dt = dal.Query(sb, 4, 6);
            n  = dal.SelectCount(sb);

            for (var i = 0; i < 20; i++)
            {
                //Console.WriteLine(i);

                var sw = Stopwatch.StartNew();
                list = UserX.FindAll(null, null, null, 1, 20);
                u    = UserX.FindByKey(1);
                n    = UserX.FindCount();

                ds = dal.Select(sql);
                ds = dal.Select(sql, CommandType.Text);
                ds = dal.Select(sql, CommandType.Text, new Dictionary <String, Object>());
                dt = dal.Query(sql, new Dictionary <String, Object>());
                n  = dal.SelectCount(sql, CommandType.Text);

                ds = dal.Select(sb, 3, 5);
                dt = dal.Query(sb, 4, 6);
                n  = dal.SelectCount(sb);

                sw.Stop();
                XTrace.WriteLine("{0} {1:n0}us", i, sw.Elapsed.TotalMilliseconds * 1000);

                Thread.Sleep(1000);
            }
        }
Beispiel #11
0
 static void Test6()
 {
     var list = UserX.FindAll();
 }