protected void getTimesheet()
        {
            try
            {
                //populate form with existing timesheet record
                Int32 TimesheetID = Convert.ToInt32(Request.QueryString["TimesheetID"]);

                //connect to db via EF
                using (wfbEntities2 db = new wfbEntities2())
                {
                    //populate a timesheet instance with the timesheetID from the URL parameter
                    Timesheet t = (from objT in db.Timesheets
                                   where objT.TimesheetID == TimesheetID
                                   select objT).FirstOrDefault();

                    //map the student properties to the form controls if we found a match
                    if (t != null)
                    {
                        txtDate.Text = t.date_worked.ToString("yyyy-MM-dd");
                        ddlHours.Text = Convert.ToString(t.total_hours);
                        txtJobDesc.Text = t.job_desc;
                        txtJobNumber.Text = Convert.ToString(t.job_number);
                        txtJobSite.Text = t.job_site;
                        txtCompany.Text = Convert.ToString(t.Reference_CompanyID);
                        txtEmployeeID.Text = Convert.ToString(t.employee_id);
                    }

                }
            }
            catch (Exception e)
            {
                Response.Redirect("/error.aspx");
            }
        }
        protected void grdTimesheets_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                //store which row was clicked
                Int32 selectedRow = e.RowIndex;

                //get the selected TimesheetID using the grid's Data Key collection
                Int32 TimesheetID = Convert.ToInt32(grdTimesheets.DataKeys[selectedRow].Values["TimesheetID"]);

                //use EF to remove the selected Timesheets from the db
                using (wfbEntities2 db = new wfbEntities2())
                {
                    Timesheet t = (from objT in db.Timesheets
                                   where objT.TimesheetID == TimesheetID
                                   select objT).FirstOrDefault();
                    //do the delete
                    db.Timesheets.Remove(t);
                    db.SaveChanges();
                }

                //refresh the grid
                getTimesheets();
            }
            catch (Exception d)
            {
                Response.Redirect("/error.aspx");
            }
        }
        protected void btnAddtime_Click(object sender, EventArgs e)
        {
            try
            {
                //use EF to connect to SQL Server
                using (wfbEntities2 db = new wfbEntities2())
                {

                    //use the timesheet model to save the new record
                    Timesheet t = new Timesheet();
                    Int32 TimesheetID = 0;

                    //check the querystring for an id so we can determine add / update
                    if (Request.QueryString["TimesheetID"] != null)
                    {
                        //get the id from the url
                        TimesheetID = Convert.ToInt32(Request.QueryString["TimesheetID"]);

                        //get the current timesheet from EF
                        t = (from objT in db.Timesheets
                             where objT.TimesheetID == TimesheetID
                             select objT).FirstOrDefault();
                    }

                    t.Reference_CompanyID = 1;
                    t.job_desc = txtJobDesc.Text;
                    t.job_number = Convert.ToInt32(txtJobNumber.Text);
                    t.job_site = txtJobSite.Text;
                    t.employee_id = Convert.ToInt32(txtEmployeeID.Text);
                    t.total_hours = Convert.ToDouble(ddlHours.SelectedValue);
                    t.date_worked = Convert.ToDateTime(txtDate.Text);

                    //call add only if we have no timesheet ID
                    if (TimesheetID == 0)
                    {
                        db.Timesheets.Add(t);
                    }

                    //run the update or insert
                    db.SaveChanges();

                    //redirect to the updated students page
                    Response.Redirect("/user/addtime.aspx");
                }
            }

            catch (Exception d)
            {
                Response.Redirect("/error.aspx");
            }
        }
        // protected void GetStudents()
        protected void GetBroadcasts()
        {
            try
            {
                //connect to EF
                using (wfbEntities2 db = new wfbEntities2())
                {
                    var grdBroad = from b in db.Broadcasts
                                   select b;
                    //bind the result to the gridview
                    grdBroadcasts.DataSource = grdBroad.ToList();
                    grdBroadcasts.DataBind();

                }
            }
            catch (Exception e)
            {
                Response.Redirect("/error.aspx");
            }
        }
        protected void getTimesheets()
        {
            try
            {
                //connect to EF
                using (wfbEntities2 db = new wfbEntities2())
                {
                    var grdTime = from ti in db.Timesheets
                                  select ti;

                    grdTimesheets.DataSource = grdTime.ToList();
                    grdTimesheets.DataBind();

                }
            }
            catch(Exception e)
            {
                Response.Redirect("/error.aspx");
            }
        }