Exemple #1
0
        /// <summary>
        /// 设置显示控制器
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="dm"></param>
        /// <param name="gridName"></param>
        public static void SetDisplayManager(this IBoundGrid grid, IDisplayManager dm, string gridName)
        {
            if (dm == null)
            {
                throw new ArgumentNullException("dm");
            }
            grid.DisplayManager = dm;
            grid.GridName       = gridName;
            grid.SetState(StateType.View);

            grid.DisplayManager.BindingControls.Add(grid);
            grid.CreateGrid();
            ManagerFactory.CreateSearchManagerEagerFetchs(dm.SearchManager, gridName);

            grid.AfterLoadData();
        }
        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);
        }