public ActionResult DeleteConfirmed(int id) { ExportDateRange exportDateRange = db.ExportDateRange.Find(id); db.ExportDateRange.Remove(exportDateRange); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ExportDateRangeID,StartDate,EndDate")] ExportDateRange exportDateRange) { if (ModelState.IsValid) { db.Entry(exportDateRange).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(exportDateRange)); }
public ActionResult ExportData() { Date = db.ExportDateRange.SqlQuery( "SELECT * " + "FROM ExportDateRange " + "WHERE ExportDateRange.ExportDateRangeID = (SELECT MAX(ExportDateRange.ExportDateRangeID) AS DateRangeID " + "FROM ExportDateRange)" ).FirstOrDefault(); SqlConnection Con = new SqlConnection(); string Path = ConfigurationManager.ConnectionStrings["GVBDBContext"].ConnectionString; Con.ConnectionString = Path; DataTable DtNew = new DataTable(); SqlDataAdapter Adp = new SqlDataAdapter("SELECT Deceased.CattleNumber AS 'Cattle Number', " + "Dairy.dName AS 'Dairy', Feedlot.fName AS 'Feedlot', " + "Employee.EmpFname + ' ' + Employee.EmpLname AS 'Employee' , " + "Deceased.DeceasedDate " + "FROM Deceased INNER JOIN " + "Dairy ON Deceased.DairyID = Dairy.DairyID INNER JOIN " + "Feedlot ON Deceased.FeedlotID = Feedlot.FeedlotID FULL JOIN " + "Employee ON Deceased.EmployeeID = Employee.EmployeeID " + "WHERE Deceased.DeceasedDate BETWEEN '" + Date.StartDate + "' AND '" + Date.EndDate + "' AND Deceased.CattleNumber IS NOT NULL " + "ORDER BY Deceased.DeceasedDate DESC", Con); Adp.Fill(DtNew); if (DtNew.Rows.Count > 0) { string FilePath = Server.MapPath("~/DeceasedCattle.xlsx"); FileInfo Files = new FileInfo(FilePath); ExcelPackage excel = new ExcelPackage(Files); ExcelWorksheet ws = excel.Workbook.Worksheets.Add("Deceased Cattle"); for (int i = 0; i < DtNew.Columns.Count; i++) { ws.Cells[1, i + 1].Value = DtNew.Columns[i].ColumnName.ToString(); } for (int i = 0; i < DtNew.Rows.Count; i++) { for (int j = 0; j < DtNew.Columns.Count; j++) { ws.Cells[i + 2, j + 1].Value = DtNew.Rows[i][j].ToString(); } } Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment: filename=" + "DeceasedCattle.xlsx"); Response.BinaryWrite(excel.GetAsByteArray()); Response.End(); } return(View("Reports")); }
public ActionResult Create([Bind(Include = "ExportDateRangeID,StartDate,EndDate")] ExportDateRange exportDateRange) { if (ModelState.IsValid) { db.ExportDateRange.Add(exportDateRange); db.SaveChanges(); return(RedirectToAction("Reports", "User")); } return(View("Create")); }
// GET: ExportDateRanges/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ExportDateRange exportDateRange = db.ExportDateRange.Find(id); if (exportDateRange == null) { return(HttpNotFound()); } return(View(exportDateRange)); }