Ejemplo n.º 1
0
        private static void BuildFailingAddresses(ref Utf8JsonReader reader, ref RouteDetail routeDetail)
        {
            var addresses = new List <FailedAddress>();

            while (reader.Read())
            {
                if (reader.TokenType == JsonTokenType.EndArray)
                {
                    break;
                }

                if (reader.TokenType != JsonTokenType.StartObject)
                {
                    continue;
                }

                var failedAddress = new FailedAddress();
                while (reader.Read())
                {
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        break;
                    }

                    if (reader.TokenType != JsonTokenType.PropertyName)
                    {
                        continue;
                    }

                    var index = reader.ValueSpan[^ 1];
Ejemplo n.º 2
0
        public HttpResponseMessage AddRouteData(Route objRouteDetail, string Token)
        {
            string strJson  = string.Empty;
            var    response = this.Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                using (TTPAPIDataContext DB = new TTPAPIDataContext())
                {
                    foreach (var route in objRouteDetail.RouteDetail)
                    {
                        RouteDetail objroute = new RouteDetail();
                        objroute.RouteId = objRouteDetail.routeId;
                        objroute.SeqNo   = route.SeqNo;
                        objroute.Lat     = route.Lat;
                        objroute.Long    = route.Long;
                        DB.RouteDetails.InsertOnSubmit(objroute);
                        DB.SubmitChanges();
                    }
                    strJson          = "{\"Result\":\"204\"}";
                    response.Content = new StringContent(strJson, Encoding.UTF8, "application/json");
                    return(response);
                }
            }
            catch (Exception ex)
            {
                strJson          = "{\"Result\":\"" + ex.Message + "\"}";
                response.Content = new StringContent(strJson, Encoding.UTF8, "application/json");
                return(response);
            }
        }
Ejemplo n.º 3
0
        public void SavePath(string ProjectId, double?Distance, string LonLatStr)
        {
            using (var tx = this.m_UnitOfWork.BeginTransaction())
            {
                try
                {
                    ProjectRoute PR = new ProjectRoute();
                    PR.ProjectId = ProjectId;
                    PR.Source    = "E";
                    PR.IsPrimary = false;
                    PR           = this.Add(PR);


                    this.m_UnitOfWork.Flush();
                    RouteDetail RD = new RouteDetail();
                    RD.Distance = Distance;

                    RD.LonLatStr    = LonLatStr;
                    RD.RouteId      = PR.ID;
                    RD.ProjectID    = PR.ProjectId;
                    RD.ProjectRoute = PR;
                    PublicService ps = new PublicService();
                    ps.GetGenericService <RouteDetail>().Add(RD);
                    tx.Commit();
                }
                catch (Exception ex)
                {
                    tx.Rollback();
                    logger.Error(ex.Message, ex);
                    throw ex;
                }
            }
        }
Ejemplo n.º 4
0
        private static void BuildIPBlock(ref Utf8JsonReader reader, ref RouteDetail routeDetail)
        {
            var ipBlock = new IPBlock();

            while (reader.Read())
            {
                if (reader.TokenType == JsonTokenType.EndObject)
                {
                    break;
                }

                if (reader.TokenType != JsonTokenType.PropertyName)
                {
                    continue;
                }

                var index = reader.ValueSpan[0];
                reader.Read();

                switch (index)
                {
                case (byte)'t':
                    ipBlock.Type = reader.GetString();
                    break;

                case (byte)'s':
                    ipBlock.Size = reader.GetString();
                    break;
                }
            }

            routeDetail.IPBlock = ipBlock;
        }
        private void AddRouteDetail(RouteDetail routeDetail, Route route)
        {
            var stops = from stop in db.Stops
                        from routeStop in db.RouteStops
                        orderby routeStop.StopSequence
                        where (routeStop.StopID == stop.ID) && (routeStop.RouteID == route.ID)
                        select stop;

            foreach (var stop in stops)
            {
                // Use arrival times if available
                var stopWithArrivalTime = StopArrivalTime.GetStopSummaryWithArrivalTimes(stop.ID);
                if (stopWithArrivalTime != null)
                {
                    routeDetail.Stops.Add(stopWithArrivalTime);
                }
                else
                {
                    routeDetail.Stops.Add(new StopSummary(stop));
                }
            }

            var shapes = from shape in db.Shapes
                         orderby shape.Sequence
                         where (shape.RouteID == route.ID)
                         select shape;

            foreach (var shape in shapes)
            {
                var coordinate = new Location();
                coordinate.Lat = shape.Lat;
                coordinate.Lon = shape.Lon;
                routeDetail.RoutePath.Add(coordinate);
            }
        }
Ejemplo n.º 6
0
 private void LoadDependencies(CodeGenerationParameter aggregate, bool useCQRS)
 {
     if (useCQRS)
     {
         aggregate.Relate(RouteDetail.DefaultQueryRouteParameter(aggregate));
     }
     this.DependOn(AutoDispatchRouteTemplateData.From(aggregate.RetrieveAllRelated(Label.RouteSignature)));
 }
Ejemplo n.º 7
0
        public ActionResult DeleteConfirmed(decimal id)
        {
            RouteDetail routeDetail = db.RouteDetails.Find(id);

            db.RouteDetails.Remove(routeDetail);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 加載工站Pass下一站
        /// </summary>
        /// <param name="Station"></param>
        /// <param name="Input"></param>
        /// <param name="Paras"></param>
        /// add by LLF 2018-01-29
        public static void StationNextDataloader(MESPubLab.MESStation.MESStationBase Station, MESPubLab.MESStation.MESStationInput Input, List <R_Station_Action_Para> Paras)
        {
            string            NextStation     = "";
            MESStationSession StationNextSave = Station.StationSession.Find(t => t.MESDataType == Paras[0].SESSION_TYPE && t.SessionKey == Paras[0].SESSION_KEY);

            if (StationNextSave == null)
            {
                StationNextSave = new MESStationSession()
                {
                    MESDataType = Paras[0].SESSION_TYPE, InputValue = Input.Value.ToString(), SessionKey = Paras[0].SESSION_KEY, ResetInput = Input
                };
                Station.StationSession.Add(StationNextSave);
            }
            string strSn = Input.Value.ToString();
            SN     sn    = new SN();

            //Marked by LLF 2018-02-22 begin
            //sn.PanelSN(strSn, Station.SFCDB, MESDataObject.DB_TYPE_ENUM.Oracle);
            try
            {
                sn.PanelSN(strSn, Station.SFCDB, MESDataObject.DB_TYPE_ENUM.Oracle);
            }
            catch
            {
                sn.Load(strSn, Station.SFCDB, MESDataObject.DB_TYPE_ENUM.Oracle);
            }
            //Marked by LLF 2018-02-22 end

            Route              routeDetail     = new Route(sn.RouteID, GetRouteType.ROUTEID, Station.SFCDB, MESDataObject.DB_TYPE_ENUM.Oracle);
            List <string>      snStationList   = new List <string>();
            List <RouteDetail> routeDetailList = routeDetail.DETAIL;
            RouteDetail        R = routeDetailList.Where(r => r.STATION_NAME == Station.StationName).FirstOrDefault();

            if (R == null)
            {
                throw new MESReturnMessage(MESReturnMessage.GetMESReturnMessage("MSGCODE20180724154541", new string[] { Station.StationName }));
            }

            if (routeDetailList.Where(r => r.SEQ_NO > R.SEQ_NO).FirstOrDefault() == null)//當前工站為最後一個工站時
            {
                NextStation = routeDetailList.Where(r => r.SEQ_NO == R.SEQ_NO).FirstOrDefault().STATION_TYPE;
            }
            else
            {
                NextStation = routeDetailList.Where(r => r.SEQ_NO > R.SEQ_NO).FirstOrDefault().STATION_NAME;
            }

            snStationList.Add(NextStation);
            if (R.DIRECTLINKLIST != null)
            {
                foreach (var item in R.DIRECTLINKLIST)
                {
                    snStationList.Add(item.STATION_NAME);
                }
            }
            StationNextSave.Value = snStationList;
            Station.AddMessage("MES00000029", new string[] { "StationNext", "StationNextList" }, MESPubLab.MESStation.MESReturnView.Station.StationMessageState.Pass);
        }
Ejemplo n.º 9
0
        //加載SN待過工站
        public static void SNNextStationDataloader(MESPubLab.MESStation.MESStationBase Station, MESPubLab.MESStation.MESStationInput Input, List <R_Station_Action_Para> Paras)
        {
            //Modify by LLF 2018-01-26 通過配置獲取
            //MESStationSession WipStationSave = new MESStationSession() {MESDataType= "WIPSTATION", InputValue=Input.Value.ToString(),SessionKey="1",ResetInput=Input };

            string            StrNextStation  = "";
            MESStationSession NextStationSave = Station.StationSession.Find(t => t.MESDataType == Paras[0].SESSION_TYPE && t.SessionKey == Paras[0].SESSION_KEY);

            if (NextStationSave == null)
            {
                NextStationSave = new MESStationSession()
                {
                    MESDataType = Paras[0].SESSION_TYPE, InputValue = Input.Value.ToString(), SessionKey = Paras[0].SESSION_KEY, ResetInput = Input
                };
                Station.StationSession.Add(NextStationSave);
            }
            string             strSn           = Input.Value.ToString();
            SN                 sn              = new SN(strSn, Station.SFCDB, MESDataObject.DB_TYPE_ENUM.Oracle);
            Route              routeDetail     = new Route(sn.RouteID, GetRouteType.ROUTEID, Station.SFCDB, MESDataObject.DB_TYPE_ENUM.Oracle);
            List <string>      snStationList   = new List <string>();
            List <RouteDetail> routeDetailList = routeDetail.DETAIL;
            RouteDetail        R = routeDetailList.Where(r => r.STATION_NAME == sn.CurrentStation).FirstOrDefault();

            //Modify by LLF 2018-01-29
            //string nextStation1 = routeDetailList.Where(r => r.SEQ_NO == R.SEQ_NO + 10).FirstOrDefault().STATION_NAME;

            string nextStation1 = sn.NextStation;

            if (!sn.CurrentStation.Equals("REWORK"))
            {
                if (R == null)
                {
                    throw new MESReturnMessage(MESReturnMessage.GetMESReturnMessage("MES00000156", new string[] { strSn, sn.CurrentStation }));
                }

                if (routeDetailList.Where(r => r.SEQ_NO > R.SEQ_NO).FirstOrDefault() == null && !sn.CurrentStation.Equals("REWORK"))
                {
                    if (!string.IsNullOrEmpty(sn.CurrentStation))
                    {
                        StrNextStation = sn.NextStation;
                    }
                    throw new MESReturnMessage(MESReturnMessage.GetMESReturnMessage("MES00000200", new string[] { strSn, StrNextStation }));
                }
                nextStation1 = routeDetailList.Where(r => r.SEQ_NO > R.SEQ_NO).FirstOrDefault().STATION_NAME;
            }

            snStationList.Add(nextStation1);
            if (R != null && R.DIRECTLINKLIST != null)
            {
                foreach (var item in R.DIRECTLINKLIST)
                {
                    snStationList.Add(item.STATION_NAME);
                }
            }
            NextStationSave.Value = snStationList;
            Station.AddMessage("MES00000029", new string[] { "NextStationList", "NextStation" }, MESPubLab.MESStation.MESReturnView.Station.StationMessageState.Pass);
        }
Ejemplo n.º 10
0
        public void UpdateRoute(RouteDetail route, int RouteId)
        {
            var data = context.RouteDetails.SingleOrDefault(s => s.RouteId == RouteId);

            data.TripId     = route.TripId;
            data.CostId     = route.CostId;
            data.AirplaneId = route.AirplaneId;
            context.SaveChanges();
        }
Ejemplo n.º 11
0
        // GET: RouteDetails/Delete/5
        public ActionResult Delete(decimal id)
        {
            RouteDetail routeDetail = db.RouteDetails.Find(id);

            if (routeDetail == null)
            {
                return(HttpNotFound());
            }
            return(View(routeDetail));
        }
Ejemplo n.º 12
0
 public ActionResult Edit([Bind(Include = "ID,RouteID,StopNo,StopID,DistanceFromPrevStop")] RouteDetail routeDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(routeDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.RouteID = new SelectList(db.Routes, "ID", "Name", routeDetail.RouteID);
     ViewBag.StopID  = new SelectList(db.Stops, "ID", "Name", routeDetail.StopID);
     return(View(routeDetail));
 }
        private String SingleRouteDetailJSON(Route route, TrolleyTrackerContext db)
        {
            var routeDetailList = new List <RouteDetail>();  // Schedule web page expects array, even for single route
            var routeDetail     = new RouteDetail(route);

            routeDetail.AddRouteDetail(db, route);
            routeDetailList.Add(routeDetail);

            string routeDetailJSON = JsonConvert.SerializeObject(routeDetailList);

            return(routeDetailJSON);
        }
Ejemplo n.º 14
0
 public ActionResult UpdateRoute(int RouteId, RouteDetail route)
 {
     try
     {
         repository.UpdateRoute(route, RouteId);
         return(Ok("Route is Updated Successfully"));
     }
     catch (Exception e)
     {
         return(BadRequest(e));
     }
 }
Ejemplo n.º 15
0
 public ActionResult InsertRoute(RouteDetail route)
 {
     try
     {
         repository.InsertRoute(route);
         return(Ok("Route is Inserted Successfully"));
     }
     catch (Exception e)
     {
         return(BadRequest(e));
     }
 }
Ejemplo n.º 16
0
        /// <summary>
        /// By工單Route獲取下一工站
        /// </summary>
        /// <param name="Station"></param>
        /// <param name="Input"></param>
        /// <param name="Paras"></param>
        public static void StationNextByWODataloader(MESPubLab.MESStation.MESStationBase Station, MESPubLab.MESStation.MESStationInput Input, List <R_Station_Action_Para> Paras)
        {
            string    NextStation = "";
            WorkOrder WoObj       = new WorkOrder();

            MESStationSession WOSession = Station.StationSession.Find(t => t.MESDataType == Paras[0].SESSION_TYPE && t.SessionKey == Paras[0].SESSION_KEY);

            if (WOSession == null)
            {
                throw new MESReturnMessage(MESReturnMessage.GetMESReturnMessage("MES00000052", new string[] { Paras[0].SESSION_TYPE + Paras[0].SESSION_KEY }));
            }

            MESStationSession StationNextSave = Station.StationSession.Find(t => t.MESDataType == Paras[1].SESSION_TYPE && t.SessionKey == Paras[1].SESSION_KEY);

            if (StationNextSave == null)
            {
                StationNextSave = new MESStationSession()
                {
                    MESDataType = Paras[1].SESSION_TYPE, InputValue = Input.Value.ToString(), SessionKey = Paras[1].SESSION_KEY, ResetInput = Input
                };
                Station.StationSession.Add(StationNextSave);
            }

            WoObj = (WorkOrder)WOSession.Value;
            Route routeDetail = new Route(WoObj.RouteID, GetRouteType.ROUTEID, Station.SFCDB, MESDataObject.DB_TYPE_ENUM.Oracle);

            List <string>      snStationList   = new List <string>();
            List <RouteDetail> routeDetailList = routeDetail.DETAIL;
            RouteDetail        R = routeDetailList.Where(r => r.STATION_NAME == Station.StationName).FirstOrDefault();

            if (routeDetailList.Where(r => r.SEQ_NO > R.SEQ_NO).FirstOrDefault() == null)//當前工站為最後一個工站時
            {
                NextStation = routeDetailList.Where(r => r.SEQ_NO == R.SEQ_NO).FirstOrDefault().STATION_TYPE;
            }
            else
            {
                NextStation = routeDetailList.Where(r => r.SEQ_NO > R.SEQ_NO).FirstOrDefault().STATION_NAME;
            }

            snStationList.Add(NextStation);

            if (R.DIRECTLINKLIST != null)
            {
                foreach (var item in R.DIRECTLINKLIST)
                {
                    snStationList.Add(item.STATION_NAME);
                }
            }
            StationNextSave.Value = snStationList;
            Station.AddMessage("MES00000029", new string[] { "StationNext", "StationNextList" }, MESPubLab.MESStation.MESReturnView.Station.StationMessageState.Pass);
        }
Ejemplo n.º 17
0
        // GET: RouteDetails/Details/5
        public ActionResult Details(decimal id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RouteDetail routeDetail = db.RouteDetails.Find(id);

            if (routeDetail == null)
            {
                return(HttpNotFound());
            }
            return(View(routeDetail));
        }
Ejemplo n.º 18
0
        private static void BuildRouteDetail(ref Utf8JsonReader reader, ref RouteStatus routeStatus)
        {
            var routeDetail = new RouteDetail();

            while (reader.Read())
            {
                if (reader.TokenType == JsonTokenType.EndObject)
                {
                    break;
                }

                if (reader.TokenType != JsonTokenType.PropertyName)
                {
                    continue;
                }

                if (reader.TryRead("ipBlock"))
                {
                    BuildIPBlock(ref reader, ref routeDetail);
                }
                else if (reader.TryRead("failingAddresses"))
                {
                    BuildFailingAddresses(ref reader, ref routeDetail);
                }
                else if (reader.TryRead("blockIndex"))
                {
                    routeDetail.BlockIndex = reader.GetString();
                }
                else if (reader.TryRead("currentAddressIndex"))
                {
                    routeDetail.CurrentAddressIndex = reader.GetString();
                }
                else if (reader.TryRead("rotateIndex"))
                {
                    routeDetail.RotateIndex = reader.GetString();
                }
                else if (reader.TryRead("ipIndex"))
                {
                    routeDetail.IPIndex = reader.GetString();
                }
                else if (reader.TryRead("currentAddress"))
                {
                    routeDetail.CurrentAddress = reader.GetString();
                }
            }

            routeStatus.Details = routeDetail;
        }
        public IHttpActionResult GetRoute(int id)
        {
            Route route = db.Routes.Find(id);

            if (route == null)
            {
                return(NotFound());
            }

            // Assemble route + Stops + Shape
            var routeDetail = new RouteDetail(route);

            AddRouteDetail(routeDetail, route);

            return(Ok(routeDetail));
        }
Ejemplo n.º 20
0
        // GET: RouteDetails/Edit/5
        public ActionResult Edit(decimal id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RouteDetail routeDetail = db.RouteDetails.Find(id);

            if (routeDetail == null)
            {
                return(HttpNotFound());
            }
            ViewBag.RouteID = new SelectList(db.Routes, "ID", "Name", routeDetail.RouteID);
            ViewBag.StopID  = new SelectList(db.Stops, "ID", "Name", routeDetail.StopID);
            return(View(routeDetail));
        }
        private string ActiveRouteDetailJSON(TrolleyTrackerContext db)
        {
            var activeRouteSummaries = ActiveRoutes.GetActiveRoutes();
            var routeDetailList      = new List <RouteDetail>();

            foreach (var routeSummary in activeRouteSummaries)
            {
                var route       = db.Routes.Find(routeSummary.ID);
                var routeDetail = new RouteDetail(route);
                routeDetail.AddRouteDetail(db, route);
                routeDetailList.Add(routeDetail);
            }

            string routeDetailJSON = JsonConvert.SerializeObject(routeDetailList);

            return(routeDetailJSON);
        }
Ejemplo n.º 22
0
        public IHttpActionResult GetRoute(int id)
        {
            using (var db = new TrolleyTracker.Models.TrolleyTrackerContext())
            {
                Route route = db.Routes.Find(id);
                if (route == null)
                {
                    return(NotFound());
                }

                // Assemble route + Stops + Shape
                var routeDetail = new RouteDetail(route);

                routeDetail.AddRouteDetail(db, route);

                return(Ok(routeDetail));
            }
        }
Ejemplo n.º 23
0
 internal FilterDetail()
 {
     UniqueRoutes = new RouteDetail();
     GlobalRoutes = new RouteDetail();
 }
Ejemplo n.º 24
0
        /// <summary>
        /// 加載REWORK工站ROUTE LIST站
        /// </summary>
        /// <param name="Station"></param>
        /// <param name="Input"></param>
        /// <param name="Paras"></param>
        public static void RouteDetailDataloader(MESPubLab.MESStation.MESStationBase Station, MESPubLab.MESStation.MESStationInput Input, List <R_Station_Action_Para> Paras)
        {
            string            ErrMessage     = "";
            List <string>     NoCheckStation = new List <string>();
            MESStationSession StationSave    = Station.StationSession.Find(t => t.MESDataType == Paras[0].SESSION_TYPE && t.SessionKey == Paras[0].SESSION_KEY);

            if (StationSave == null)
            {
                StationSave = new MESStationSession()
                {
                    MESDataType = Paras[0].SESSION_TYPE, InputValue = Input.Value.ToString(), SessionKey = Paras[0].SESSION_KEY, ResetInput = Input
                };
                Station.StationSession.Add(StationSave);
            }
            MESStationSession WoSession = Station.StationSession.Find(t => t.MESDataType == Paras[1].SESSION_TYPE && t.SessionKey == Paras[1].SESSION_KEY);

            if (WoSession == null)
            {
                ErrMessage = MESReturnMessage.GetMESReturnMessage("MES00000052", new string[] { Paras[1].SESSION_TYPE + Paras[1].SESSION_KEY });
                throw new MESReturnMessage(ErrMessage);
            }
            WorkOrder ObjWo = (WorkOrder)WoSession.Value;

            List <R_Station_Action_Para> NoCheckSession = Paras.FindAll(t => t.SESSION_TYPE.Equals("NOCHECK"));


            try
            {
                MESStationInput I             = Station.Inputs.Find(t => t.DisplayName == "StationName");
                List <object>   snStationList = I.DataForUse;
                snStationList.Clear();
                snStationList.Add(""); ///BY SDL  加載頁面默認賦予空值,操作員必須點選其他有內容選項

                Route routeDetail = new Route(ObjWo.RouteID, GetRouteType.ROUTEID, Station.SFCDB, MESDataObject.DB_TYPE_ENUM.Oracle);
                List <RouteDetail> routeDetailList = routeDetail.DETAIL;
                RouteDetail        h = routeDetailList.Find(t => t.STATION_NAME == ObjWo.START_STATION);
                if (h == null)
                {
                    ErrMessage = MESReturnMessage.GetMESReturnMessage("MES00000204", new string[] { ObjWo.WorkorderNo, ObjWo.START_STATION });
                    throw new MESReturnMessage(ErrMessage);
                }
                for (int i = 0; i < routeDetailList.Count; i++)
                {
                    if (routeDetailList[i].SEQ_NO <= h.SEQ_NO)
                    {
                        snStationList.Add(routeDetailList[i].STATION_NAME);
                        if (routeDetailList[i].DIRECTLINKLIST != null)
                        {
                            foreach (var item in routeDetailList[i].DIRECTLINKLIST)
                            {
                                snStationList.Add(item.STATION_NAME);
                            }
                        }
                    }
                }
                for (int i = 0; i < NoCheckSession.Count; i++)
                {
                    snStationList.Remove(NoCheckSession[i].VALUE.ToString());
                }
                StationSave.Value = snStationList;
                Station.AddMessage("MES00000029", new string[] { "RouteID :", ObjWo.RouteID }, MESPubLab.MESStation.MESReturnView.Station.StationMessageState.Pass);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 25
0
            public override void Start()
            {
                QueueElement element;
                QueueElement newElement = new QueueElement();

                Subscription subscriptionEvent;

                bool elementRetrieved;

                try
                {
                    Manager.ThreadInitialize.Release();
                }
                catch
                {
                    // If the thread is restarted, this could throw an exception but just ignore
                }

                try
                {
                    while (true)
                    {
                        try
                        {
                            element = subscriptionMgrQueue.Dequeue();

                            if (element == default(QueueElement))
                            {
                                element          = newElement;
                                elementRetrieved = false;
                            }
                            else
                            {
                                elementRetrieved = true;
                            }
                        }
                        catch (InvalidOperationException)
                        {
                            element          = newElement;
                            elementRetrieved = false;
                        }

                        if (elementRetrieved == true)
                        {
                            if (element.BodyEvent == null)
                            {
                                element.BodyEvent = new Subscription(element.WspEvent.Body);
                            }

                            subscriptionEvent = (Subscription)element.BodyEvent;

                            if (subscriptionEvent.LocalOnly == false)
                            {
                                if (subscriptionEvent.Subscribe == true)
                                {
                                    lock (subscriptionsLock)
                                    {
                                        if (string.IsNullOrEmpty(subscriptionEvent.MethodBody) == true)
                                        {
                                            RouteDetail routeDetail;

                                            if (generalSubscriptions.TryGetValue(subscriptionEvent.SubscriptionEventType, out routeDetail) == false)
                                            {
                                                routeDetail = new RouteDetail();
                                                routeDetail.Routes[element.WspEvent.InRouterName] = DateTime.UtcNow.AddMinutes(subscriptionManagement.ExpirationIncrement);

                                                generalSubscriptions[subscriptionEvent.SubscriptionEventType] = routeDetail;

                                                subscriptionEntries.Increment();

                                                FilterSummary filterSummary;

                                                if (filteredSubscriptions.TryGetValue(subscriptionEvent.SubscriptionEventType, out filterSummary) == true)
                                                {
                                                    foreach (string filter in filterSummary.Filters.Keys)
                                                    {
                                                        if (filterSummary.Filters[filter].UniqueRoutes.Routes.ContainsKey(element.WspEvent.InRouterName) == true)
                                                        {
                                                            filterSummary.Filters[filter].GlobalRoutes.Routes[element.WspEvent.InRouterName] =
                                                                filterSummary.Filters[filter].UniqueRoutes.Routes[element.WspEvent.InRouterName];

                                                            filterSummary.Filters[filter].UniqueRoutes.Routes.Remove(element.WspEvent.InRouterName);
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                routeDetail.Routes[element.WspEvent.InRouterName] = DateTime.UtcNow.AddMinutes(subscriptionManagement.ExpirationIncrement);
                                            }
                                        }
                                        else
                                        {
                                            FilterSummary filterSummary;
                                            FilterDetail  filterDetail;

                                            if (filteredSubscriptions.TryGetValue(subscriptionEvent.SubscriptionEventType, out filterSummary) == false)
                                            {
                                                filterSummary = new FilterSummary();
                                                filterDetail  = new FilterDetail();
                                                filterSummary.Filters[subscriptionEvent.MethodBody] = filterDetail;

                                                CompilerResults results;

                                                if (WspEventObservable.CompileFilterMethod(subscriptionEvent.MethodBody, subscriptionEvent.UsingLibraries,
                                                                                           subscriptionEvent.ReferencedAssemblies, out filterDetail.filterMethod, out results) == false)
                                                {
                                                    continue;
                                                }

                                                filterDetail.subscription = subscriptionEvent;

                                                subscriptionEntries.Increment();

                                                filteredSubscriptions[subscriptionEvent.SubscriptionEventType] = filterSummary;
                                            }
                                            else
                                            {
                                                if (filterSummary.Filters.TryGetValue(subscriptionEvent.MethodBody, out filterDetail) == false)
                                                {
                                                    filterDetail = new FilterDetail();

                                                    CompilerResults results;

                                                    if (WspEventObservable.CompileFilterMethod(subscriptionEvent.MethodBody, subscriptionEvent.UsingLibraries,
                                                                                               subscriptionEvent.ReferencedAssemblies, out filterDetail.filterMethod, out results) == false)
                                                    {
                                                        continue;
                                                    }

                                                    filterDetail.subscription = subscriptionEvent;

                                                    subscriptionEntries.Increment();

                                                    filterSummary.Filters[subscriptionEvent.MethodBody] = filterDetail;
                                                }
                                            }

                                            if (generalSubscriptions.ContainsKey(subscriptionEvent.SubscriptionEventType) == true)
                                            {
                                                filterDetail.GlobalRoutes.Routes[element.WspEvent.InRouterName] =
                                                    DateTime.UtcNow.AddMinutes(subscriptionManagement.ExpirationIncrement);
                                            }
                                            else
                                            {
                                                filterDetail.UniqueRoutes.Routes[element.WspEvent.InRouterName] =
                                                    DateTime.UtcNow.AddMinutes(subscriptionManagement.ExpirationIncrement);
                                            }
                                        }
                                    }

                                    forwarderQueue.Enqueue(element);
                                }
                            }
                        }

                        if (subscriptionEntries.RawValue > 0 && DateTime.UtcNow > nextTimeout)
                        {
                            lock (subscriptionsLock)
                            {
                                RemoveExpiredEntries();
                            }

                            nextTimeout = DateTime.UtcNow.AddMinutes(subscriptionManagement.ExpirationIncrement);
                        }
                    }
                }
                catch
                {
                    // intentionally left blank
                }
            }
Ejemplo n.º 26
0
 public void InsertRoute(RouteDetail route)
 {
     context.RouteDetails.Add(route);
     context.SaveChanges();
 }
Ejemplo n.º 27
0
        public static void RouteDatachecker(MESPubLab.MESStation.MESStationBase Station, MESPubLab.MESStation.MESStationInput Input, List <MESDataObject.Module.R_Station_Action_Para> Paras)
        {
            string       ErrMessage = "";
            List <R_MRB> GetMRBList = new List <R_MRB>();
            R_MRB        New_R_MRB  = new R_MRB();
            T_R_MRB      TR_MRB     = new T_R_MRB(Station.SFCDB, Station.DBType);

            if (Paras.Count != 3)
            {
                throw new Exception("參數數量不正確!");
            }
            MESStationSession SnSession = Station.StationSession.Find(t => t.MESDataType == Paras[0].SESSION_TYPE && t.SessionKey == Paras[0].SESSION_KEY);

            if (SnSession == null)
            {
                ErrMessage = MESReturnMessage.GetMESReturnMessage("MES00000052", new string[] { Paras[0].SESSION_TYPE + Paras[0].SESSION_KEY });
                throw new MESReturnMessage(ErrMessage);
            }
            else if (SnSession.Value == null)
            {
                ErrMessage = MESReturnMessage.GetMESReturnMessage("MES00000052", new string[] { Paras[0].VALUE + Paras[0].SESSION_KEY });
                throw new MESReturnMessage(ErrMessage);
            }
            SN ObjSn = (SN)SnSession.Value;

            MESStationSession WoSession = Station.StationSession.Find(t => t.MESDataType == Paras[1].SESSION_TYPE && t.SessionKey == Paras[1].SESSION_KEY);

            if (WoSession == null)
            {
                ErrMessage = MESReturnMessage.GetMESReturnMessage("MES00000052", new string[] { Paras[1].SESSION_TYPE + Paras[1].SESSION_KEY });
                throw new MESReturnMessage(ErrMessage);
            }
            WorkOrder ObjWo = (WorkOrder)WoSession.Value;

            MESStationSession StationSession = Station.StationSession.Find(t => t.MESDataType == Paras[2].SESSION_TYPE && t.SessionKey == Paras[2].SESSION_KEY);

            if (StationSession == null)
            {
                ErrMessage = MESReturnMessage.GetMESReturnMessage("MES00000052", new string[] { Paras[2].SESSION_TYPE + Paras[2].SESSION_KEY });
                throw new MESReturnMessage(ErrMessage);
            }
            else if (StationSession.Value == null)
            {
                ErrMessage = MESReturnMessage.GetMESReturnMessage("MES00000052", new string[] { Paras[2].VALUE + Paras[2].SESSION_KEY });
                throw new MESReturnMessage(ErrMessage);
            }

            string NextStation = StationSession.Value.ToString();

            try
            {
                GetMRBList = TR_MRB.GetMrbInformationBySN(ObjSn.SerialNo, Station.SFCDB);

                if (GetMRBList == null || GetMRBList.Count == 0)
                {
                    ErrMessage = MESReturnMessage.GetMESReturnMessage("MES00000045", new string[] { "R_MRB:" + ObjSn.SerialNo });
                    throw new MESReturnMessage(ErrMessage);
                }
                //MESStationInput I = Station.Inputs.Find(t => t.DisplayName == "StationName");
                //List<object> snStationList = I.DataForUse;
                //snStationList.Clear();
                //snStationList.Add(""); ///BY SDL  加載頁面默認賦予空值,操作員必須點選其他有內容選項

                Route routeDetail = new Route(ObjWo.RouteID, GetRouteType.ROUTEID, Station.SFCDB, MESDataObject.DB_TYPE_ENUM.Oracle);
                List <RouteDetail> routeDetailList = routeDetail.DETAIL;
                RouteDetail        h = routeDetailList.Find(t => t.STATION_NAME == GetMRBList[0].NEXT_STATION || t.STATION_TYPE == GetMRBList[0].NEXT_STATION);
                if (h == null)   //R_MRB next_station欄位的值
                {
                    ErrMessage = MESReturnMessage.GetMESReturnMessage("MES00000205", new string[] { ObjSn.SerialNo, ObjWo.WorkorderNo });
                    throw new MESReturnMessage(ErrMessage);
                }

                RouteDetail g = routeDetailList.Find(t => t.STATION_NAME == NextStation);
                if (g == null)  //REWORK選擇的要打回工站
                {
                    ErrMessage = MESReturnMessage.GetMESReturnMessage("MES00000052", new string[] { NextStation });
                    throw new MESReturnMessage(ErrMessage);
                }

                if (g.SEQ_NO > h.SEQ_NO)
                {
                    ErrMessage = MESReturnMessage.GetMESReturnMessage("MES00000211", new string[] {  });
                    throw new MESReturnMessage(ErrMessage);
                }


                Station.AddMessage("MES00000026", new string[] {  }, MESPubLab.MESStation.MESReturnView.Station.StationMessageState.Pass);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public MainWindow()
        {
            InitializeComponent();

            bool IsMySQLDB = true;

            DataSet busDataSet      = AccessEngine.Get("SELECT DISTINCT(bus_id) FROM [IntervalData2014-2015]");
            DataSet intervalDataSet = AccessEngine.Get("SELECT * FROM [IntervalData2014-2015]");
            DataSet routeDataSet    = AccessEngine.Get("SELECT * FROM [Route ID]");
            DataSet stopDataSet     = AccessEngine.Get("SELECT * FROM [Stop ID]");
            DataSet weatherDataSet  = AccessEngine.Get("SELECT * FROM [Weather Data]");

            List <Bus> buses = new List <Bus>();

            foreach (DataRow row in busDataSet.Tables[0].Rows)
            {
                Bus bus = new Bus();
                bus.ID          = SQLUtil.ParseID(row[0]);
                bus.Description = string.Empty;
                buses.Add(bus);
            }

            List <Route> routes = new List <Route>();

            foreach (DataRow row in routeDataSet.Tables[0].Rows)
            {
                Route route = new Route();
                route.ID = SQLUtil.ParseID(row["ID"]);
                string   info      = SQLUtil.ParseString(row["Route ID"]);
                string[] infoArray = info.Split(' ');
                if (infoArray.Length > 1 && infoArray[0].Length == 1)
                {
                    route.Name = infoArray[0];
                }
                else
                {
                    route.Name = info;
                }

                route.RouteDetail = info;

                if (route.RouteDetail.Contains("M-R"))
                {
                    route.IsMtoR = true;
                }
                else
                {
                    route.IsMtoR = false;
                }

                routes.Add(route);
            }

            List <RouteDetail> routeDetails = new List <RouteDetail>();
            List <string>      lines        = new List <string>();

            //Build each route.
            lines = CSVUtil.ReadCSV("A.csv");
            int ARouteID = routes.First(o => o.Name == lines[0].Substring(0, 1) && o.IsMtoR == true).ID.Value;

            for (int i = 2; i < lines.Count; i++) // Line 0 is route name and Line 1 is header
            {
                string[]    line = lines[i].Split(',');
                RouteDetail rd   = new RouteDetail();
                rd.RouteID       = ARouteID;
                rd.Sequence      = i - 1;
                rd.FromBusStopID = int.Parse(line[0]);
                rd.ToBusStopID   = int.Parse(line[1]);
                if (rd.FromBusStopID == rd.ToBusStopID)
                {
                    rd.IsStationary = true;
                }
                else
                {
                    rd.IsStationary = false;
                }

                rd.Distance            = double.Parse(line[2]);
                rd.IdealTravelTime     = int.Parse(line[3]);
                rd.ScheduledTravelTime = int.Parse(line[3]);
                if (rd.IsStationary)
                {
                    rd.ScheduledStopTime = int.Parse(line[3]);
                }

                routeDetails.Add(rd);
            }

            lines.Clear();
            lines = CSVUtil.ReadCSV("B.csv");
            int BRouteID = routes.First(o => o.Name == lines[0].Substring(0, 1) && o.IsMtoR == true).ID.Value;

            for (int i = 2; i < lines.Count; i++) // Line 0 is route name and Line 1 is header
            {
                string[]    line = lines[i].Split(',');
                RouteDetail rd   = new RouteDetail();
                rd.RouteID       = BRouteID;
                rd.Sequence      = i - 1;
                rd.FromBusStopID = int.Parse(line[0]);
                rd.ToBusStopID   = int.Parse(line[1]);
                if (rd.FromBusStopID == rd.ToBusStopID)
                {
                    rd.IsStationary = true;
                }
                else
                {
                    rd.IsStationary = false;
                }

                rd.Distance            = double.Parse(line[2]);
                rd.IdealTravelTime     = int.Parse(line[3]);
                rd.ScheduledTravelTime = int.Parse(line[3]);
                if (rd.IsStationary)
                {
                    rd.ScheduledStopTime = int.Parse(line[3]);
                }

                routeDetails.Add(rd);
            }

            lines.Clear();
            lines = CSVUtil.ReadCSV("E.csv");
            int ERouteID = routes.First(o => o.Name == lines[0].Substring(0, 1) && o.IsMtoR == true).ID.Value;

            for (int i = 2; i < lines.Count; i++) // Line 0 is route name and Line 1 is header
            {
                string[]    line = lines[i].Split(',');
                RouteDetail rd   = new RouteDetail();
                rd.RouteID       = ERouteID;
                rd.Sequence      = i - 1;
                rd.FromBusStopID = int.Parse(line[0]);
                rd.ToBusStopID   = int.Parse(line[1]);
                if (rd.FromBusStopID == rd.ToBusStopID)
                {
                    rd.IsStationary = true;
                }
                else
                {
                    rd.IsStationary = false;
                }

                rd.Distance            = double.Parse(line[2]);
                rd.IdealTravelTime     = int.Parse(line[3]);
                rd.ScheduledTravelTime = int.Parse(line[3]);
                if (rd.IsStationary)
                {
                    rd.ScheduledStopTime = int.Parse(line[3]);
                }

                routeDetails.Add(rd);
            }

            lines.Clear();
            lines = CSVUtil.ReadCSV("X.csv");
            int XRouteID = routes.First(o => o.Name == lines[0].Substring(0, 1) && o.IsMtoR == true).ID.Value;

            for (int i = 2; i < lines.Count; i++) // Line 0 is route name and Line 1 is header
            {
                string[]    line = lines[i].Split(',');
                RouteDetail rd   = new RouteDetail();
                rd.RouteID       = ERouteID;
                rd.Sequence      = i - 1;
                rd.FromBusStopID = int.Parse(line[0]);
                rd.ToBusStopID   = int.Parse(line[1]);
                if (rd.FromBusStopID == rd.ToBusStopID)
                {
                    rd.IsStationary = true;
                }
                else
                {
                    rd.IsStationary = false;
                }

                rd.Distance            = double.Parse(line[2]);
                rd.IdealTravelTime     = int.Parse(line[3]);
                rd.ScheduledTravelTime = int.Parse(line[3]);
                if (rd.IsStationary)
                {
                    rd.ScheduledStopTime = int.Parse(line[3]);
                }

                routeDetails.Add(rd);
            }

            List <BusStop> busStops = new List <BusStop>();

            //foreach (DataRow row in stopDataSet.Tables[0].Rows)
            //{
            //    BusStop busStop = new BusStop();
            //    busStop.ID = SQLUtil.ParseID(row["ID"]);
            //    busStop.Name = SQLUtil.ParseString(row["Stop"]);
            //    busStop.IsMajorStop = false;

            //    busStops.Add(busStop);
            //}

            lines.Clear();
            lines = CSVUtil.ReadCSV("Combined GPS Data.csv");
            for (int i = 1; i < lines.Count; i++) // Line 0 is header
            {
                string[] line    = lines[i].Split(',');
                BusStop  busStop = new BusStop();
                busStop.ID        = int.Parse(line[0]);
                busStop.Name      = line[1];
                busStop.Latitude  = double.Parse(line[2]);
                busStop.Longitude = double.Parse(line[3]);
                busStop.Buddy     = line[4];
                if (line[5].ToLower() == "yes")
                {
                    busStop.Visible = true;
                }
                else
                {
                    busStop.Visible = false;
                }

                if (line[6].ToLower() == "yes")
                {
                    busStop.Announce = true;
                }
                else
                {
                    busStop.Announce = false;
                }

                busStops.Add(busStop);
            }


            List <Weather> weathers = new List <Weather>();

            foreach (DataRow row in weatherDataSet.Tables[0].Rows)
            {
                Weather weather = new Weather();
                weather.ID            = SQLUtil.ParseID(row["ID"]);
                weather.Date          = SQLUtil.ParseDateTime(row["EDT"]);
                weather.MinTemp       = SQLUtil.ParseInt(row["MinTemp"]);
                weather.Precipitation = SQLUtil.ParseString(row["Precipitation"]);
                weather.Events        = SQLUtil.ParseString(row["Events"]);

                weathers.Add(weather);
            }

            List <Interval> intervals = new List <Interval>();

            foreach (DataRow row in intervalDataSet.Tables[0].Rows)
            {
                Interval interval = new Interval();
                //interval.ID = SQLUtil.ParseID(row["ID1"]);
                interval.BusID = SQLUtil.ParseInt(row["bus_id"]);
                string routeName = SQLUtil.ParseString(row["route_id"]);
                if (routeName == "354")
                {
                    routeName = "A";
                }
                interval.RouteObj      = routes.First(o => o.Name == routeName && o.IsMtoR == true);
                interval.FromBusStopID = SQLUtil.ParseInt(row["from"]);
                string toBusStop = SQLUtil.ParseString(row["to"]);
                interval.ToBusStopID = busStops.First(o => o.Name.ToLower().Contains(toBusStop.ToLower())).ID.Value;

                if (interval.FromBusStopID == interval.ToBusStopID)
                {
                    interval.IsStationary = true;
                }
                else
                {
                    interval.IsStationary = false;
                }

                interval.TimeInterval = SQLUtil.ParseInt(row["time"]);
                interval.Timestamp    = SQLUtil.ParseDateTime(row["when"]);

                Weather temp = weathers.FirstOrDefault(o => o.DateString == interval.Timestamp.ToShortDateString());
                if (temp != null)
                {
                    interval.MinTemp       = temp.MinTemp;
                    interval.Precipitation = temp.Precipitation;
                    interval.Events        = temp.Events;
                }

                intervals.Add(interval);
            }

            DataTable rdDataTable;

            if (IsMySQLDB)
            {
                MySQLEngine.OpenDBConnection();
                MySqlCommand myCmd = new MySqlCommand();

                foreach (Bus bus in buses)
                {
                    myCmd.CommandText = "INSERT INTO TBL_Bus(ID, Description) VALUES (" + bus.ID + ", '" + bus.Description + "')";

                    MySQLEngine.ExecuteCommandText(myCmd);
                }

                foreach (Bus bus in buses)
                {
                    myCmd.CommandText = "INSERT INTO TBL_Bus(ID, Description) VALUES (" + bus.ID + ", '" + bus.Description + "')";

                    MySQLEngine.ExecuteCommandText(myCmd);
                }

                foreach (BusStop busStop in busStops)
                {
                    myCmd.CommandText = "INSERT INTO TBL_BusStop(ID, Name, IsMajorStop, Latitude, Longitude, Buddy, Visible, Announce) VALUES ("
                                        + busStop.ID + ", '" + busStop.Name.Replace("'", "''") + "', '" + busStop.IsMajorStop + "', "
                                        + busStop.Latitude + ", " + busStop.Longitude + ", '" + busStop.Buddy + "', '"
                                        + busStop.Visible + "', '" + busStop.Announce + "')";

                    MySQLEngine.ExecuteCommandText(myCmd);
                }

                foreach (Route route in routes)
                {
                    myCmd.CommandText = "INSERT INTO TBL_Route(ID, Name, RouteDetail, IsMtoR) VALUES (" + route.ID + ", '"
                                        + route.Name + "', '" + route.RouteDetail + "', '" + route.IsMtoR.ToString() + "')";

                    MySQLEngine.ExecuteCommandText(myCmd);
                }

                foreach (RouteDetail rd in routeDetails)
                {
                    myCmd.CommandText = "INSERT INTO TBL_RouteDetail(RouteID, Sequence, FromBusStopID, ToBusStopID, IsStationary, "
                                        + "Distance, IdealTravelTime, ScheduleStopTime, ScheduleTravelTime) VALUES ("
                                        + rd.RouteID + ", " + rd.Sequence + ", " + rd.FromBusStopID + ", " + rd.ToBusStopID
                                        + ", '" + rd.IsStationary + "', " + rd.Distance + ", " + rd.IdealTravelTime
                                        + ", " + rd.ScheduledStopTime + ", " + rd.ScheduledTravelTime + ")";

                    MySQLEngine.ExecuteCommandText(myCmd);
                    myCmd.CommandText = "SELECT MAX(ID) FROM TBL_RouteDetail";
                    rdDataTable       = MySQLEngine.GetDataTableCommandText(myCmd);
                    rd.ID             = SQLUtil.ParseID(rdDataTable.Rows[0][0]);
                }

                foreach (Interval interval in intervals)
                {
                    interval.RouteDetailObj = routeDetails.FirstOrDefault(o => o.FromBusStopID == interval.FromBusStopID &&
                                                                          o.ToBusStopID == interval.ToBusStopID && o.RouteID == interval.RouteID);
                    myCmd.CommandText = "INSERT INTO TBL_Interval(BusID, RouteID, RouteDetailID, FromBusStopID, ToBusStopID, "
                                        + "IsStationary, TimeInterval, Timestamp, Day, MinTemp, Precipitation, Events) VALUES ("
                                        + interval.BusID + ", " + interval.RouteID + ", " + interval.RouteDetailID + ", "
                                        + interval.FromBusStopID + ", " + interval.ToBusStopID + ", '" + interval.IsStationary + "', "
                                        + interval.TimeInterval + ", '" + interval.Timestamp.ToString() + "', '" + interval.Day + "', "
                                        + interval.MinTemp + ", '" + interval.Precipitation + "', '" + interval.Events + "')";
                    MySQLEngine.ExecuteCommandText(myCmd);
                }

                MySQLEngine.CloseDBConnection();
            }
            else
            {
                SQLEngine.OpenDBConnection();
                SqlCommand cmd = new SqlCommand();

                foreach (Bus bus in buses)
                {
                    cmd.CommandText = "INSERT INTO TBL_Bus(ID, Description) VALUES (" + bus.ID + ", '" + bus.Description + "')";

                    SQLEngine.ExecuteCommandText(cmd);
                }

                foreach (Bus bus in buses)
                {
                    cmd.CommandText = "INSERT INTO TBL_Bus(ID, Description) VALUES (" + bus.ID + ", '" + bus.Description + "')";

                    SQLEngine.ExecuteCommandText(cmd);
                }

                foreach (BusStop busStop in busStops)
                {
                    cmd.CommandText = "INSERT INTO TBL_BusStop(ID, Name, IsMajorStop, Latitude, Longitude, Buddy, Visible, Announce) VALUES ("
                                      + busStop.ID + ", '" + busStop.Name.Replace("'", "''") + "', '" + busStop.IsMajorStop + "', "
                                      + busStop.Latitude + ", " + busStop.Longitude + ", '" + busStop.Buddy + "', '"
                                      + busStop.Visible + "', '" + busStop.Announce + "')";

                    SQLEngine.ExecuteCommandText(cmd);
                }

                foreach (Route route in routes)
                {
                    cmd.CommandText = "INSERT INTO TBL_Route(ID, Name, RouteDetail, IsMtoR) VALUES (" + route.ID + ", '"
                                      + route.Name + "', '" + route.RouteDetail + "', '" + route.IsMtoR.ToString() + "')";

                    SQLEngine.ExecuteCommandText(cmd);
                }

                foreach (RouteDetail rd in routeDetails)
                {
                    cmd.CommandText = "INSERT INTO TBL_RouteDetail(RouteID, Sequence, FromBusStopID, ToBusStopID, IsStationary, "
                                      + "Distance, IdealTravelTime, ScheduleStopTime, ScheduleTravelTime) VALUES ("
                                      + rd.RouteID + ", " + rd.Sequence + ", " + rd.FromBusStopID + ", " + rd.ToBusStopID
                                      + ", '" + rd.IsStationary + "', " + rd.Distance + ", " + rd.IdealTravelTime
                                      + ", " + rd.ScheduledStopTime + ", " + rd.ScheduledTravelTime + ")";

                    SQLEngine.ExecuteCommandText(cmd);
                    cmd.CommandText = "SELECT MAX(ID) FROM TBL_RouteDetail";
                    rdDataTable     = SQLEngine.GetDataTableCommandText(cmd);
                    rd.ID           = SQLUtil.ParseID(rdDataTable.Rows[0][0]);
                }

                foreach (Interval interval in intervals)
                {
                    interval.RouteDetailObj = routeDetails.FirstOrDefault(o => o.FromBusStopID == interval.FromBusStopID &&
                                                                          o.ToBusStopID == interval.ToBusStopID && o.RouteID == interval.RouteID);
                    cmd.CommandText = "INSERT INTO TBL_Interval(BusID, RouteID, RouteDetailID, FromBusStopID, ToBusStopID, "
                                      + "IsStationary, TimeInterval, Timestamp, Day, MinTemp, Precipitation, Events) VALUES ("
                                      + interval.BusID + ", " + interval.RouteID + ", " + interval.RouteDetailID + ", "
                                      + interval.FromBusStopID + ", " + interval.ToBusStopID + ", '" + interval.IsStationary + "', "
                                      + interval.TimeInterval + ", '" + interval.Timestamp.ToString() + "', '" + interval.Day + "', "
                                      + interval.MinTemp + ", '" + interval.Precipitation + "', '" + interval.Events + "')";
                    SQLEngine.ExecuteCommandText(cmd);
                }

                SQLEngine.CloseDBConnection();
            }
        }