protected void Page_Load(object sender, EventArgs e)
        {
            int query = 2;

            string queryStr1 = Request.Params["ItemID"];
            string ItemID    = queryStr1;

            if (queryStr1 != null)
            {
                query = Int32.Parse(queryStr1);
            }
            if (ItemID != null)
            {
                itemid = Int32.Parse(ItemID);
            }

            // Save state for use in post back
            ViewState["query"] = query;

            if (IsPostBack)
            {
                query = (int)ViewState["query"];
            }
            else
            {
            }
            asub.HRef = "SubItem.aspx?id=" + itemid;
            string connStr = ConfigurationSettings.AppSettings["ConnectionString"];
            string sql;
            string qryTitle;

            ButtonColumn bcDone;
            ButtonColumn bcEdit;
            ButtonColumn bcDelete;
            ButtonColumn bcReopen;
            BoundColumn  bcOpened;
            BoundColumn  bcClosed;

            switch (query)
            {
            case 0:
                qryTitle = "All Items";
                sql      = "select * from ChildItems where ItemID = " + itemid + "  order by priority desc";

                bcOpened            = new BoundColumn();
                bcOpened.HeaderText = "Opened";
                bcOpened.DataField  = "Opened";
                ToDoDataGrid.Columns.Add(bcOpened);
                break;

            case 1:
                qryTitle = "All Closed Items";
                sql      = "SELECT * FROM ChildItems where ItemID = " + itemid + " AND Closed Is Not Null order by priority desc";

                bcClosed            = new BoundColumn();
                bcClosed.HeaderText = "Closed";
                bcClosed.DataField  = "Closed";
                ToDoDataGrid.Columns.Add(bcClosed);

                bcReopen             = new ButtonColumn();
                bcReopen.Text        = "Reopen";
                bcReopen.CommandName = "ReopenToDo";
                ToDoDataGrid.Columns.Add(bcReopen);

                bcDelete             = new ButtonColumn();
                bcDelete.Text        = "Delete";
                bcDelete.CommandName = "DeleteToDo";
                ToDoDataGrid.Columns.Add(bcDelete);
                break;

            default:
            case 2:
                qryTitle = "All Open Items";
                sql      = "SELECT * FROM ChildItems WHERE ItemID = " + itemid + " AND  Closed Is Null order by priority desc";

                bcDone             = new ButtonColumn();
                bcDone.Text        = "Done";
                bcDone.CommandName = "DoneToDo";
                ToDoDataGrid.Columns.Add(bcDone);

                bcEdit             = new ButtonColumn();
                bcEdit.Text        = "Edit";
                bcEdit.CommandName = "EditToDo";
                ToDoDataGrid.Columns.Add(bcEdit);

                bcDelete             = new ButtonColumn();
                bcDelete.Text        = "Delete";
                bcDelete.CommandName = "DeleteToDo";
                ToDoDataGrid.Columns.Add(bcDelete);
                break;
            }

            _title = "To Do List - " + qryTitle;

            SqlConnection dbconn = new SqlConnection(connStr);


            dbconn.Open();
            //SqlCommand cmd = new SqlCommand(Sql, dbconn);
            SqlDataAdapter adapter = new SqlDataAdapter(sql, connStr);

            DataSet ds = new DataSet();

            adapter.Fill(ds);
            ToDoDataGrid.DataSource = ds;
            ToDoDataGrid.DataBind();
            if (itemid != null)
            {
                string         queryStr = "select * from Items where id=" + itemid;
                SqlDataAdapter adapter1 = new SqlDataAdapter(queryStr, connStr);

                DataSet ds1 = new DataSet();

                adapter1.Fill(ds1);

                DataTable tbl = ds1.Tables[0];

                if (tbl.Rows.Count > 0)
                {
                    DataRow row = tbl.Rows[0];

                    lblDescription.Text = row["Description"].ToString();
                }
            }
        }
示例#2
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            int query = 2;

            if (IsPostBack)
            {
                query = (int)ViewState["query"];
            }
            else
            {
                string queryStr = Request.Params["query"];

                if (queryStr != null)
                {
                    query = Int32.Parse(queryStr);
                }

                // Save state for use in post back
                ViewState["query"] = query;
            }

            string connStr = ConfigurationSettings.AppSettings["ConnectionString"];
            string sql;
            string qryTitle;

            ButtonColumn bcDone;
            ButtonColumn bcEdit;
            ButtonColumn bcDelete;
            ButtonColumn bcReopen;
            BoundColumn  bcOpened;
            BoundColumn  bcClosed;

            switch (query)
            {
            case 0:
                qryTitle = "All Items";
                sql      = "select ID, Description, Opened, Closed, Priority,FORMAT(EndDate,'dd/MM/yyyy') as EndDate from items order by priority desc";

                bcOpened            = new BoundColumn();
                bcOpened.HeaderText = "Opened";
                bcOpened.DataField  = "Opened";
                ToDoDataGrid.Columns.Add(bcOpened);
                break;

            case 1:
                qryTitle = "All Closed Items";
                sql      = "select ID, Description, Opened, Closed, Priority,FORMAT(EndDate,'dd/MM/yyyy') as EndDate from items WHERE Closed Is Not Null order by priority desc";

                bcClosed            = new BoundColumn();
                bcClosed.HeaderText = "Closed";
                bcClosed.DataField  = "Closed";
                ToDoDataGrid.Columns.Add(bcClosed);

                bcReopen             = new ButtonColumn();
                bcReopen.Text        = "Reopen";
                bcReopen.CommandName = "ReopenToDo";
                ToDoDataGrid.Columns.Add(bcReopen);

                bcDelete             = new ButtonColumn();
                bcDelete.Text        = "Delete";
                bcDelete.CommandName = "DeleteToDo";
                ToDoDataGrid.Columns.Add(bcDelete);
                break;

            default:
            case 2:
                qryTitle = "All Open Items";
                sql      = "select ID, Description, Opened, Closed, Priority,FORMAT(EndDate,'dd/MM/yyyy') as EndDate from items WHERE Closed Is Null order by priority desc";

                bcDone             = new ButtonColumn();
                bcDone.Text        = "Done";
                bcDone.CommandName = "DoneToDo";
                ToDoDataGrid.Columns.Add(bcDone);

                bcEdit             = new ButtonColumn();
                bcEdit.Text        = "Edit";
                bcEdit.CommandName = "EditToDo";
                ToDoDataGrid.Columns.Add(bcEdit);

                bcDelete             = new ButtonColumn();
                bcDelete.Text        = "Delete";
                bcDelete.CommandName = "DeleteToDo";
                ToDoDataGrid.Columns.Add(bcDelete);
                break;
            }

            _title = "To Do List - " + qryTitle;

            SqlConnection dbconn = new SqlConnection(connStr);


            dbconn.Open();
            //SqlCommand cmd = new SqlCommand(Sql, dbconn);
            SqlDataAdapter adapter = new SqlDataAdapter(sql, connStr);

            DataSet ds = new DataSet();

            adapter.Fill(ds);
            ToDoDataGrid.DataSource = ds;
            ToDoDataGrid.DataBind();
        }