using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using digioz;

public partial class controls_admin_DataBaseUtil : System.Web.UI.UserControl
{
    public DataTable dt
    {
        set { ViewState["dt"] = value; }
        get { return (DataTable)ViewState["dt"]; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        lbl_message.Text = "";
    }

    protected void menu1_MenuItemClick(object sender, MenuEventArgs e)
    {
        mv1.ActiveViewIndex = Int32.Parse(e.Item.Value);
    }

    protected void btnExecute_Click(object sender, EventArgs e)
    {
        dt = DatabaseUtilManagement.GetObject(txtCommand.Text);
        if (dt.Rows.Count > 0)
        {
            PopulateGrid();
        }
        else
        {
            lbl_message.ForeColor = System.Drawing.Color.Red;
            lbl_message.Text = "There is no data to display. ";
            lbl_message.Font.Bold = true;
        }
    }

    private void PopulateGrid()
    {
        gr_data.Columns.Clear();
        try
        {
            foreach (DataColumn col in dt.Columns)
            {
                BoundField bfield = new BoundField();
                bfield.DataField = col.ColumnName;
                bfield.HeaderText = col.ColumnName;
                gr_data.Columns.Add(bfield);
                gr_data.DataSource = dt;
                gr_data.DataBind();
            }
        }
        catch
        {
            lbl_message.ForeColor = System.Drawing.Color.Red;
            lbl_message.Text = "There is no data to display. ";
            lbl_message.Font.Bold = true;
        }
    }

    protected void gr_data_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.gr_data.PageIndex = e.NewPageIndex;
        PopulateGrid();
        this.gr_data.DataBind();
    }
}
