Пример #1
0
        protected void newPromiseDescription_TextChanged(object sender, EventArgs e)
        {
            // User has entered a new promise
            DropDownList ddWeek   = (DropDownList)this.Parent.FindControl("dropdownWeek");
            DropDownList ddPerson = (DropDownList)this.Parent.FindControl("dropdownPerson");
            TextBox      newPromiseDescription = ((TextBox)sender);

            // Create the promise with relevant attributes
            FRT.DAL.Promise newPromise = new FRT.DAL.Promise();
            newPromise.PromiseCategory    = this.PromiseCategoryID;
            newPromise.PromiseDescription = newPromiseDescription.Text;
            newPromise.PromiseWeek        = Convert.ToDateTime(ddWeek.SelectedValue);
            newPromise.PersonCode         = ddPerson.SelectedValue;
            newPromiseDescription.Text    = "";

            // Add to DB and commit
            entities.AddToPromises(newPromise);
            entities.SaveChanges();

            // Refresh data
            BindRepeaters();

            // Set the control focus to the 'new promise' textbox
            ScriptManager.GetCurrent(Page).SetFocus(this.rptThisWeek.Controls[rptThisWeek.Controls.Count - 1].Controls[0].FindControl("newPromiseDescription"));
            //((ScriptManager)Parent.FindControl("ScriptManager1")).SetFocus(newPromiseDescription);
        }
Пример #2
0
        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);
        }