//handles the toggling of favorite goals //called when the favorite icon is clicked by the user public void toggleFavorite(object sender, CommandEventArgs e) { DataAbstract DA = new DataAbstract(); DataRow DR = DA.returnOneGoal(Convert.ToInt32(e.CommandArgument)).Tables[0].Rows[0]; bool pastFavor = Convert.ToBoolean(DR.Field <object>("Favorite")); DA.updateGoalFavorite(Convert.ToInt32(e.CommandArgument), !pastFavor); }
//handles the presentation of correct favorite/nonfavorite icons //changes the src of image to be correct based on database public void imageChoose(object sender, EventArgs e) { Image x = (Image)sender; int id = Convert.ToInt32(x.Attributes["Text"]); DataAbstract DA = new DataAbstract(); DataRow DR = DA.returnOneGoal(id).Tables[0].Rows[0]; bool fav = Convert.ToBoolean(DR.Field <object>("favorite")); if (fav) { x.Attributes["src"] = "images/faveTrue.png"; } else { x.Attributes["src"] = "images/faveFalse.png"; } sender = x; }
//called by button clicked by user //uses bound data along with abstract layer calls to update database public void addFundsClick(object sender, CommandEventArgs e) { int id = Convert.ToInt32(e.CommandArgument); System.Diagnostics.Debug.WriteLine(id); DataAbstract DA = new DataAbstract(); DataRow DR = DA.returnOneGoal(id).Tables[0].Rows[0]; double prev = Convert.ToDouble(DR.Field <object>("CurrentAmt")); Button addBtn = sender as Button; //finding listview item, finding textbox value ListViewItem lvi = addBtn.NamingContainer as ListViewItem; //gets listViewItem containing the clicked button TextBox tb = lvi.FindControl("AddAmt") as TextBox; string tbs = tb.Text; if (tbs != "") { double toAdd = Convert.ToDouble(tbs); double newAmount = prev + toAdd; DA.updateGoalCurrentAmount(id, newAmount, Convert.ToInt64(Session["account"])); Response.Redirect("~/Goals.aspx"); } }