protected void GetTodoList() { // populate the form with existing data from db int TodoID = Convert.ToInt32(Request.QueryString["TodoId"]); // connect to the EF DB using (TodoContext db = new TodoContext()) { // Query student matching the selected one ToDoTable updatedTask = (from tasks in db.ToDoTables where tasks.TodoId == TodoID select tasks).FirstOrDefault(); // Assign the student data to the form if (updatedTask != null) { TodoDescriptionTextBox.Text = updatedTask.TodoDescription; TodoNotesTextBox.Text = updatedTask.TodoNotes; if (updatedTask.Completed == true) { TodoCheckBox.Checked = true; } else { TodoCheckBox.Checked = false; } } } }
protected void SearchButton_Click(object sender, EventArgs e) { SqlConnect sql = new SqlConnect(); String sorgu = "Select * From ToDoList Where " + "SubjectTitle Like '%" + SearchTextBox.Text + "%' and UserID='" + Session["UID"].ToString() + "'" + "or SubjectText Like '%" + SearchTextBox.Text + "%' and UserID='" + Session["UID"].ToString() + "'" + "or Status Like '%" + SearchTextBox.Text + "%' and UserID='" + Session["UID"].ToString() + "'" + " ORDER BY Status DESC, Date ASC"; using (SqlCommand komut = new SqlCommand(sorgu, sql.connection())) { SqlDataAdapter adapter = new SqlDataAdapter(komut); DataSet ds = new DataSet(); adapter.Fill(ds); ToDoTable.DataSource = ds; if (ds.Tables[0].Rows.Count > 0) { ToDoTable.DataBind(); nullRow.Visible = false; } else { ToDoTable.DataBind(); nullRow.Visible = true; } } sql.disconnection(); }
protected void TodoGridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { // Archive the row selected from the page int selectedRow = e.RowIndex; // Use the Grid View to archive the task ID int TodoID = Convert.ToInt32(TodoGridView.DataKeys[selectedRow].Values["TodoId"]); using (TodoContext db = new TodoContext()) { // Query the tasks matching the selected one by id ToDoTable deletedTask = (from alltasks in db.ToDoTables where alltasks.TodoId == TodoID select alltasks).FirstOrDefault(); // Remove the task from the database db.ToDoTables.Remove(deletedTask); // Commit Changes to the db db.SaveChanges(); // Clean up the grid view to show current records this.GetTodoList(); } }
protected void SaveButton_Click(object sender, EventArgs e) { // Use EF to conect to the server using (TodoContext db = new TodoContext()) { // Use the variable model for a task to save to dv ToDoTable newTask = new ToDoTable(); int TodoID = 0; if (Request.QueryString.Count > 0) { // get the id from the URL TodoID = Convert.ToInt32(Request.QueryString["TodoId"]); // get the current task from EF db newTask = (from tasks in db.ToDoTables where tasks.TodoId == TodoID select tasks).FirstOrDefault(); } // Add the textbox data to the variable newTask.TodoDescription = TodoDescriptionTextBox.Text; newTask.TodoNotes = TodoNotesTextBox.Text; if (TodoCheckBox.Checked == true) { newTask.Completed = true; } else { newTask.Completed = false; } // use LINQ to ADO.NET to add/update the task in the database. if (TodoID == 0) { db.ToDoTables.Add(newTask); } // save our changes - also updates and inserts db.SaveChanges(); // Redirect back to the updated students page Response.Redirect("~/TodoList.aspx"); } }
private void GetData() { SqlConnect sql = new SqlConnect(); String sorgu = "Select * From ToDoList Where UserID='" + Session["UID"].ToString() + "' ORDER BY Status DESC, Date ASC"; using (SqlCommand komut = new SqlCommand(sorgu, sql.connection())) { SqlDataAdapter adapter = new SqlDataAdapter(komut); DataSet ds = new DataSet(); adapter.Fill(ds); ToDoTable.DataSource = ds; if (ds.Tables[0].Rows.Count > 0) { ToDoTable.DataBind(); NullTable.Visible = false; } else { ToDoTable.DataBind(); NullTable.Visible = true; } } sql.disconnection(); }