コード例 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            ExportDateRange exportDateRange = db.ExportDateRange.Find(id);

            db.ExportDateRange.Remove(exportDateRange);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #2
0
 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));
 }
コード例 #3
0
        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"));
        }
コード例 #4
0
        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"));
        }
コード例 #5
0
        // 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));
        }