示例#1
0
        public Dictionary <string, object> fetchCountList(int limit)
        {
            Dictionary <string, object> r = new Dictionary <string, object>();

            try
            {
                //DataTable dtComponentMonth = new DataTable();
                //DataTable dtServerMonth = new DataTable();
                DataTable dtComponentTop   = new DataTable();
                DataTable dtServerCountTop = new DataTable();

                DataTable dtCom    = db.getCountByMonth("1"); //组件
                DataTable dtServer = db.getCountByMonth("2"); //服务
                DataSet   ds       = db.getCountTop();
                DataTable dtcomT   = new DataTable();
                DataTable dtserT   = new DataTable();
                if (ds != null && ds.Tables.Count > 0)
                {
                    dtcomT = ds.Tables["comp"];
                    dtserT = ds.Tables["server"];
                    if (dtcomT != null && dtcomT.Rows.Count > 0)
                    {
                        dtComponentTop = dtcomT.Clone();
                    }
                    if (dtserT != null && dtserT.Rows.Count > 0)
                    {
                        dtServerCountTop = dtserT.Clone();
                    }
                    if (limit == 10)
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            if (dtcomT != null && dtcomT.Rows.Count > i)
                            {
                                dtComponentTop.ImportRow(dtcomT.Rows[i]);
                            }
                            if (dtserT != null && dtserT.Rows.Count > i)
                            {
                                dtServerCountTop.ImportRow(dtserT.Rows[i]);
                            }
                        }
                        r["dtComponentTop"]   = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(dtComponentTop));
                        r["dtServerCountTop"] = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(dtServerCountTop));
                        r["code"]             = 2000;
                        r["message"]          = "查询成功";
                        return(r);
                    }
                    else
                    {
                        r["dtComponentTop"]   = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(dtcomT));
                        r["dtServerCountTop"] = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(dtserT));
                        r["code"]             = 2000;
                        r["message"]          = "查询成功";
                        return(r);
                    }
                }
                //if (dtCom != null && dtCom.Rows.Count > 0)
                //{
                //    dtComponentMonth = dtCom.Clone();
                //}
                //if (dtServer != null && dtServer.Rows.Count > 0)
                //{
                //    dtServerMonth = dtServer.Clone();
                //}
                //for (int i = 0; i < 6; i++)
                //{
                //    if (dtCom != null && dtCom.Rows.Count > i)
                //    {
                //        dtComponentMonth.ImportRow(dtCom.Rows[i]);
                //    }
                //    if (dtServer != null && dtServer.Rows.Count > i)
                //    {
                //        dtServerMonth.ImportRow(dtServer.Rows[i]);
                //    }
                //}
                //r["dtComponentMonth"] = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(dtComponentMonth));
                //r["dtServerMonth"] = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(dtServerMonth));
            }
            catch (Exception e)
            {
                r["dtComponentTop"]   = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(new object()));
                r["dtServerCountTop"] = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(new object()));
                r["code"]             = -1;
                r["message"]          = e.Message;
            }

            return(r);
        }