Ejemplo n.º 1
0
        /// <summary>
        /// Basic query for pagination.
        /// </summary>
        /// <param name="tableName">the table name.</param>
        /// <param name="selectClause">the select clauses.</param>
        /// <param name="dataAdapter">the data.</param>
        /// <param name="sqlCriteria">the condition.</param>
        /// <param name="recordCount">the record count of the result.</param>
        /// <returns>the result.</returns>
        protected virtual DataTable InnerQuery(string tableName, string selectClause, BeeDataAdapter dataAdapter,
                                               SqlCriteria sqlCriteria)
        {
            int pageNum     = dataAdapter.TryGetValue <int>("pagenum", 1);
            int pageSize    = dataAdapter.TryGetValue <int>("pagesize", 20);
            int recordCount = dataAdapter.TryGetValue <int>("recordcount", 0);

            string orderField     = dataAdapter.TryGetValue <string>("orderField", "Id");
            string orderDirection = dataAdapter.TryGetValue <string>("orderDirection", "desc");

            DataTable result = DbSession.Current.Query(tableName, selectClause, sqlCriteria,
                                                       "{0} {1}".FormatWith(orderField, orderDirection), pageNum, pageSize, ref recordCount);

            dataAdapter["recordcount"] = recordCount;

            return(result);
        }
Ejemplo n.º 2
0
        protected override BeeDataAdapter GetRouteData(System.Web.HttpContext context)
        {
            XmlDocument document = new XmlDocument();

            document.Load(context.Request.InputStream);

            BeeDataAdapter dataAdapter = new BeeDataAdapter();

            foreach (XmlNode node in document.DocumentElement.ChildNodes)
            {
                dataAdapter.Add(node.Name, node.InnerText);
            }

            string msgType = dataAdapter.TryGetValue <string>("msgtype", string.Empty);

            if (string.Compare("event", msgType, true) == 0)
            {
                string eventName = dataAdapter.TryGetValue <string>("event", string.Empty);

                dataAdapter.Add(Constants.BeeControllerName, MainControllerName);
                dataAdapter.Add(Constants.BeeActionName, eventName);
            }
            else
            {
                dataAdapter.Add(Constants.BeeControllerName, MainControllerName);
                dataAdapter.Add(Constants.BeeActionName, msgType);
            }

            Logger.Debug(dataAdapter.ToString());

            // 实现一个调用链

            /*
             * menuid-1-2-3
             *
             *
             */

            InvokeTreeManager.Instance.Check(dataAdapter);

            return(dataAdapter);
        }
Ejemplo n.º 3
0
        public override PageResult Index(BeeDataAdapter dataAdapter)
        {
            DbSession dbSession = GetDbSession();

            DataTable dataTable = null;

            try
            {
                InitPagePara(dataAdapter);

                EntityProxy <WeiXinUser> entityProxy = EntityProxyManager.Instance.GetEntityProxy <WeiXinUser>();

                SqlCriteria sqlCriteria = GetQueryCondition(dataAdapter);

                if (dataAdapter.ContainsKey("linkflag"))
                {
                    bool linkFlag = dataAdapter.TryGetValue <Boolean>("linkflag", false);
                    if (!linkFlag)
                    {
                        sqlCriteria.Equal("fakeid", "");
                    }
                    else
                    {
                        sqlCriteria.NotEqual("fakeid", "");
                    }
                }

                string selectClause = GetQuerySelectClause(typeof(WeiXinUser));

                dataTable = InnerQuery("WeiXinUser", selectClause, dataAdapter, sqlCriteria);
            }
            catch (Exception e)
            {
                Logger.Error("List object({0}) Error".FormatWith(typeof(WeiXinUser)), e);
            }
            finally
            {
                dbSession.Dispose();
            }

            return(View(dataTable));
        }
