示例#1
0
        protected void newGoal(object sender, EventArgs e)
        {
            FRT.DAL.frtEntities entities = new FRT.DAL.frtEntities();

            TextBox newGoal    = (TextBox)rptTrainingGoals.Controls[rptTrainingGoals.Controls.Count - 1].Controls[0].FindControl("newGoal");
            TextBox newGoalURL = (TextBox)rptTrainingGoals.Controls[rptTrainingGoals.Controls.Count - 1].Controls[0].FindControl("newGoalURL");

            // User has entered a new goal

            // Create the promise with relevant attributes
            FRT.DAL.TrainingGoal goal = new FRT.DAL.TrainingGoal();
            goal.PersonCode = dropdownPerson.SelectedValue;
            goal.Date       = DateTime.Today;
            goal.Goal       = newGoal.Text;
            goal.URL        = newGoalURL.Text;

            // Add to DB and commit
            entities.AddToTrainingGoals(goal);
            entities.SaveChanges();

            // Refresh data
            RefreshTrainingGoals();

            // Set focus to the new caption
            ScriptManager.GetCurrent(Page).SetFocus(rptTrainingGoals.Controls[rptTrainingGoals.Controls.Count - 1].Controls[0].FindControl("newGoal"));
        }
示例#2
0
        protected void SaveGoals_Click(object sender, EventArgs e)
        {
            FRT.DAL.frtEntities entities = new FRT.DAL.frtEntities();

            // Go through each of the items in the repeater and update
            foreach (RepeaterItem item in rptTrainingGoals.Items)
            {
                HiddenField lblGoalID  = (HiddenField)item.FindControl("lblGoalID");
                TextBox     txtGoal    = (TextBox)item.FindControl("txtGoal");
                TextBox     txtGoalURL = (TextBox)item.FindControl("txtGoalURL");

                int goalID = Convert.ToInt32(lblGoalID.Value);

                // See if the goal exists in the database
                var goals = from g in entities.TrainingGoals
                            where g.GoalID == goalID
                            select g;

                if (goals.Count() != 0)
                {
                    // It does exist
                    FRT.DAL.TrainingGoal goal = goals.First();

                    // If the textbox is empty, delete the row
                    if (txtGoal.Text.Equals(""))
                    {
                        entities.DeleteObject(goal);
                    }
                    else
                    {
                        // Otherwise update the goal
                        goal.Goal = txtGoal.Text;
                        goal.URL  = txtGoalURL.Text;
                    }
                }
                else
                {
                    // it doesn't exist. wtf??
                }
            }
            // Save changes and refresh data
            entities.SaveChanges();
            RefreshTrainingGoals();
            pnlTrainingGoals.Visible = false;
        }