Example #1
0
        private static string GetGridXmlString(List <SysDict> sysDicts)
        {
            DhtmlxGrid grid = new DhtmlxGrid();

            foreach (var item in sysDicts.Where(p => p.CategoryId < 0))
            {
                DhtmlxGridRow row = new DhtmlxGridRow(item.Id);
                row.AddCell(item.Name);
                row.AddCell(item.KeyValue);
                row.AddCell("");
                row.AddCell(item.Status);
                row.AddCell(new DhtmlxGridCell("编辑", false).AddCellAttribute("title", "编辑"));
                row.AddCell(new DhtmlxGridCell("删除", false).AddCellAttribute("title", "删除"));

                foreach (var subItem in sysDicts.Where(p => p.CategoryId == item.Id))
                {
                    DhtmlxGridRow subRow = new DhtmlxGridRow(subItem.Id.ToString());
                    subRow.AddCell(subItem.Name);
                    subRow.AddCell(subItem.KeyValue);
                    subRow.AddCell(subItem.OrderNo);
                    subRow.AddCell(subItem.Status);
                    subRow.AddCell(new DhtmlxGridCell("编辑", false).AddCellAttribute("title", "编辑"));
                    subRow.AddCell(new DhtmlxGridCell("删除", false).AddCellAttribute("title", "删除"));

                    row.AddRow(subRow);
                }

                grid.AddGridRow(row);
            }

            return(grid.BuildRowXml().ToString(System.Xml.Linq.SaveOptions.DisableFormatting));
        }
        private static string GetGridXmlString(List <Path> paths, List <Pkpm.Entity.Action> actions)
        {
            DhtmlxGrid grid = new DhtmlxGrid();

            foreach (var item in paths.OrderBy(p => p.OrderNo))
            {
                DhtmlxGridRow row = new DhtmlxGridRow(item.Id.ToString());
                row.AddCell(item.Name);
                row.AddCell(item.Url);
                row.AddCell(item.OrderNo.ToString());
                row.AddCell(item.Status.ToString());
                row.AddLinkJsCell("按钮", "actionInPath({0})".Fmt(item.Id.ToString()));
                row.AddCell(new DhtmlxGridCell("编辑", false).AddCellAttribute("title", "编辑"));
                row.AddCell(new DhtmlxGridCell("删除", false).AddCellAttribute("title", "删除"));

                var pathActions = actions.Where(a => a.PathId == item.Id).ToList();

                foreach (var pathAction in pathActions)
                {
                    DhtmlxGridRow actionRow = new DhtmlxGridRow(string.Format("Action,{0}", pathAction.Id));
                    actionRow.AddCell(pathAction.Name);
                    actionRow.AddCell(pathAction.Url);
                    actionRow.AddCell(string.Empty);
                    actionRow.AddCell(pathAction.Status.ToString());
                    actionRow.AddCell(string.Empty);
                    actionRow.AddCell(new DhtmlxGridCell("编辑", false).AddCellAttribute("title", "编辑"));
                    actionRow.AddCell(new DhtmlxGridCell("删除", false).AddCellAttribute("title", "删除"));

                    row.AddRow(actionRow);
                }

                grid.AddGridRow(row);
            }

            return(grid.BuildRowXml().ToString(System.Xml.Linq.SaveOptions.DisableFormatting));
        }
        /// <summary>
        /// 根据机构分组统计之后,塞到对应的地区中
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult Search(SysSearchModel model)
        {
            model.GroupType = "Custom";
            var        response = GetStatisData(model);
            DhtmlxGrid grid     = new DhtmlxGrid();

            /*
             * 1.查出所有报告数量以及分组统计不合格报告数量
             * 2.countByArea 存储该地区报告总数
             * 3.需要一个存储该地区所有不合格报告数量
             * 4.存储改地区所有有不合格报告数量的厂家    厂家总数
             *
             */
            if (response.IsValid)
            {
                var bucks = response.Aggs.Terms("Custom").Buckets;
                Dictionary <string, int> countByArea, unQualifyCount, countUnitByArea, unQualifyUnitCountByArea;
                GetSearchResult(bucks, out countByArea, out unQualifyCount, out countUnitByArea, out unQualifyUnitCountByArea);
                var allAreas = AreaService.GetAllArea();

                /*
                 * 1.从所有的地区中选择名字相对应的地区,判断是否为市级节点,是直接加入,不是的话需要判断本节点所属的市级节点是否存在,如果存在直接加上,不存在则增加一条数值为0的记录
                 */
                var index      = 1;
                var rootAreas  = new List <AreaResultModel>();
                var childAreas = new List <AreaResultModel>();
                foreach (var item in countByArea)
                {
                    if (item.Key.IsNullOrEmpty())
                    {
                        continue;
                    }


                    var unQualifyCountRow    = 0;
                    var unitCountByArea      = 0;
                    var unqualifyUnitCount   = 0;
                    var isUnqualify          = unQualifyCount.TryGetValue(item.Key, out unQualifyCountRow); //isUnqualify 标识是否有不合格报告
                    var isUnitCount          = countUnitByArea.TryGetValue(item.Key, out unitCountByArea);
                    var isUnqualifyUnitCount = unQualifyUnitCountByArea.TryGetValue(item.Key, out unqualifyUnitCount);
                    List <t_bp_area> areas   = new List <t_bp_area>();

                    var areass = allAreas.Where(t => t.AREANAME == item.Key);


                    if (areass != null)
                    {
                        areas = areass.ToList();
                    }

                    if (areas != null && areas.Count > 0)
                    {
                        var area = areas.First();
                        logger.Debug("areasfirst");
                        AreaResultModel areaResult = new AreaResultModel()
                        {
                            AreaCode              = area.AREACODE,
                            ParentCode            = area.PAREACODE,
                            Name                  = area.AREANAME,
                            TotalCount            = (int)item.Value,
                            UnqualifuCount        = unQualifyCountRow,
                            FactoryCount          = unitCountByArea,
                            UnqualifyFactoryCount = unqualifyUnitCount
                        };

                        if (area.PAREACODE == "45")//市
                        {
                            GetRootAreaResult(rootAreas, area, areaResult, areaResult);
                        }
                        else //市辖区,县等
                        {
                            childAreas.Add(areaResult);
                            var parentCode = area.PAREACODE;
                            if (parentCode != null)
                            {
                                List <t_bp_area> parentAreas = new List <t_bp_area>();
                                var parentAreass             = allAreas.Where(t => t.AREACODE == parentCode);
                                if (parentAreass != null)
                                {
                                    parentAreas = parentAreass.ToList();
                                }
                                if (parentAreas != null && parentAreas.Count > 0)
                                {
                                    var             parentArea       = parentAreas.First(); //获得所属市地区信息
                                    AreaResultModel parentareaResult = new AreaResultModel()
                                    {
                                        AreaCode              = parentArea.AREACODE,
                                        Name                  = parentArea.AREANAME,
                                        TotalCount            = 0,
                                        UnqualifuCount        = 0,
                                        FactoryCount          = 0,
                                        UnqualifyFactoryCount = 0
                                    };
                                    GetRootAreaResult(rootAreas, parentArea, areaResult, parentareaResult);
                                }
                            }
                        }
                    }
                }
                foreach (var item in rootAreas)
                {
                    DhtmlxGridRow row = new DhtmlxGridRow(item.AreaCode);
                    row.AddCell(index++);
                    row.AddCell(item.Name);
                    row.AddCell(item.TotalCount);
                    row.AddCell(item.UnqualifuCount);
                    row.AddCell(item.TotalCount == 0 ? "0" : Math.Round(((item.UnqualifuCount * 1.00 / item.TotalCount) * 100), 2).ToString() + "%");
                    row.AddCell(item.FactoryCount);
                    row.AddCell(item.UnqualifyFactoryCount);
                    row.AddCell(item.FactoryCount == 0 ? "0" : Math.Round(((item.UnqualifyFactoryCount * 1.00 / item.FactoryCount) * 100), 2).ToString() + "%");
                    row.AddCell(string.Empty); //同比
                    row.AddCell(string.Empty); //环比

                    if (item.TotalCount > 0)
                    {
                        row.AddLinkJsCell("详情查看", "showItemKeyGrid(\"{0}\")".Fmt(item.Name));
                    }

                    List <AreaResultModel> thisChildAreas = new List <AreaResultModel>();

                    var thisChildAreass = childAreas.Where(t => t.ParentCode == item.AreaCode);
                    if (thisChildAreass != null)
                    {
                        thisChildAreas = thisChildAreass.ToList();
                    }
                    if (thisChildAreas != null && thisChildAreas.Count > 0)
                    {
                        var childIndex = 1;
                        foreach (var childItem in thisChildAreas)
                        {
                            DhtmlxGridRow childRow = new DhtmlxGridRow(childItem.AreaCode);
                            childRow.AddCell(childIndex++);
                            childRow.AddCell(childItem.Name);
                            childRow.AddCell(childItem.TotalCount);
                            childRow.AddCell(childItem.UnqualifuCount);
                            childRow.AddCell(childItem.TotalCount == 0 ? "0" : Math.Round(((childItem.UnqualifuCount * 1.00 / childItem.TotalCount) * 100), 2).ToString() + "%");
                            childRow.AddCell(childItem.FactoryCount);
                            childRow.AddCell(childItem.UnqualifyFactoryCount);
                            childRow.AddCell(childItem.FactoryCount == 0 ? "0" : Math.Round(((childItem.UnqualifyFactoryCount * 1.00 / childItem.FactoryCount) * 100), 2).ToString() + "%");
                            childRow.AddCell(string.Empty);   //同比
                            childRow.AddCell(string.Empty);   //环比
                            if (childItem.UnqualifuCount > 0) //有不合格报告才显示详情查看
                            {
                                //TODO 由于改了实现方式,将市辖区,县的信息塞到了市中,在不合格详情查看时需要增加如果是市,则需要查本市所有的不合格数据
                                childRow.AddLinkJsCell("详情查看", "showItemKeyGrid(\"{0}\")".Fmt(childItem.Name));
                            }
                            row.AddRow(childRow);
                        }
                    }
                    grid.AddGridRow(row);
                }
                //foreach (var item in countByArea)
                //{
                //    var unQualifyCountRow = 0;
                //    var unitCountByArea = 0;
                //    var unqualifyUnitCount = 0;
                //    var isUnqualify = unQualifyCount.TryGetValue(item.Key, out unQualifyCountRow); //isUnqualify 标识是否有不合格报告
                //    var isUnitCount = countUnitByArea.TryGetValue(item.Key, out unitCountByArea);
                //    var isUnqualifyUnitCount = unQualifyUnitCountByArea.TryGetValue(item.Key, out unqualifyUnitCount);

                //    DhtmlxGridRow row = new DhtmlxGridRow(item.Key);
                //    row.AddCell(index++);
                //    row.AddCell(item.Key);
                //    row.AddCell(item.Value);
                //    row.AddCell(isUnqualify ? unQualifyCountRow : 0);
                //    row.AddCell(item.Value == 0 ? "0" : Math.Round(((unQualifyCountRow * 1.00 / item.Value) * 100), 2).ToString() + "%");
                //    row.AddCell(unitCountByArea.ToString());
                //    row.AddCell(unqualifyUnitCount.ToString());
                //    row.AddCell(unitCountByArea == 0 ? "0" : Math.Round(((unqualifyUnitCount * 1.00 / unitCountByArea) * 100), 2).ToString() + "%");
                //    row.AddCell(string.Empty);//同比
                //    row.AddCell(string.Empty);//环比
                //    if (isUnqualify)//有不合格报告才显示详情查看
                //    {
                //        row.AddLinkJsCell("详情查看", "showItemKeyGrid(\"{0}\")".Fmt(item.Key));
                //    }
                //    grid.AddGridRow(row);
                //}
            }

            string str = grid.BuildRowXml().ToString(System.Xml.Linq.SaveOptions.DisableFormatting);

            return(Content(str, "text/xml"));
        }