protected void grdBroadcasts_OnRowDeleting(object sender, GridViewDeleteEventArgs e) { try { //store which row was clicked Int32 selectedRow = e.RowIndex; //get the selected StudentID using the grid's Data Key collection Int32 BroadcastID = Convert.ToInt32(grdBroadcasts.DataKeys[selectedRow].Values["BroadcastID"]); //use EF to remove the selected broadcast from the db using (wfbEntities2 db = new wfbEntities2()) { Broadcast b = (from objB in db.Broadcasts where objB.BroadcastID == BroadcastID select objB).FirstOrDefault(); //do the delete db.Broadcasts.Remove(b); db.SaveChanges(); } //refresh the grid getBroadcasts(); } catch (Exception d) { Response.Redirect("/error.aspx"); } }
protected void btnBroadcast_Click(object sender, EventArgs e) { try { //use EF to connect to SQL Server using (wfbEntities2 db = new wfbEntities2()) { //use the broadcast model to save the new record Broadcast b = new Broadcast(); Int32 BroadcastID = 0; //check the querystring for an id so we can determine add / update if (Request.QueryString["BroadcastID"] != null) { //get the id from the url BroadcastID = Convert.ToInt32(Request.QueryString["BroadcastID"]); //get the current broadcast from EF b = (from objB in db.Broadcasts where objB.BroadcastID == BroadcastID select objB).FirstOrDefault(); } b.MessageBroadcast = txtMessage.Text; b.Reference_CompanyID = 1; b.SignatureBroadcast = txtName.Text; b.TitleBroadcast = txtTitle.Text; //call add only if we have no broadcast ID if (BroadcastID == 0) { db.Broadcasts.Add(b); } //run the update or insert db.SaveChanges(); //redirect to the updated students page Response.Redirect("/admin/broadcasts.aspx"); } } catch (Exception d) { 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"); } }
protected void getJobNumber() { try { using (wfbEntities2 db = new wfbEntities2()) { Int32 job_number = Convert.ToInt32(txtJobNumber.Text); var job = (from objT in db.Timesheets where objT.job_number == job_number select objT); grdJobNumber.DataSource = job.ToList(); grdJobNumber.DataBind(); } } catch(Exception e) { Response.Redirect("/error.aspx"); } }
protected void getEmployee() { try { using (wfbEntities2 db = new wfbEntities2()) { Int32 employeeID = Convert.ToInt32(txtEmployee.Text); var grd = (from objT in db.Timesheets where objT.employee_id == employeeID select objT); grdEmployee.DataSource = grd.ToList(); grdEmployee.DataBind(); } } catch (Exception e) { Response.Redirect("/error.aspx"); } }
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 getBroadcast() { try { //populate form with existing Broadcast record Int32 BroadcastID = Convert.ToInt32(Request.QueryString["BroadcastID"]); //connect to db via EF using (wfbEntities2 db = new wfbEntities2()) { //populate a Broadcast instance with the BroadcastID from the URL parameter Broadcast b = (from objB in db.Broadcasts where objB.BroadcastID == BroadcastID select objB).FirstOrDefault(); //map the broadcast properties to the form controls if we found a match if (b != null) { txtCompany.Text = Convert.ToString(b.Reference_CompanyID); txtMessage.Text = b.MessageBroadcast; txtName.Text = b.SignatureBroadcast; txtTitle.Text = b.TitleBroadcast; } //broadcasts - this code goes in the same method that populates the broadcast form but below the existing code that's already in getBroadcast() /* grdCourses.DataSource = objE.ToList(); grdCourses.DataBind();*/ } } catch (Exception e) { Response.Redirect("/error.aspx"); } }