public bool Save_Changes() { // Go through the each repeater item for this week foreach (RepeaterItem item in rptThisWeek.Items) { TextBox txtPromiseDescription = ((TextBox)item.FindControl("twPromiseDescription")); CheckBox cbPromiseComplete = ((CheckBox)item.FindControl("twPromiseComplete")); Label lblPromiseID = ((Label)item.FindControl("twPromiseID")); int promiseID = Convert.ToInt32(lblPromiseID.Text); // See if the promise exists in the database var promises = from p in entities.Promises where p.PromiseID == promiseID select p; if (promises.Count() != 0) { // It does exist FRT.DAL.Promise promise = promises.First(); // If the new textbox is empty, delete the row if (txtPromiseDescription.Text == "") { entities.DeleteObject(promise); } else { // Otherwise update the promisedescription if (!promise.PromiseDescription.Equals(txtPromiseDescription.Text)) { promise.PromiseDescription = txtPromiseDescription.Text; } // If the promisecomplete has changed, update that too. if (!promise.PromiseComplete.Equals(cbPromiseComplete.Checked)) { promise.PromiseComplete = cbPromiseComplete.Checked; } } } else { // it doesn't exist. wtf?? } } // Save changes and refresh data entities.SaveChanges(); BindRepeaters(); // Always return true (we have the option to in the future return false for failure) return(true); }
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")); }
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; }
protected void SaveChanges() { FRT.DAL.frtEntities entities = new FRT.DAL.frtEntities(); // Go through the each repeater item for this month foreach (RepeaterItem item in rptBudget.Items) { Label lblPersonCode = ((Label)item.FindControl("lblPersonCode")); TextBox txtTimesheet = ((TextBox)item.FindControl("txtTimesheet")); TextBox txtInvoice = ((TextBox)item.FindControl("txtInvoice")); TextBox txtWOF = ((TextBox)item.FindControl("txtWOF")); TextBox txtWIP = ((TextBox)item.FindControl("txtWIP")); // Try to convert all the textboxes to decimal values // If the conversion fails, it will convert with 0 decimal dTimesheet, dInvoice, dWOF, dWIP; Decimal.TryParse(txtTimesheet.Text, out dTimesheet); Decimal.TryParse(txtInvoice.Text, out dInvoice); Decimal.TryParse(txtWOF.Text, out dWOF); Decimal.TryParse(txtWIP.Text, out dWIP); DateTime thisMonth = Convert.ToDateTime(dropdownMonth.SelectedValue); // See if the kpi exists in the database var kpis = from kpi in entities.FinancialKPIsMonths where kpi.KPIMonth == thisMonth && kpi.PersonCode.Equals(lblPersonCode.Text) select kpi; if (kpis.Count() != 0) { // It does exist FRT.DAL.FinancialKPIsMonth kpi = kpis.First(); kpi.TimesheetDollarsBudget = dTimesheet; kpi.InvoiceDollarsBudget = dInvoice; kpi.WriteOffDollarsBudget = dWOF; kpi.WIPDollarsBudget = dWIP; } else { // It doesn't exist, make a new row FRT.DAL.FinancialKPIsMonth kpi = new FRT.DAL.FinancialKPIsMonth(); kpi.PersonCode = lblPersonCode.Text; kpi.KPIMonth = thisMonth; kpi.TimesheetDollarsBudget = dTimesheet; kpi.InvoiceDollarsBudget = dInvoice; kpi.WriteOffDollarsBudget = dWOF; kpi.WIPDollarsBudget = dWIP; kpi.TimesheetDollars = 0; kpi.InvoiceDollars = 0; kpi.WriteOffDollars = 0; kpi.WIPDollars = 0; entities.AddToFinancialKPIsMonths(kpi); } } // Save changes and refresh data entities.SaveChanges(); RefreshData(); }