protected void grdContractors_RowDeleting(object sender, GridViewDeleteEventArgs g) { try { //Store which row was clicked Int32 selectedRow = g.RowIndex; //get the selected sudent ID using the grids data key collection Int32 ContractorID = Convert.ToInt32(grdContractors.DataKeys[selectedRow].Values["ContractorID"]); //use entity to find the object and remove it using (ErmagerdEntities db = new ErmagerdEntities()) { Contractor j = (from objs in db.Contractors where objs.ContractorID == ContractorID select objs).FirstOrDefault(); //now we need to do the delete db.Contractors.Remove(j); db.SaveChanges(); } //refresh the grid getContractors(); } catch (FileNotFoundException e) { Server.Transfer("/ErrorPage.aspx", true); } catch (System.IO.IOException e) { Server.Transfer("/ErrorPage.aspx", true); } catch(Exception e) { Server.Transfer("/ErrorPage.aspx", true); } }
protected void getContractor() { try { Int32 ContractorID = Convert.ToInt32(Request.QueryString["ContractorID"]); using (ErmagerdEntities db = new ErmagerdEntities()) { Contractor d = (from objs in db.Contractors where objs.ContractorID == ContractorID select objs).FirstOrDefault(); txtFirstName.Text = d.FirstName; txtLastName.Text = d.LastName; txtService.Text = d.Service; } } catch (FileNotFoundException e) { Server.Transfer("/ErrorPage.aspx", true); } catch (System.IO.IOException e) { Server.Transfer("/ErrorPage.aspx", true); } catch (Exception e) { Server.Transfer("/ErrorPage.aspx", true); } }
protected void getContractors() { try { using (ErmagerdEntities db = new ErmagerdEntities()) { //query the Jobs table using entity var Contractors = from c in db.Contractors select c; grdContractors.DataSource = Contractors.ToList(); grdContractors.DataBind(); } } catch (FileNotFoundException e) { Server.Transfer("/ErrorPage.aspx", true); } catch (System.IO.IOException e) { Server.Transfer("/ErrorPage.aspx", true); } catch (Exception e) { Server.Transfer("/ErrorPage.aspx", true); } }
protected void getCustomer() { try { Int32 CustomerID = Convert.ToInt32(Request.QueryString["CustomerID"]); using (ErmagerdEntities db = new ErmagerdEntities()) { Customer d = (from objs in db.Customers where objs.CustomerID == CustomerID select objs).FirstOrDefault(); txtName.Text = d.Name; txtAddress.Text = d.Address; } } catch (FileNotFoundException e) { Server.Transfer("/ErrorPage.aspx", true); } catch (System.IO.IOException e) { Server.Transfer("/ErrorPage.aspx", true); } catch (Exception e) { Server.Transfer("/ErrorPage.aspx", true); } }
protected void getEmployees() { try { using (ErmagerdEntities db = new ErmagerdEntities()) { //query the Employees table using entity var Employees = from s in db.Employees select s; grdEmployees.DataSource = Employees.ToList(); grdEmployees.DataBind(); } } catch (FileNotFoundException e) { Server.Transfer("/ErrorPage.aspx", true); } catch (System.IO.IOException e) { Server.Transfer("/ErrorPage.aspx", true); } catch (Exception e) { Server.Transfer("/ErrorPage.aspx", true); } }
protected void getCustomers() { try { using (ErmagerdEntities db = new ErmagerdEntities()) { var Customers = from s in db.Customers select s; grdShowCustomers.DataSource = Customers.ToList(); grdShowCustomers.DataBind(); } } catch (FileNotFoundException e) { Server.Transfer("/ErrorPage.aspx", true); } catch (System.IO.IOException e) { Server.Transfer("/ErrorPage.aspx", true); } catch (Exception e) { Server.Transfer("/ErrorPage.aspx", true); } }
//Populate the dropdown for the customers protected void GetCustomers() { try { using (ErmagerdEntities db = new ErmagerdEntities()) { var customer = (from d in db.Customers orderby d.CustomerID select d); ddlCustomerSearch.DataSource = customer.ToList(); ddlCustomerSearch.DataBind(); } } catch (FileNotFoundException e) { Server.Transfer("/ErrorPage.aspx", true); } catch (System.IO.IOException e) { Server.Transfer("/ErrorPage.aspx", true); } catch (Exception e) { Server.Transfer("/ErrorPage.aspx", true); } }
protected void GetEmployee() { try { //populate form for edit //get the ID Int32 EmployeeID = Convert.ToInt32(Request.QueryString["EmployeeID"]); //connec tot he db using Entity using (ErmagerdEntities db = new ErmagerdEntities()) { //populate from a Employee instance with the Employee ID from the URL params Employee s = (from objs in db.Employees where objs.EmployeeID == EmployeeID select objs).FirstOrDefault(); //mpa the Employee properties from the form controls txtLastName.Text = s.LastName; txtFirstName.Text = s.FirstName; txtHireDate.Text = s.HireDate.ToShortDateString(); //enrollments - this code goes in the same method that populates the Employee form but below the existing code that's already in GetEmployee() //var objE = (from en in db.Enrollments // join c in db.Courses on en.CourseID equals c.CourseID // join d in db.Departments on c.DepartmentID equals d.DepartmentID // where en.EmployeeID == EmployeeID // select new { en.EnrollmentID, en.Grade, c.Title, d.Name }); //grdCourses.DataSource = objE.ToList(); //grdCourses.DataBind(); } } catch (FileNotFoundException e) { Server.Transfer("/ErrorPage.aspx", true); } catch (System.IO.IOException e) { Server.Transfer("/ErrorPage.aspx", true); } catch (Exception e) { Server.Transfer("/ErrorPage.aspx", true); } }
//When save is clicked protected void btnSave_Click(object sender, EventArgs e) { try { using (ErmagerdEntities db = new ErmagerdEntities()) { Job J = new Job(); Int32 JobID = 0; if (Request.QueryString.Count > 0) { JobID = Convert.ToInt32(Request.QueryString["JobID"]); //get the Job from the entity ;D } J.CustomerID = Convert.ToInt32(ddlCustomerSearch.SelectedValue.ToString()); J.Cost = Convert.ToInt32(txtCost.Text); J.MaterialCost = Convert.ToInt32(txtMaterialCost.Text); J.JobDate = Convert.ToDateTime(txtJobDate.Text); J.Description = txtDescription.Text; if (JobID == 0) { db.Jobs.Add(J); } db.SaveChanges(); Response.Redirect("~/admin/Jobs.aspx"); } } catch (FileNotFoundException ex) { Server.Transfer("/ErrorPage.aspx", true); } catch (System.IO.IOException ex) { Server.Transfer("/ErrorPage.aspx", true); } catch (Exception ex) { Server.Transfer("/ErrorPage.aspx", true); } }
//When save is clicked protected void btnSave_Click(object sender, EventArgs e) { try { using (ErmagerdEntities db = new ErmagerdEntities()) { Contractor Con = new Contractor(); Int32 ContractorID = 0; if (Request.QueryString.Count > 0) { ContractorID = Convert.ToInt32(Request.QueryString["ContractorID"]); //get the Employee from the entity ;D } Con.FirstName = txtFirstName.Text; Con.LastName = txtLastName.Text; Con.Service = txtService.Text; if (ContractorID == 0) { db.Contractors.Add(Con); } db.SaveChanges(); Response.Redirect("~/admin/ShowContractors.aspx"); } } catch (FileNotFoundException r) { Server.Transfer("/ErrorPage.aspx", true); } catch (System.IO.IOException r) { Server.Transfer("/ErrorPage.aspx", true); } catch (Exception r) { Server.Transfer("/ErrorPage.aspx", true); } }
//When save is clicked protected void btnSave_Click(object sender, EventArgs e) { try { using (ErmagerdEntities db = new ErmagerdEntities()) { Employee Emp = new Employee(); Int32 EmployeeID = 0; if (Request.QueryString.Count > 0) { EmployeeID = Convert.ToInt32(Request.QueryString["EmployeeID"]); //get the Employee from the entity ;D } Emp.LastName = txtLastName.Text; Emp.FirstName = txtFirstName.Text; Emp.HireDate = Convert.ToDateTime(txtHireDate.Text); if (EmployeeID == 0) { db.Employees.Add(Emp); } db.SaveChanges(); Response.Redirect("~/admin/Employees.aspx"); } } catch (FileNotFoundException ex) { Server.Transfer("/ErrorPage.aspx", true); } catch (System.IO.IOException ex) { Server.Transfer("/ErrorPage.aspx", true); } catch (Exception ex) { Server.Transfer("/ErrorPage.aspx", true); } }
//When save is clicked protected void btnSave_Click(object sender, EventArgs e) { try { using (ErmagerdEntities db = new ErmagerdEntities()) { Customer Cus = new Customer(); Int32 CustomerID = 0; if (Request.QueryString.Count > 0) { CustomerID = Convert.ToInt32(Request.QueryString["CustomerID"]); //get the Employee from the entity ;D } Cus.Name = txtName.Text; Cus.Address = txtAddress.Text; if (CustomerID == 0) { db.Customers.Add(Cus); } db.SaveChanges(); Response.Redirect("~/admin/ShowCustomers.aspx"); } } catch (FileNotFoundException ex) { Server.Transfer("/ErrorPage.aspx", true); } catch (System.IO.IOException ex) { Server.Transfer("/ErrorPage.aspx", true); } catch (Exception ex) { Server.Transfer("/ErrorPage.aspx", true); } }