Пример #1
0
        public void TestSQLite()
        {
            string dbPath = ".\\Example.db3";
            //如果不存在改数据库文件,则创建该数据库文件 
            if (!System.IO.File.Exists(dbPath))
            {
                CreateDB(dbPath);
            }

            var u = new ExUsers();
            u.Name = "张三";
            u.Age = 23;
            u.Email = "*****@*****.**";
            u.Status = 2;
            //OyEngine<ExUsers>.Insert(u);

            var cd = new OyCondition(ExUsers.sTatus, ConditionOperator.NotEqual, 9)
                & new OyCondition(ExUsers.aGe, ConditionOperator.Greater, 1);
            var mp = new MPager { PageIndex = 1, PageSize = 2 };
            var us = OyEngine<ExUsers>.Filter(cd, mp);
            if (us != null && us.Count > 0)
            {
                u = us[0];
            }

            OyEngine<ExUsers>.Update(
                new OyValue(ExUsers.nAme, "张山是个好名字")
                & new OyValue(ExUsers.eMail, "*****@*****.**")
                , new OyCondition(ExUsers.iD, u.Id));
        }
Пример #2
0
 public IList<IModel> Filter(IModel m, Condition condition, MPager mp = null, OrderBy orderby = null)
 {
     var dic = FilterWithId(m, condition, mp, orderby);
     if (dic != null && dic.Count > 0)
     {
         return dic.Values.ToList();
     }
     return null;
 }
Пример #3
0
        public IDictionary<long, IModel> FilterWithId(IModel m, Condition condition, MPager mp = null, OrderBy orderby = null)
        {
            if (m == null)
            {
                throw new Exception("Model Class Must Implements the interface IModel");
            }
            string sqlexp = "select {0} from {1} where {2} ";
            var dicols = MReflection.GetModelColumns(m);
            string columns = string.Join(",", dicols.Values);

            var plist = Db.DbEngine.NewParameters();
            string condstr = condition.ToString(m, plist);
            string orderbystr = orderby == null ? "" : orderby.ToString(m);
            string sql = string.Format(sqlexp, new string[] { columns, m.zTableName, condstr });

            if (mp != null)
            {
                sql = DbEngine.Instance.GetPagerSql(sql, orderbystr, mp.PageIndex, mp.PageSize, out mp.TotalCount, plist.Values.ToArray());
            }
            else
            {
                sql += orderbystr;
            }

            var ds = DbEngine.Instance.ExecuteQuery(sql, plist.Values.ToArray());

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                var dic = BindData.BindDataByTableWithId(m.zModelType, ds.Tables[0]);
                if (dic != null && dic.Count > 0)
                {
                    Dictionary<long, IModel> ddd = new Dictionary<long, IModel>();
                    foreach (var d in dic.Keys)
                    {
                        ddd.Add(d, dic[d] as IModel);
                    }
                    return ddd;
                }
            }
            return new Dictionary<long, IModel>();
        }
Пример #4
0
 public ActionResult _MPage(int _mpindex = 1, int _mpsize = 20)
 {
     ViewData["_MP"] = new MPager { PageIndex = _mpindex, PageSize = _mpsize };
     return View();
 }