コード例 #1
0
        public void UpdateReport(IncidentReport report)
        {
            List <IncidentReport> list = new List <IncidentReport>();

            using (var ctx = new IncidentCloudContext())
            {
                foreach (IncidentReport ir in ctx.IncidentReports)
                {
                    list.Add(ir);
                }

                int i = 0;
                for (i = 0; i < list.Count; i++)
                {
                    if (DateTime.Compare(list[i].Time, report.Time) == 0)
                    {
                        i = list[i].Id;
                        break;
                    }
                }

                var res = ctx.IncidentReports.Where(r => r.Id == i).FirstOrDefault();
                res.Reason        = report.Reason;
                res.RepairTime    = report.RepairTime;
                res.CrewSent      = report.CrewSent;
                res.Crewtype      = report.Crewtype;
                res.IncidentState = report.IncidentState;
                res.LostPower     = report.LostPower;
                try { res.InvestigationCrew = ctx.Crews.Where(c => c.Id == report.InvestigationCrew.Id).FirstOrDefault(); } catch { }
                try { res.RepairCrew = ctx.Crews.Where(c => c.Id == report.RepairCrew.Id).FirstOrDefault(); } catch { }

                ctx.SaveChanges();
            }
        }
コード例 #2
0
        public List <List <IncidentReport> > GetAllReportsSortByBreaker(List <string> mrids)
        {
            List <IncidentReport> temp = new List <IncidentReport>();
            Dictionary <string, List <IncidentReport> > reportsByBreaker = new Dictionary <string, List <IncidentReport> >();
            List <List <IncidentReport> > retVal = new List <List <IncidentReport> >();

            foreach (string mrid in mrids)
            {
                reportsByBreaker.Add(mrid, new List <IncidentReport>());
            }

            using (var ctxCloud = new IncidentCloudContext())
            {
                temp = ctxCloud.IncidentReports.ToList();
            }

            foreach (IncidentReport report in temp)
            {
                if (reportsByBreaker.ContainsKey(report.MrID))
                {
                    reportsByBreaker[report.MrID].Add(report);
                }
            }

            int i = 0;

            foreach (List <IncidentReport> reports in reportsByBreaker.Values)
            {
                retVal.Add(new List <IncidentReport>());
                retVal[i++] = reports;
            }

            return(retVal);
        }
コード例 #3
0
        public IncidentReport GetReport(DateTime id)
        {
            List <IncidentReport> retVal = new List <IncidentReport>();

            using (var ctxCloud = new IncidentCloudContext())
            {
                foreach (IncidentReport ir in ctxCloud.IncidentReports)
                {
                    retVal.Add(ir);
                }
            }

            IncidentReport res = null;

            foreach (IncidentReport report in retVal)
            {
                if (DateTime.Compare(report.Time, id) == 0)
                {
                    res = report;
                    break;
                }
            }

            using (var ctxCloud = new IncidentCloudContext())
            {
                res = ctxCloud.IncidentReports.Where(ir => ir.Id == res.Id).Include("InvestigationCrew").FirstOrDefault();
            }
            return(res);
        }
コード例 #4
0
 public void AddReport(IncidentReport report)
 {
     using (var ctxCloud = new IncidentCloudContext())
     {
         ctxCloud.IncidentReports.Add(report);
         ctxCloud.SaveChanges();
     }
 }
コード例 #5
0
 public void AddElementStateReport(ElementStateReport report)
 {
     using (var ctxCloud = new IncidentCloudContext())
     {
         ctxCloud.ElementStateReports.Add(report);
         ctxCloud.SaveChanges();
         Console.WriteLine("Upisano:\n MRID: " + report.MrID + ", Date Time: " + report.Time + ", State: " + report.State);
     }
 }
コード例 #6
0
        public List <IncidentReport> GetReportsForSpecificTimeInterval(DateTime startTime, DateTime endTime)
        {
            List <IncidentReport> retVal = new List <IncidentReport>();

            using (var ctxCloud = new IncidentCloudContext())
            {
                ctxCloud.IncidentReports.Where(u => u.Time > startTime && u.Time < endTime).ToList().ForEach(x => retVal.Add(x));
            }
            return(retVal);
        }
コード例 #7
0
        public List <ElementStateReport> GetElementStateReportsForSpecificMrIDAndSpecificTimeInterval(string mrID, DateTime startTime, DateTime endTime)
        {
            List <ElementStateReport> retVal = new List <ElementStateReport>();

            using (var ctxClud = new IncidentCloudContext())
            {
                ctxClud.ElementStateReports.Where(u => u.MrID == mrID && u.Time > startTime && u.Time < endTime).ToList().ForEach(x => retVal.Add(x));
            }
            return(retVal);
        }
コード例 #8
0
        public List <Crew> GetCrews()
        {
            List <Crew> retVal = new List <Crew>();

            using (var ctxCloud = new IncidentCloudContext())
            {
                ctxCloud.Crews.ToList().ForEach(u => retVal.Add(u));
            }
            return(retVal);
        }
コード例 #9
0
        public List <IncidentReport> GetAllReports()
        {
            List <IncidentReport> retVal = new List <IncidentReport>();

            using (var ctxCloud = new IncidentCloudContext())
            {
                foreach (IncidentReport ir in ctxCloud.IncidentReports.Include("InvestigationCrew").Include("RepairCrew"))
                {
                    retVal.Add(ir);
                }
            }
            return(retVal);
        }
コード例 #10
0
        public List <ElementStateReport> GetAllElementStateReports()
        {
            List <ElementStateReport> retVal = new List <ElementStateReport>();

            using (var ctxCloud = new IncidentCloudContext())
            {
                foreach (ElementStateReport ir in ctxCloud.ElementStateReports)
                {
                    retVal.Add(ir);
                }
            }
            return(retVal);
        }
