Beispiel #1
0
        private void LoadDataToGrid(bool useDefeultColumns)
        {
            using (PostgresEntities dbContext = new PostgresEntities())
            {
                List <int> columnsIds = useDefeultColumns ? defaultVisibleColumns.ToList() : LeftMenu.GetColumnsIds();
                if (columnsIds.Count == 0)
                {
                    return;
                }

                // select
                string sql = "SELECT ";
                foreach (int columnId in columnsIds)
                {
                    if (columnId == 0 || columnId == 1)
                    {
                        sql += "CAST(" + columnsNames[columnId].ToString() + " AS bigint), ";
                    }
                    else
                    {
                        sql += (columnsNames[columnId] + ", ");
                    }
                }
                sql  = sql.Substring(0, sql.Length - 2);
                sql += " FROM pg_stat_statements";

                // where
                long dbId = LeftMenu.GetDbIdFilter();
                if (LeftMenu.GetDbIdFilter() != -1)
                {
                    sql += " WHERE dbid=" + dbId;
                }

                // order by
                if (GridSortDirection != null && GridSortExpression != null)
                {
                    sql += " ORDER BY " + GridSortExpression + " " + GridSortDirection;
                }

                // execute
                var         query = dbContext.Database.SqlQuery <Stat>(sql);
                List <Stat> items = query.Skip(MainGridView.PageSize * PageNum).Take(MainGridView.PageSize).ToList();
                MainGridView.VirtualItemCount = query.Count();
                MainGridView.DataSource       = items;
                MainGridView.DataBind();

                // chart
                ChartLabelsHiddenField.Value = ChartDataHiddenField.Value = string.Empty;
                foreach (Stat item in items)
                {
                    ChartLabelsHiddenField.Value += item.queryid + ",";
                    ChartDataHiddenField.Value   += item.calls + ",";
                }
                ChartLabelsHiddenField.Value.Substring(0, ChartLabelsHiddenField.Value.Length - 1);
                ChartDataHiddenField.Value.Substring(0, ChartDataHiddenField.Value.Length - 1);
            }
        }
        private void LoadItemsToDropDownLists()
        {
            using (PostgresEntities dbContext = new PostgresEntities())
            {
                DbIdsDropDownList.Items.Add(new ListItem("ALL"));

                List <long> dbIds = dbContext.Database.SqlQuery <long>("SELECT DISTINCT CAST(dbid AS bigint) FROM pg_stat_statements").ToList();
                foreach (long id in dbIds)
                {
                    DbIdsDropDownList.Items.Add(new ListItem(id.ToString()));
                }
            }
        }