private string GetVariableText(TaskInfo info)
        {
            string          text = info.Text;
            MatchCollection mc   = s_regexOwnData.Matches(text);

            foreach (Match m in mc)
            {
                string s = string.Empty;
                switch (m.Groups[1].Value.ToUpper())
                {
                case "COUNT":
                    if (!string.IsNullOrEmpty(info.SearchManagerClassName))
                    {
                        ISearchManager searchManager = ServiceProvider.GetService <IManagerFactory>().GenerateSearchManager(info.SearchManagerClassName, info.SearchManagerClassParams);
                        s = searchManager.GetCount(SearchExpression.Parse(EntityHelper.ReplaceExpression(info.SearchExpression))).ToString();

                        m_sms[info.Name] = searchManager;
                    }
                    break;

                case "EXP":
                    string exp = m.Groups[3].Value.Trim();
                    object ret = PythonHelper.ExecutePythonExpression(exp, null);
                    s = ret == null ? string.Empty : ret.ToString();
                    break;

                default:
                    throw new NotSupportedException("Invalid text of " + text);
                }
                text = text.Replace(m.Groups[0].Value, s);
            }
            return(text);
        }
        // http://localhost:8080/查询统计_人员单位/?exp=编号  = 100000
        // http://localhost:8080/查询统计_人员单位/count?exp=编号  = 100000
        // http://localhost:8080/查询统计_人员单位/?format=json&exp= 编号  = 100000
        // http://localhost:8080/查询统计_人员单位/count?format=json&exp= 编号  = 100000
        internal static int InternalGetItemCount(string winTabName, NameValueCollection nvc)
        {
            if (!Utils.AuthHelper.CheckAuthentication())
            {
                return(0);
            }

            ISearchManager sm = Feng.Server.Utils.ServiceHelper.GetSearchManagerFromWindowTab(winTabName);

            if (sm == null)
            {
                return(0);
            }

            ISearchExpression exp = null;

            if (!string.IsNullOrEmpty(nvc["exp"]))
            {
                exp = SearchExpression.Parse(System.Web.HttpUtility.UrlDecode(nvc["exp"]));
            }
            return(sm.GetCount(exp));
        }
        public override SoaDataGridSelectResponse Select(SoaDataGridSelectRequest request)
        {
            SoaDataGridSelectResponse response = new SoaDataGridSelectResponse();

            if (request.Tag == null || string.IsNullOrEmpty(request.Tag.ToString()))
            {
                return(response);
            }

            try
            {
                //WindowInfo windowInfo = ADInfoBll.Instance.GetWindowInfo(request.Tag.ToString());
                //IList<WindowTabInfo> tabInfos = null;
                //if (windowInfo != null)
                //{
                //    tabInfos = ADInfoBll.Instance.GetWindowTabInfo(windowInfo.Id);
                //}

                Dictionary <string, string> dict = StringToDictionary(request.Tag.ToString());

                if (!dict.ContainsKey("winTab") || string.IsNullOrEmpty(dict["winTab"]))
                {
                    return(response);
                }

                WindowTabInfo tabInfo = ADInfoBll.Instance.GetWindowTabInfo(dict["winTab"]);

                if (tabInfo != null)
                {
                    ISearchManager sm = ServiceProvider.GetService <IManagerFactory>().GenerateSearchManager(tabInfo, null);
                    ManagerFactory.CreateSearchManagerEagerFetchs(sm, tabInfo.GridName);

                    ISearchExpression exp = null;
                    if (dict.ContainsKey("se") && !string.IsNullOrEmpty(dict["se"]))
                    {
                        //exp = HttpUtility.UrlDecode(exp, System.Text.Encoding.GetEncoding("gb2312"));
                        //exp = HttpContext.Current.Server.UrlDecode(exp);
                        exp = SearchExpression.Parse(dict["se"]);
                    }

                    //if (request.Filters != null)
                    //{
                    //    //searchs.Add(SearchExpression.Parse(request.Tag.ToString()));
                    //    foreach (SoaDataGridDataCondition i in request.Filters)
                    //    {
                    //        switch (i.Operand)
                    //        {
                    //            case SoaDataGridDataConditionOperand.Contains:
                    //                searchExps.Add(SearchExpression.Like(i.DataFieldName, i.DataFieldValue));
                    //                break;
                    //            case SoaDataGridDataConditionOperand.Equals:
                    //                searchExps.Add(SearchExpression.Eq(i.DataFieldName, i.DataFieldValue));
                    //                break;
                    //            case SoaDataGridDataConditionOperand.GreaterThan:
                    //                searchExps.Add(SearchExpression.Gt(i.DataFieldName, i.DataFieldValue));
                    //                break;
                    //            case SoaDataGridDataConditionOperand.GreaterThanOrEqual:
                    //                searchExps.Add(SearchExpression.Ge(i.DataFieldName, i.DataFieldValue));
                    //                break;
                    //            case SoaDataGridDataConditionOperand.In:
                    //                searchExps.Add(SearchExpression.InG(i.DataFieldName, i.DataFieldValue));
                    //                break;
                    //            case SoaDataGridDataConditionOperand.LessThan:
                    //                searchExps.Add(SearchExpression.Lt(i.DataFieldName, i.DataFieldValue));
                    //                break;
                    //            case SoaDataGridDataConditionOperand.LessThanOrEqual:
                    //                searchExps.Add(SearchExpression.Le(i.DataFieldName, i.DataFieldValue));
                    //                break;
                    //            case SoaDataGridDataConditionOperand.NotEqualTo:
                    //                searchExps.Add(SearchExpression.NotEq(i.DataFieldName, i.DataFieldValue));
                    //                break;
                    //            case SoaDataGridDataConditionOperand.NotIn:
                    //                searchExps.Add(SearchExpression.NotInG(i.DataFieldName, i.DataFieldValue));
                    //                break;
                    //            case SoaDataGridDataConditionOperand.StartsWith:
                    //                searchExps.Add(SearchExpression.Like(i.DataFieldName, i.DataFieldValue));
                    //                break;
                    //        }
                    //    }
                    //}

                    IList <ISearchOrder> searchOrders = new List <ISearchOrder>();
                    if (request.Sortings != null)
                    {
                        foreach (SoaDataGridSorting i in request.Sortings)
                        {
                            searchOrders.Add(i.Direction == SoaSortDirection.Ascending ? SearchOrder.Asc(i.Column.Name) : SearchOrder.Desc(i.Column.Name));
                        }
                    }

                    sm.FirstResult = request.Offset;
                    sm.MaxResult   = request.Count;

                    List <List <object> > arMessages;

                    arMessages = GenerateData(sm.GetData(exp, searchOrders), tabInfo.GridName, request.Columns);

                    //IList<Dictionary<string, object>> values = null;
                    //

                    //using (DataProcess dp = new DataProcess())
                    //{
                    //    if (dt == null)
                    //    {
                    //        // should be IEnumerable because IList<T> not support IList
                    //        IEnumerable data = ret as IEnumerable;
                    //        values = dp.Process(data, tabInfo.GridName);
                    //    }
                    //    else
                    //    {
                    //        values = dp.Process(dt.Rows, tabInfo.GridName);
                    //    }
                    //}

                    //foreach (Dictionary<string, object> obj in values)
                    //{
                    //    List<object> msg = new List<object>();

                    //    foreach (SoaDataGridColumn oColumn in request.Columns)
                    //    {
                    //        if (!obj.ContainsKey(oColumn.Name))
                    //        {
                    //            msg.Add(null);
                    //        }
                    //        else
                    //        {
                    //            msg.Add(obj[oColumn.Name]);
                    //        }
                    //    }

                    //    arMessages.Add(msg);
                    //}
                    response.Data = arMessages;

                    if (sm.EnablePage)
                    {
                        response.ItemCount = sm.GetCount(exp);
                    }
                    else
                    {
                        response.ItemCount = arMessages.Count;
                    }
                }
                else
                {
                    throw new ArgumentException("Invalide tabName of " + dict["winTab"]);
                }
            }
            catch (Exception)
            {
#if DEBUG
                throw;
#endif
            }

            return(response);
        }