コード例 #11
0
        public List <List <IncidentReport> > GetReportsForMrID(string mrID)
        {
            List <IncidentReport> temp = new List <IncidentReport>();
            Dictionary <string, List <IncidentReport> > reportsByBreaker = new Dictionary <string, List <IncidentReport> >();
            List <List <IncidentReport> > retVal = new List <List <IncidentReport> >();

            using (var ctxCloud = new IncidentCloudContext())
            {
                ctxCloud.IncidentReports.ToList();

                foreach (IncidentReport report in ctxCloud.IncidentReports.ToList())
                {
                    if (report.MrID == mrID)
                    {
                        temp.Add(report);
                    }
                }
            }

            foreach (IncidentReport report in temp)
            {
                string key = report.Time.Day + "/" + report.Time.Month + "/" + report.Time.Year;

                if (!reportsByBreaker.ContainsKey(key))
                {
                    reportsByBreaker.Add(key, new List <IncidentReport>());
                }

                reportsByBreaker[key].Add(report);
            }

            int i = 0;

            foreach (List <IncidentReport> reports in reportsByBreaker.Values)
            {
                retVal.Add(new List <IncidentReport>());
                retVal[i++] = reports;
            }

            return(retVal);
        }
コード例 #12
0
        public bool AddCrew(Crew crew)
        {
            using (var ctx = new IncidentCloudContext())
            {
                try
                {
                    ctx.Crews.Add(crew);

                    foreach (Crew c in ctx.Crews)
                    {
                        Console.WriteLine("Added crew: " + c.CrewName + ", crew id: " + c.Id);
                    }

                    ctx.SaveChanges();

                    using (var ctxCloud = new IncidentCloudContext())
                    {
                        try
                        {
                            ctxCloud.Crews.Add(crew);
                            foreach (Crew c in ctx.Crews)
                            {
                                Console.WriteLine("Added crew: " + c.CrewName + ", crew id: " + c.Id);
                            }
                            ctxCloud.SaveChanges();
                            return(true);
                        }
                        catch (Exception e)
                        {
                            return(false);
                        }
                    }
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
        }
コード例 #13
0
        private void LoadCrews()
        {
            List <Crew> crews = new List <Crew>();
            Crew        c1    = new Crew()
            {
                Id = "1", CrewName = "Adam Smith", Type = CrewType.Investigation
            };
            Crew c2 = new Crew()
            {
                Id = "2", CrewName = "Danny Phillips", Type = CrewType.Investigation
            };
            Crew c3 = new Crew()
            {
                Id = "3", CrewName = "Anna Davis", Type = CrewType.Investigation
            };
            Crew c4 = new Crew()
            {
                Id = "4", CrewName = "Mark Crow", Type = CrewType.Repair
            };
            Crew c5 = new Crew()
            {
                Id = "5", CrewName = "Jullie Stephenson", Type = CrewType.Repair
            };
            Crew c6 = new Crew()
            {
                Id = "6", CrewName = "David Phill", Type = CrewType.Repair
            };

            crews.Add(c1);
            crews.Add(c2);
            crews.Add(c3);
            crews.Add(c4);
            crews.Add(c5);

            //using (var ctx = new IncidentContext())
            //{
            //    foreach (Crew c in crews)
            //    {
            //        try
            //        {
            //            if (!ctx.Crews.Any(e => e.Id == c.Id))
            //            {
            //                ctx.Crews.Add(c);
            //                ctx.SaveChanges();
            //            }
            //        }
            //        catch (Exception e) { }
            //    }
            //}
            using (var ctxCloud = new IncidentCloudContext())
            {
                foreach (Crew c in crews)
                {
                    try
                    {
                        if (!ctxCloud.Crews.Any(e => e.Id == c.Id))
                        {
                            ctxCloud.Crews.Add(c);
                            ctxCloud.SaveChanges();
                        }
                    }
                    catch (Exception e) { }
                }
            }
        }
コード例 #14
0
        private void LoadCrews()
        {
            List <Crew> crews = new List <Crew>();
            Crew        c1    = new Crew()
            {
                Id = "1", CrewName = "Crew_1", Type = CrewType.TYPE1
            };
            Crew c2 = new Crew()
            {
                Id = "2", CrewName = "Crew_2", Type = CrewType.TYPE1
            };
            Crew c3 = new Crew()
            {
                Id = "3", CrewName = "Crew_3", Type = CrewType.TYPE2
            };
            Crew c4 = new Crew()
            {
                Id = "4", CrewName = "Crew_4", Type = CrewType.TYPE2
            };
            Crew c5 = new Crew()
            {
                Id = "5", CrewName = "Crew_5", Type = CrewType.TYPE3
            };

            crews.Add(c1);
            crews.Add(c2);
            crews.Add(c3);
            crews.Add(c4);
            crews.Add(c5);

            using (var ctx = new IncidentContext())
            {
                foreach (Crew c in crews)
                {
                    try
                    {
                        if (!ctx.Crews.Any(e => e.Id == c.Id))
                        {
                            ctx.Crews.Add(c);
                            ctx.SaveChanges();
                        }
                    }
                    catch (Exception e) { }
                }
            }
            using (var ctxCloud = new IncidentCloudContext())
            {
                foreach (Crew c in crews)
                {
                    try
                    {
                        if (!ctxCloud.Crews.Any(e => e.Id == c.Id))
                        {
                            ctxCloud.Crews.Add(c);
                            ctxCloud.SaveChanges();
                        }
                    }
                    catch (Exception e) { }
                }
            }
        }