public bool checkAndUpdateVhEntryCycleRunAdr(string vh_id, string adr_id)
        {
            bool             isCyclingAdr    = false;
            ACYCLEZONEMASTER cycleZoneMaster = null;
            ALINE            line            = scApp.getEQObjCacheManager().getLine();
            AVEHICLE         vh = scApp.VehicleBLL.getVehicleByID(vh_id);

            if (!SCUtility.isEmpty(vh.CYCLERUN_ID) &&
                !vh.IS_CYCLING)
            {
                //DBConnection_EF con = DBConnection_EF.GetContext();
                //using (DBConnection_EF con = new DBConnection_EF())
                using (DBConnection_EF con = DBConnection_EF.GetUContext())
                {
                    cycleZoneMaster = cycleZoneMasterDao.getByEntryAdr(con, adr_id);
                    if (cycleZoneMaster == null)
                    {
                        return(false);
                    }
                    if (SCUtility.isMatche(vh.CYCLERUN_ID, cycleZoneMaster.CYCLE_ZONE_ID))
                    {
                        scApp.VehicleBLL.setVhIsInCycleRun(vh_id); //TODO 討論移到144判斷
                        isCyclingAdr = true;
                    }
                }
            }

            return(isCyclingAdr);
        }
        public List <ACYCLEZONEMASTER> loadByCycleTypeIDAndHasCycleSpace(DBConnection_EF con, String _cycle_type_id)
        {
            List <ACYCLEZONEMASTER> HasCycleSpaceZoneMaster = null;;

            var query = from zone_master in con.ACYCLEZONEMASTER
                        join vehicle in con.AVEHICLE
                        on zone_master.CYCLE_ZONE_ID equals vehicle.CYCLERUN_ID into VH_CycleMaters
                        from VH_CycleMater in VH_CycleMaters.DefaultIfEmpty()
                        where zone_master.CYCLE_TYPE_ID == _cycle_type_id.Trim() &&
                        (VH_CycleMater.CYCLERUN_ID == null || VH_CycleMater.CYCLERUN_ID == "")
                        group zone_master by zone_master.CYCLE_ZONE_ID;

            foreach (var q in query)
            {
                ACYCLEZONEMASTER masterTemp = q.First();
                if (q.Count() < masterTemp.TOTAL_BORDER)
                {
                    if (HasCycleSpaceZoneMaster == null)
                    {
                        HasCycleSpaceZoneMaster = new List <ACYCLEZONEMASTER>();
                    }
                    HasCycleSpaceZoneMaster.Add(masterTemp);
                }
            }
            return(HasCycleSpaceZoneMaster);
        }
        public ACYCLEZONEMASTER getCycleZoneMasterByZoneID(string cyc_zone_id)
        {
            ACYCLEZONEMASTER parkZoneMaster = null;

            using (DBConnection_EF con = new DBConnection_EF())
            {
                parkZoneMaster = cycleZoneMasterDao.getByID(con, cyc_zone_id);
            }
            return(parkZoneMaster);
        }
        public ACYCLEZONEMASTER getCycleZoneMaterByEntryAdr(string entry_adr)
        {
            ACYCLEZONEMASTER cyc_zone_master = null;

            //using (DBConnection_EF con = new DBConnection_EF())
            using (DBConnection_EF con = DBConnection_EF.GetUContext())
            {
                cyc_zone_master = cycleZoneMasterDao.getByEntryAdr(con, entry_adr);
            }
            return(cyc_zone_master);
        }
        public bool tryFindCycleZone(AVEHICLE vh, out ACYCLEZONEMASTER bestCycleZone)
        {
            bestCycleZone = null;
            bool isFind = false;

            //DBConnection_EF con = DBConnection_EF.GetContext();
            //using (DBConnection_EF con = new DBConnection_EF())
            using (DBConnection_EF con = DBConnection_EF.GetUContext())
            {
                //List<ACYCLEZONEMASTER> HasCycleSpaceZoneMaster = cycleZoneMasterDao.loadByCycleTypeIDAndHasCycleSpace
                //    (con, scApp.getEQObjCacheManager().getLine().Currnet_Cycle_Type);
                List <ACYCLEZONEMASTER> HasCycleSpaceZoneMaster = loadByCycleTypeIDAndHasCycleSpace
                                                                      (scApp.getEQObjCacheManager().getLine().Currnet_Cycle_Type);
                if (HasCycleSpaceZoneMaster != null)
                {
                    List <KeyValuePair <ACYCLEZONEMASTER, double> > lstCycleZoneMasterAndDis =
                        new List <KeyValuePair <ACYCLEZONEMASTER, double> >();

                    foreach (ACYCLEZONEMASTER park_zone_master in HasCycleSpaceZoneMaster)
                    {
                        //string[] ReutrnFromAdr2ToAdr = scApp.RouteGuide.DownstreamSearchRoute
                        string[] ReutrnFromAdr2ToAdr = scApp.RouteGuide.DownstreamSearchSection
                                                           (vh.NODE_ADR, park_zone_master.ENTRY_ADR_ID, 1);
                        string[] minRoute_From2To = ReutrnFromAdr2ToAdr[0].Split('=');

                        double distance = 0;
                        if (double.TryParse(minRoute_From2To[1], out distance))
                        {
                            lstCycleZoneMasterAndDis.Add
                                (new KeyValuePair <ACYCLEZONEMASTER, double>(park_zone_master, distance));
                        }
                        else
                        {
                            lstCycleZoneMasterAndDis.Add
                                (new KeyValuePair <ACYCLEZONEMASTER, double>(park_zone_master, double.MaxValue));
                        }
                    }
                    if (lstCycleZoneMasterAndDis.Count > 0)
                    {
                        bestCycleZone = lstCycleZoneMasterAndDis.OrderBy(o => o.Value).First().Key;
                        isFind        = true;
                    }
                }
            }
            return(isFind);
        }
 public void add(DBConnection_EF con, ACYCLEZONEMASTER cyc_zone_master)
 {
     con.ACYCLEZONEMASTER.Add(cyc_zone_master);
     con.SaveChanges();
 }