Ejemplo n.º 4
0
        private WeiXinInvokeTree FindCurrentInvoke(BeeDataAdapter dataAdapter)
        {
            WeiXinInvokeTree result = null;

            string        fromUserName   = dataAdapter.TryGetValue <string>("fromusername", string.Empty);
            InvokeContext currentContext = InvokeContextManager.Instance.CurrentContext(fromUserName);

            // 调用链目前仅仅关心到菜单起始的文本输入链
            string currentCommand = dataAdapter.TryGetValue <string>("content", string.Empty);

            if (string.IsNullOrEmpty(currentCommand))
            {
                currentCommand = dataAdapter.TryGetValue <string>("eventkey", string.Empty);
            }

            string eventName = dataAdapter.TryGetValue <string>("event", string.Empty);

            if (string.Compare("click", eventName, true) == 0)
            {
                currentContext.MessageStack.Clear();
            }

            WeiXinInvokeTree parentInvokeTree = null;
            int parentId = 0;

            List <string> list = (from item in currentContext.MessageStack select item.InvokeTreeName).ToList();

            list.Reverse();

            foreach (string item in list)
            {
                parentInvokeTree = FindChild(parentId, item);
                if (parentInvokeTree != null)
                {
                    parentId = parentInvokeTree.Id;
                }
                else
                {
                    break;
                }
            }

            if (parentInvokeTree != null)
            {
                parentId = parentInvokeTree.Id;
            }

            result = FindChild(parentId, currentCommand);

            if (result == null)
            {
                result = FindChild(parentId, "*");
            }


            if (result == null)
            {
                result = parentInvokeTree;
            }
            else
            {
                dataAdapter["createtime"] = DateTimeUtil.GetDateTimeFromXml(dataAdapter["createtime"].ToString());

                RequestMessage message = ConvertUtil.ConvertDataToObject <RequestMessage>(dataAdapter);
                message.InvokeTreeName = result.Name;

                currentContext.MessageStack.Push(message);
            }

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the conditions via the attribute of the modeltype and the data from page.
        /// </summary>
        /// <param name="modelType">the model type.</param>
        /// <param name="dataAdapter">the data from page.</param>
        /// <returns>the condition.</returns>
        protected virtual SqlCriteria GetQueryCondition(Type modelType, BeeDataAdapter dataAdapter)
        {
            IEntityProxy entityProxy = EntityProxyManager.Instance.GetEntityProxyFromType(modelType);
            SqlCriteria  result      = new SqlCriteria();

            dataAdapter = new BeeDataAdapter(dataAdapter);
            dataAdapter.RemoveEmptyOrNull();

            ModelAttribute modelAttribute = entityProxy.GetCustomerAttribute <ModelAttribute>();

            foreach (PropertySchema propertySchema in entityProxy.GetPropertyList())
            {
                string propertyName = propertySchema.Name;
                ModelPropertyAttribute modelPropertyAttribute
                    = propertySchema.GetCustomerAttribute <ModelPropertyAttribute>();
                if (modelPropertyAttribute != null)
                {
                    if (dataAdapter.ContainsKey(propertyName))
                    {
                        if (modelPropertyAttribute.Queryable)
                        {
                            object conditionValue = dataAdapter[propertyName];

                            if (propertySchema.PropertyType == typeof(string))
                            {
                                conditionValue = HttpUtility.HtmlDecode(conditionValue.ToString());
                            }

                            if (modelPropertyAttribute.QueryType == ModelQueryType.Equal &&
                                propertySchema.PropertyType == typeof(bool))
                            {
                                bool value = false;
                                bool.TryParse(conditionValue.ToString(), out value);
                                if (value)
                                {
                                    conditionValue = 1;
                                }
                                else
                                {
                                    conditionValue = 0;
                                }
                            }

                            if (propertySchema.PropertyType == typeof(DateTime))
                            {
                                DateTime propertyValue = dataAdapter.TryGetValue <DateTime>(propertyName, DateTime.MinValue);
                                if (propertyValue != DateTime.MinValue)
                                {
                                    conditionValue = propertyValue;
                                }
                                else
                                {
                                    // 若是时间,而又没有赋值, 则略过
                                    continue;
                                }
                            }

                            AddCondition(result, modelPropertyAttribute.QueryType, propertyName, conditionValue);
                        }
                    }
                    else
                    {
                        if (modelPropertyAttribute.Queryable &&
                            modelPropertyAttribute.QueryType == ModelQueryType.Between)
                        {
                            if (dataAdapter.ContainsKey(propertyName + "begin"))
                            {
                                if (propertySchema.PropertyType == typeof(DateTime))
                                {
                                    DateTime beginTime = dataAdapter.TryGetValue <DateTime>(propertyName + "begin", DateTime.MinValue);
                                    result.GreaterThanOrEqual(propertyName, beginTime);
                                }
                                else
                                {
                                    result.GreaterThanOrEqual(propertyName, dataAdapter[propertyName + "begin"]);
                                }
                            }

                            if (dataAdapter.ContainsKey(propertyName + "end"))
                            {
                                DateTime endTime = dataAdapter.TryGetValue <DateTime>(propertyName + "end", DateTime.MinValue);
                                if (propertySchema.PropertyType == typeof(DateTime))
                                {
                                    if (endTime == endTime.Date)
                                    {
                                        endTime = endTime.AddDays(1);
                                    }

                                    //result.LessThan(propertyName, endTime.ToString("yyyy-MM-dd"));
                                    result.LessThan(propertyName, endTime);
                                }
                                else
                                {
                                    result.LessThanOrEqual(propertyName, dataAdapter[propertyName + "end"]);
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 6
0
 public void Create2(BeeDataAdapter dataAdapter)
 {
     ThrowExceptionUtil.ArgumentConditionTrue(dataAdapter.TryGetValue <string>("name", string.Empty) == "admin", string.Empty, "not null");
 }
Ejemplo n.º 7
0
        public virtual PageResult List(BeeDataAdapter dataAdapter)
        {
            DbSession dbSession = GetDbSession();

            DataTable dataTable = null;

            try
            {
                InitPagePara(dataAdapter);

                #region datetime 处理
                EntityProxy <T> entityProxy = EntityProxyManager.Instance.GetEntityProxy <T>();

                //List<PropertySchema> propertyList = entityProxy.GetPropertyList();

                //propertyList = (from item in propertyList
                // where item.PropertyType == typeof(DateTime)
                // select item).ToList();

                BeeDataAdapter realDataAdapter = new BeeDataAdapter(dataAdapter);

                //foreach (PropertySchema item in propertyList)
                //{
                //    string beginkey = "{0}begin".FormatWith(item.Name);
                //    string endkey = "{0}end".FormatWith(item.Name);
                //    if (realDataAdapter.ContainsKey(item.Name))
                //    {
                //        realDataAdapter[item.Name] = ConvertUtil.CommonConvert<DateTime>(realDataAdapter[item.Name]);
                //    }
                //    if (realDataAdapter.ContainsKey(beginkey))
                //    {
                //        realDataAdapter[beginkey] = ConvertUtil.CommonConvert<DateTime>(realDataAdapter[beginkey]);
                //    }
                //    if (realDataAdapter.ContainsKey(endkey))
                //    {
                //        realDataAdapter[endkey] = ConvertUtil.CommonConvert<DateTime>(realDataAdapter[endkey]);
                //    }
                //}

                #endregion

                string tableName = OrmUtil.GetTableName <T>();

                SqlCriteria sqlCriteria = GetQueryCondition(realDataAdapter);

                int recordCount = dataAdapter.TryGetValue <int>("recordcount", 0);

                string selectClause = GetQuerySelectClause(typeof(T));

                dataTable = InnerQuery(tableName, selectClause, dataAdapter, sqlCriteria);
            }
            catch (Exception e)
            {
                Logger.Error("List object({0}) Error".FormatWith(typeof(T)), e);
            }
            finally
            {
                dbSession.Dispose();
            }

            return(View(null, "BeeAutoList", dataTable));
        }