Esempio n. 1
0
        public ActionResult FacilityOverview(int?id)
        {
            using (var db = new Models.watermentdbEntities())
            {
                var model = new MainViewModel
                {
                    countries = db.countries_with_facilites_view.ToList(),
                    Facilites = db.facilities.Where(x => x.locations_countries_Id == id).ToList(),
                };


                return(View(model));
            }
        }
        // GET: Main
        public ActionResult Index(int?id, string sortOrder)
        {
            //Compare user IDs and updates IP adresses.
            foreach (var item in db.facilities)
            {
                item.IP = "";
                foreach (var item2 in db2.Client_Conection.Where(c => c.user == item.Id.ToString()))
                {
                    item.IP = item2.ip;
                }
            }
            // Fetches the current row id seleted in the table facilities and sets the facility IP to
            // the Client IP.
            foreach (var item in db.facilities)
            {
                IpFacility = item.IP;

                if (PingHost(IpFacility) == true)
                {
                    item.FacilityStatus_Id = 2;
                }
                else
                {
                    item.FacilityStatus_Id = 1;
                }
            }
            db.SaveChanges();

            using (var db1 = new Models.watermentdbEntities())

            {
                var model = new MainViewModel
                {
                    //Getting desired data from the database, and returning it to the view.
                    Countries   = db.countries.Where(c => c.continents.Id == id).ToList(),
                    Alarms      = db.alarms.Where(o => o.Status == "Active").ToList(),
                    Equipment   = db.equipments.Include(c => c.alarms).Include(c => c.facilities).ToList(),
                    Locations   = db.locations.ToList(),
                    Maintenance = db.maintenance.OrderBy(x => x.LastMaintenance).Take(10).ToList(),
                    Facilites   = db.facilities.ToList(),

                    NumberOfFacilities = db.facilities.Count(),
                    NumberOnline       = db.facilities.Where(x => x.FacilityStatus_Id == 2).Count(),
                    NumberOffline      = db.facilities.Where(x => x.FacilityStatus_Id == 1).Count(),
                    noAlarms           = db.alarms.Where(x => x.Status == "Active").Count(),
                };
                return(View(model));
            }
        }
        // GET: Maintanance
        public ActionResult Index(int?id)
        {
            using (var db = new Models.watermentdbEntities())
            {
                var model = new MaintenanceViewModel
                {
                    //Getting desired data from the database, and returning it to the view.
                    Equipments  = db.equipments.Include(c => c.alarms).Include(c => c.facilities).ToList(),
                    Location    = db.locations.ToList(),
                    Maintenance = db.maintenance.OrderByDescending(x => x.LastMaintenance).DistinctBy
                                      (x => x.facilities_Id).OrderBy(x => x.LastMaintenance).Take(10).ToList(),

                    Facilites = db.facilities.ToList(),
                };

                return(View(model));
            }
        }
Esempio n. 4
0
        public ActionResult FacilityDetails(int?id)
        {
            if (id == null) //Error handling if "int? id" is missing from the link.
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            // Fetches the current row id selected in the table Client_Conection
            foreach (var item2 in db.Client_Conection.Where(c => c.user == id.ToString()))
            {
                IpClient = item2.ip;
            }
            // Fetches the current row id seleted in the table facilities and sets the facility IP to
            // the Client IP.
            foreach (var item in db.facilities.Where(c => c.Id == id))
            {
                item.IP = IpClient;
            }

            // Saves the changes to the DB
            db.SaveChanges();


            using (var db = new Models.watermentdbEntities())
            {
                var model = new MainViewModel
                {
                    //Getting desired data from the database, and returning it to the view.
                    Alarms     = db.alarms.Where(x => x.equipments_facilities_Id == id).Where(o => o.Status == "Active").OrderByDescending(x => x.AlarmOccured).ToList(),
                    Facilites  = db.facilities.Where(c => c.Id == id).ToList(),
                    Countries  = db.countries.ToList(),
                    Locations  = db.locations.ToList(),
                    Users      = db.User.ToList(),
                    Equipments = db.equipments.Where(x => x.facilities_Id == id).ToList(),
                };

                return(View(model));
            }
        }
Esempio n. 5
0
        public ActionResult ExportAlarmsToExcel(int?id)
        {
            //Code to export Alarm list to Excel file
            using (var db = new Models.watermentdbEntities())
            {
                var grid = new System.Web.UI.WebControls.GridView();

                grid.DataSource =
                    from d in db.alarms.Where(x => x.equipments_facilities_Id == id).ToList()
                    select new
                {
                    //Getting information from database, and tell the excel file what to get.
                    ID           = d.Id,
                    ProcessValue = d.ProcessValue,
                    Recorded     = d.AlarmOccured,
                    Status       = d.Status,
                    EqupmentName = d.equipments.Tag,
                    Description  = d.Description
                };

                grid.DataBind();

                Response.ClearContent();
                Response.AddHeader("content-disposition", "attachment; filename=AlarmList.xls");
                Response.ContentType = "application/excel";
                StringWriter   swriter = new StringWriter();
                HtmlTextWriter hwriter = new HtmlTextWriter(swriter);

                grid.RenderControl(hwriter);

                Response.Write(swriter.ToString());

                Response.End();

                return(null);
            }
        }