Ejemplo n.º 1
0
 public static void PopulateDayTypeProperties(DayType dt, ResourceDescription rd)
 {
     if ((dt != null) && (rd != null))
     {
         IES1Converter.PopulateIdentifiedObjectProperties(dt, rd);
     }
 }
Ejemplo n.º 2
0
        public double GenerateDayType()
        {
            day_type = DayType.Poor;

            double N          = rand.NextDouble();
            double cumulative = 0;

            cumulative += P_Days[0];
            if (N <= cumulative)
            {
                day_type = DayType.Good;
                return(N);
            }

            cumulative += P_Days[1];
            if (N <= cumulative)
            {
                day_type = DayType.Fair;
                return(N);
            }

            cumulative += P_Days[2];
            if (N <= cumulative)
            {
                day_type = DayType.Poor;
                return(N);
            }

            return(N);
        }
Ejemplo n.º 3
0
        public List <(DateTime, DayType, TimeSpan)> Get_DayTypeInYear(int year)
        {
            List <(DateTime, DayType, TimeSpan)> list1 = new List <(DateTime, DayType, TimeSpan)>();
            List <List <string> > list2 = GetAllRowFromTable("holi");

            list2.ForEach(x =>
            {
                DateTime day    = new DateTime(Convert.ToInt64(x[0])).ToLocalTime();
                TimeSpan ts     = new TimeSpan(0, Convert.ToInt32(x[2]), 0);
                DayType dayType = new DayType();
                if (Convert.ToInt32(x[1]) == 0)
                {
                    dayType = DayType.FreeDay;
                }
                else if (Convert.ToInt32(x[1]) == 1)
                {
                    dayType = DayType.FullDay;
                }
                else if (Convert.ToInt32(x[1]) == 2)
                {
                    dayType = DayType.ShortDay;
                }
                if (day.Year == year)
                {
                    list1.Add((day, dayType, ts));
                }
            });
            return(list1);
        }
Ejemplo n.º 4
0
 private void ClearProperties()
 {
     SDStackPanelVis = false;
     TheSpecialDay   = new SpecialDay();
     TheMonth        = new TimePeriod();
     TheDayType      = new DayType();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Sets the type of the day (used for user input).
        /// </summary>
        /// <param name="date">The date.</param>
        /// <param name="dayType">Type of the day.</param>
        /// /// <returns>Function doesn't return anything, but it saves daytype in user-defined calendar.</returns>
        public static void SetDayType(DateTime date, DayType dayType)
        {
            Day temp = new Day(date, dayType);

            HolidaysCalendar.Add(temp);
            return;
        }
Ejemplo n.º 6
0
 public static Color GetDayTypeForeColor(DayType dayType)
 {
     lock (m_syncRoot) {
         if (dayType.IsWorkDay)
             return Color.Black;
         else if (dayType.IsWeekend)
             return Color.MidnightBlue;
         else if (dayType.IsExecutiveOrder)
             return Color.DarkCyan;
         else if (dayType.IsFlexDay)
             return Color.DarkGreen;
         else if (dayType.IsVacationDay)
             return Color.DarkGoldenrod;
         else if (dayType.IsSickDay)
             return Color.MediumVioletRed;
         else if (dayType.IsHalfDay)
             return ColorTranslator.FromHtml("#666666");
         else if (dayType.IsOther)
             return Color.Indigo;
         else if (dayType.IsNA)
             return Color.Indigo;
         else {
             MessageBox.Show(string.Format("DayTypes.{0} is unhandled in GetDayTypeForeColor(); using default ForeColor.", dayType.Name), "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
             return Color.FromKnownColor(KnownColor.ControlText);
         }
     }
 }
Ejemplo n.º 7
0
        private bool CheckValidation(DayType dt)
        {
            string MessageError = null;

            using (SalDbContext _db = new SalDbContext())
            {
                var checkedwage = _db.DayTypes.FirstOrDefault(p => p.NameDayType == dt.NameDayType);
                if (checkedwage != null)
                {
                    MessageError += "Елемент вже є в базі"; return(false);
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(dt.NameDayType.ToString()))
                    {
                        MessageError += "Поле не може бути пустим";
                    }
                }
            }
            if (string.IsNullOrEmpty(MessageError))
            {
                return(true);
            }
            else
            {
                MessageBox.Show("Mistake {0}", MessageError.ToString());
                return(false);
            }
        }
Ejemplo n.º 8
0
 public IEnumerable <DatesRange> this[DayType dayType]
 {
     get
     {
         return(Ranges.Where(d => d.Key == dayType).SelectMany(d => d.Value));
     }
 }
Ejemplo n.º 9
0
        private DayType calculateDayType(DateTime dt, DayOfWeek dayOfWeek, GermanSpecialDays specialDays, out GermanSpecialDay foundSpecialDay)
        {
            foundSpecialDay = null;
            if (specialDays != null)
            {
                specialDays.TryGetValue(dt, out foundSpecialDay);
            }
            if (foundSpecialDay != null)
            {
                return(DayType.Holiday);
            }

            DayType ret = DayType.Unknown;

            switch (dayOfWeek)
            {
            case DayOfWeek.Monday:
            case DayOfWeek.Tuesday:
            case DayOfWeek.Wednesday:
            case DayOfWeek.Thursday:
            case DayOfWeek.Friday:
                ret = DayType.Working;
                break;

            case DayOfWeek.Saturday:
            case DayOfWeek.Sunday:
                ret = DayType.Weekend;
                break;
            }

            // TODO: more calculations required...
            return(ret);
        }
Ejemplo n.º 10
0
 public Answer this[DayType dayType]
 {
     get
     {
         return(Answers.Where(d => d.DayType == dayType).FirstOrDefault());
     }
 }
Ejemplo n.º 11
0
        public JsonResult DeleteDayType(DayType dayType)
        {
            var          isSuccess = true;
            var          message   = string.Empty;
            const string url       = "/DayType/Index";

            permission = (RoleSubModuleItem)cacheProvider.Get(cacheKey) ?? roleSubModuleItemService.GetRoleSubModuleItemBySubModuleIdandRole(url,
                                                                                                                                             Helpers.UserSession.GetUserFromSession().RoleId);

            if (permission.DeleteOperation == true)
            {
                isSuccess = this.dayTypeService.DeleteDayType(dayType.Id);
                if (isSuccess)
                {
                    message = Resources.ResourceDayType.MsgDayTypeDeleteSuccessful;
                }
                else
                {
                    message = Resources.ResourceDayType.MsgDayTypeDeleteFailed;
                }
            }
            else
            {
                message = Resources.ResourceCommon.MsgNoPermissionToDelete;
            }


            return(Json(new
            {
                isSuccess = isSuccess,
                message = message
            }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 12
0
 public RelativeTimeInterval(int leadDays, DayType dayType, DateTime from, DateTime to)
 {
     this.LeadDays    = leadDays;
     this.LeadDayType = dayType;
     this.From        = from;
     this.To          = to;
 }
Ejemplo n.º 13
0
        /**
         * Switch backward.
         */
        public void SwitchBackward()
        {
            DayType previousDayType;

            switch (currentDayType)
            {
            case DayType.DayAfterTomorrow:
                previousDayType = DayType.Tomorrow;
                break;

            case DayType.Tomorrow:
            case DayType.Today:
            default:
                previousDayType = DayType.Today;
                break;
            }

            // fetch new data if necessary
            if (previousDayType != currentDayType)
            {
                callback(previousDayType);
                currentDayType = previousDayType;
                UpdateButtons();
            }
        }
        public double GenerateDayType()
        {
            day_type = DayType.Poor;

            double N = rand.NextDouble();
            double cumulative = 0;
            cumulative += P_Days[0];
            if (N <= cumulative)
            {
                day_type = DayType.Good;
                return N;
            }

            cumulative += P_Days[1];
            if (N <= cumulative)
            {
                day_type = DayType.Fair;
                return N;
            }

            cumulative += P_Days[2];
            if (N <= cumulative)
            {
                day_type = DayType.Poor;
                return N;
            }

            return N;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Returns the localiztion text of a specified week day type
        /// </summary>
        public static int GetText(DayType dayType)
        {
            switch (dayType)
            {
            case DayType.FirstWorkingDay:
                return(GetText(GetDayByIndex(0)));

            case DayType.LastWorkingDay:
                return(GetText(GetDayByIndex(4)));

            case DayType.FirstWeekendDay:
                return(GetText(FirstWeekendDay));

            case DayType.LastWeekendDay:
                return(GetText(SecondWeekendDay));

            case DayType.WorkingDays:
                return(680);

            case DayType.Record_WorkingDays:
                return(672);

            case DayType.WeekendDays:
                return(1050);

            case DayType.Record_WeekendDays:
                return(1051);

            default:
                return(-1);
            }
        }
Ejemplo n.º 16
0
        public static SelectList ToSelectList(this DayType selectedValueOutput)
        {
            var values = from DayType e in Enum.GetValues(typeof(DayType))
                         select new { Id = (int)e, Name = e.GetDescription() };

            return(new SelectList(values, "Id", "Name", selectedValueOutput));
        }
Ejemplo n.º 17
0
        private void RefreshBackground()
        {
            var now   = DateTime.Now;
            var notes = Notes.Current.Items;

            var dayNotes = notes.Where(a => !a.IsMonthDay &&
                                       MonthDayHelper.IsSameMonthDay(Convert.ToDateTime(a.Date), Day))
                           .Select(a => a.Name).ToList();
            var monthDayNotes = notes.Where(a => a.IsMonthDay &&
                                            MonthDayHelper.IsSameMonthMonthMonthDay(Convert.ToDateTime(a.Date), Day))
                                .Select(a => a.Name);;

            dayNotes.AddRange(monthDayNotes);
            if (dayNotes.Count > 0)
            {
                DayType  = DayType.Note;
                NoteText = string.Join("\r\n", dayNotes);
            }
            else if (Day.Year == now.Year && Day.Month == now.Month && Day.Day == now.Day)
            {
                DayType  = DayType.Today;
                NoteText = "今天";
            }
            else if (Day.Year == AppModel.Current.Year && Day.Month == AppModel.Current.Month)
            {
                DayType = DayType.Normal;
            }
            else
            {
                DayType = DayType.OtherMonth;
            }
        }
Ejemplo n.º 18
0
 public virtual List<LineNameInfo> GetLineIdsFromNumber(int number, DayType daytype)
 {
     var instance = DBModel.GetInstance();
     Dictionary<string, Line> tempLineCollection = instance.Lines.GetDataFromDayType(daytype);
     var temp = (from t in tempLineCollection where t.Value.Number == number select new LineNameInfo { Number = t.Value.Number, Id = t.Key, Name = t.Value.Name }).ToList();
     return temp;
 }
Ejemplo n.º 19
0
 public virtual List<LineNameInfo> GetLinesKeyFromName(string name, DayType daytype)
 {
     var instance = DBModel.GetInstance();
     Dictionary<string, Line> tempLineCollection = instance.Lines.GetDataFromDayType(daytype);
     var temp = (from t in tempLineCollection where t.Value.Name.Contains(name) select new LineNameInfo() { Id = t.Key, Number = t.Value.Number, Name = t.Value.Name }).ToList();
     return temp;
 }
Ejemplo n.º 20
0
        /**
         * Switch forward.
         */
        public void SwitchForward()
        {
            DayType nextDayType;

            switch (currentDayType)
            {
            case DayType.Today:
                nextDayType = DayType.Tomorrow;
                break;

            //case DayType.Tomorrow:
            //case DayType.DayAfterTomorrow:
            default:
                nextDayType = DayType.DayAfterTomorrow;
                break;
            }

            // fetch new data if necessary
            if (nextDayType != currentDayType)
            {
                callback(nextDayType);
                currentDayType = nextDayType;
                UpdateButtons();
            }
        }
Ejemplo n.º 21
0
 public EmployeeTimeModel()
 {
     HourTypes = new Dictionary <string, decimal>();
     for (DayType d = DayType.Workday; d <= DayType.Other; d++)
     {
         HourTypes.Add(d.ToString(), 0);
     }
 }
        public HourAndMinuteGridView(Dictionary <int, List <int> > minuteDictionary, DayType dayType)
        {
            InitializeComponent();

            var vb = new ViewBuilder();

            Content = vb.Build(minuteDictionary, dayType);
        }
Ejemplo n.º 23
0
        private List <CalendarDay> GetDaysByType(DayType dayType)
        {
            var days = new List <CalendarDay>();

            days.AddRange(GetAllDaysCollection <CalendarDay>().Where(calendarDay => calendarDay.Type == dayType));

            return(days);
        }
Ejemplo n.º 24
0
 private void SetAddingProperties()
 {
     TheMonth        = new TimePeriod();
     TheSpecialDay   = new SpecialDay();
     TheDayType      = new DayType();
     SDStackPanelVis = true;
     UpdateSDVis     = false;
 }
Ejemplo n.º 25
0
        private static DayTypeModel PrepareDayTypeModel(DayType dayType)
        {
            DayTypeModel dayTypeTemp = new DayTypeModel();

            dayTypeTemp.Id      = dayType.Id;
            dayTypeTemp.DayType = dayType.DayType1;
            return(dayTypeTemp);
        }
Ejemplo n.º 26
0
        public static void Collect(ExcelWorksheet rawData, UnitOfWork unit)
        {
            Console.Write("Calendar: ");

            DayType workDay = new DayType {
                Name = "workday"
            };
            DayType holiday = new DayType {
                Name = "holiday"
            };
            DayType business = new DayType {
                Name = "business"
            };
            DayType religious = new DayType {
                Name = "religious"
            };
            DayType sick = new DayType {
                Name = "sick"
            };
            DayType vacation = new DayType {
                Name = "vacation"
            };
            DayType other = new DayType {
                Name = "other"
            };

            unit.DayTypes.Insert(workDay);
            unit.DayTypes.Insert(holiday);
            unit.DayTypes.Insert(business);
            unit.DayTypes.Insert(religious);
            unit.DayTypes.Insert(sick);
            unit.DayTypes.Insert(vacation);
            unit.DayTypes.Insert(other);
            unit.Save();

            int N = 0;

            for (int row = 2; row <= rawData.Dimension.Rows; row++)
            {
                int oldId = rawData.ReadInteger(row, 1);
                Day d     = new Day
                {
                    Employee = unit.Employees.Get(Utility.dicEmpl[rawData.ReadInteger(row, 2)]),
                    DayType  = unit.DayTypes.Get(rawData.ReadInteger(row, 3)),
                    Date     = rawData.ReadDate(row, 4)
                };

                unit.Calendar.Insert(d);
                unit.Save();
                Utility.dicDays.Add(oldId, d.Id);
                N++;
                if (N % 100 == 0)
                {
                    Console.Write($"{N}");
                }
            }
            Console.WriteLine(N);
        }
Ejemplo n.º 27
0
        public IEnumerable <ScheduleLine> GetSchedule(string typeOfLine, string typeOfDay, string Number)
        {
            if (typeOfLine == null || typeOfDay == null || Number == null)
            {
                //return BadRequest();
            }

            RouteType type = Enums.RouteType.Town;

            if (typeOfLine == "Town")
            {
                type = Enums.RouteType.Town;
            }
            else if (typeOfLine == "Suburban")
            {
                type = Enums.RouteType.Suburban;
            }

            DayType day = DayType.Workday;

            if (typeOfDay == "Work day")
            {
                day = Enums.DayType.Workday;
            }
            else if (typeOfDay == "Suburban")
            {
                day = Enums.DayType.Weekend;
            }

            List <ScheduleLine> schedule = new List <ScheduleLine>();
            var lines = db.Lines.GetAll();

            foreach (var line in lines)
            {
                if (line.Number == Number)
                {
                    foreach (var dep in line.Schadules)
                    {
                        ScheduleLine sl = new ScheduleLine();
                        sl.Number = line.Number;
                        sl.Time   = DateTime.Parse(dep.DepartureTime);
                        if (dep.Day == DayType.Weekend)
                        {
                            sl.Day = "Weekend";
                        }
                        else if (true)
                        {
                            sl.Day = "Work day";
                        }

                        sl.IDDay = dep.IdSchadule;
                        schedule.Add(sl);
                    }
                }
            }

            return(schedule);
        }
Ejemplo n.º 28
0
    IEnumerator DayRoutin()
    {
        WaitForSeconds waitForSeconds = new WaitForSeconds(0.4f);


        while (true)
        {
            if (dayType == DayType.Morning)
            {
                // daytime -= Time.deltaTime;

                // SeaMorningPanel();
                EnemyMorning();
                if (daytime <= 0)
                {
                    daytime = 300f;
                    dayType = DayType.NightGo;
                }

                yield return(null);
            }
            else if (dayType == DayType.MorningGo)
            {
                daylight.intensity += 0.05f;

                if (daylight.intensity >= 2f)
                {
                    dayType = DayType.Morning;
                }

                yield return(waitForSeconds);
            }
            else if (dayType == DayType.Night)
            {
                // daytime -= Time.deltaTime;
                // SeaNightPanel();
                EnemyNight();
                if (daytime <= 0)
                {
                    daytime = 300f;
                    dayType = DayType.MorningGo;
                }

                yield return(null);
            }
            else if (dayType == DayType.NightGo)
            {
                daylight.intensity -= 0.05f;

                if (daylight.intensity <= 0.5f)
                {
                    dayType = DayType.Night;
                }

                yield return(waitForSeconds);
            }
        }
    }
Ejemplo n.º 29
0
        public void StringContainsDayOffInfoWithDateTime([Values] DayType dayType)
        {
            var dateTime = 04.08.Of(2020);

            var dayOffInfo         = new DayOffDateTime(dateTime, dayType);
            var dayOffInfoAsString = dayOffInfo.ToString();

            Assert.That(dayOffInfoAsString, Is.EqualTo($"{dateTime:d} ({dayType:G})"));
        }
Ejemplo n.º 30
0
 public static DateTypeViewData Create(DayType section)
 {
     return(new DateTypeViewData
     {
         Id = section.Id,
         SchoolYearId = section.SchoolYearRef,
         Name = section.Name,
         Number = section.Number
     });
 }
Ejemplo n.º 31
0
 public ActionResult Edit([Bind(Include = "DayTypeID,DayTypeName,SymbolName,SymbolNameLatin,WorkHours")] DayType dayType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(dayType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(dayType));
 }
Ejemplo n.º 32
0
 public SpecialDayViewModel()
 {
     _specLogic           = new SpecialDayLogic();
     TheSpecialDay        = new SpecialDay();
     TheMonth             = new TimePeriod();
     TheDayType           = new DayType();
     SpecialDayCollection = new ObservableCollection <SpecialDay>(_specLogic.GetSP());
     DayTypeCollection    = new ObservableCollection <DayType>(_specLogic.GetDT());
     PeriodCollection     = new ObservableCollection <TimePeriod>(_specLogic.GetPC());
 }
Ejemplo n.º 33
0
 public Tax
 (
     TaxType taxType,
     DayType dayType,
     decimal value
 )
 {
     TaxType = taxType;
     DayType = dayType;
     Value   = value;
 }
Ejemplo n.º 34
0
        private ListViewItem CreateDayTypesListViewItem(DayType dayType)
        {
            ListViewItem listViewItem = new ListViewItem(dayType.Name);

            listViewItem.ImageIndex = 0;
            listViewItem.SubItems.Add(dayType.Description);

            listViewItem.Tag = dayType;

            return(listViewItem);
        }
Ejemplo n.º 35
0
 public static Color GetDayTypeForeColor(DayType dayType, decimal hours)
 {
     lock (m_syncRoot) {
         if (dayType.IsWorkDay) {
             // If it is a work day and no hours are allotted, this should be flagged.
             return (hours == 0.00m) ? ColorTranslator.FromHtml("#990000") : GetDayTypeForeColor(dayType);
         } else {
             // If it is NOT a work day and hours ARE allotted, this should be flagged.
             return (hours == 0.00m) ? GetDayTypeForeColor(dayType) : ColorTranslator.FromHtml("#990000");
         }
     }
 }
Ejemplo n.º 36
0
 internal static void SetColorByDayType(this DataGridViewCell cell, DayType dayType)
 {
     switch (dayType)
     {
         case DayType.WeekEnd:
             cell.Style.BackColor = CellsPalette.WeekEnd;
             break;
         case DayType.Holiday:
         case DayType.Vacations:
             cell.Style.BackColor = CellsPalette.FreeDay;
             break;
     }
 }
Ejemplo n.º 37
0
        public virtual LineInfoResult GetDetailsData(string id, DayType daytype)
        {
            var instance = DBModel.GetInstance();
            Dictionary<string, Line> tempLineCollection = instance.Lines.GetDataFromDayType(daytype);

            if (!tempLineCollection.ContainsKey(id))
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            var tempLine = tempLineCollection[id];

            var result = new LineInfoResult()
            {
                LineId = id,
                LineNumber = tempLine.Number,
                LineName = tempLine.Name,
                Buses = tempLine.Buses,
                Stations = (from sta in tempLine.Stations let staTemp = instance.Stations[sta] select new StationIdNamePair() { Id = sta, Name = staTemp.Name, Yomi = staTemp.Yomi }).ToList()
            };

            return result;
        }
Ejemplo n.º 38
0
 /// <summary>
 /// Create n-monthly repeating date generator.
 /// </summary>
 /// <param name="wday">Day of week</param>
 /// <param name="week">1=first, 2=second, 3=third, 4=fourth, 5=last</param>
 /// <param name="nMonths">how many months between events</param>
 public MonthlyRelativeGenerator(WDay wday, int week, int nMonths)
 {
     DayId = wday;
     switch (wday)
     {
         case WDay.Any:
             _DayType = DayType.EveryDay;
             break;
         case WDay.WeekDay:
             _DayType = DayType.WeekDay;
             break;
         case WDay.WeekendDay:
             _DayType = DayType.WeekendDay;
             break;
         default:
             _DayType = DayType.Specific;
             _DayOfWeek = (wday == WDay.Sun) ? DayOfWeek.Sunday : (DayOfWeek) (wday - 2);
             break;
     }
     _WeekInMonth = week;
     _M = nMonths;
 }
Ejemplo n.º 39
0
 public Dictionary<string, Line> GetDataFromDayType(DayType dayType)
 {
     switch (dayType)
     {
         case DayType.saturday:
             return this.Saturday;
         case DayType.holiday:
             return this.Holiday;
         default:
             return this.Weekday;
     }
 }
 public static bool HasCurrentDayFlag(DayType type)
 {
     return (type & DayType.CurrentDay) > 0;
 }
Ejemplo n.º 41
0
        public virtual RouteSearchResult SearchRoute(string from, string to, DayType daytype,RouteSeachMethod method = RouteSeachMethod.DepartureBase, string queryTime = null, int count = 5)
        {
            var instance = DBModel.GetInstance();

            // deptがnullなら現在時刻
            TimeSpan baseTime = DateTime.Now.TimeOfDay;
            if (queryTime != null && queryTime != String.Empty)
            {
                baseTime = Commons.ConvertToTimeSpan(queryTime);
                if (baseTime == TimeSpan.Zero)
                {
                    throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest));
                }
            }
            else
            {
                method = RouteSeachMethod.DepartureBase;
            }

            var fromStation = instance.Stations.Where(c => c.Key == from).Select(c => c.Value).SingleOrDefault();
            var toStation = instance.Stations.Where(c => c.Key == to).Select(c => c.Value).SingleOrDefault();

            if (fromStation == null || toStation == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            var result = new RouteSearchResult()
            {
                FromStation = new StationIdNamePair() { Id = from, Name = fromStation.Name, Yomi = fromStation.Yomi },
                ToStation = new StationIdNamePair() { Id = to, Name = toStation.Name, Yomi = toStation.Yomi },
                QueryDayType = daytype,
                QueryMethod = method,
                QueryTime = Commons.ConvertToString(baseTime)
            };

            IEnumerable<Tuple<BusDeptTimeInfo, BusDeptTimeInfo>> tempSource = null;
            if (method == RouteSeachMethod.DepartureBase)
            {
                // 発検索 -> fromの発車時刻がクエリとして与えられた時刻よりも新しい
                tempSource = fromStation.Buses.Where(c => c.DayType == daytype && Commons.ConvertToTimeSpan(c.DeptTime) >= baseTime)
                                    .Join(toStation.Buses, f => f.BusId, t => t.BusId, (f, t) => new Tuple<BusDeptTimeInfo, BusDeptTimeInfo>(f, t));
            }
            else
            {
                // 着検索 -> toの発車時刻がクエリとして与えられた時刻よりも古い
                tempSource = toStation.Buses.Where(c => c.DayType == daytype && Commons.ConvertToTimeSpan(c.DeptTime) <= baseTime)
                    .Join(fromStation.Buses, t => t.BusId, f => f.BusId, (t, f) => new Tuple<BusDeptTimeInfo, BusDeptTimeInfo>(f, t));
            }

            // 発と着の順番を考慮
            var tempRoute = (from busSet in tempSource
                              let bus = instance.Buses[busSet.Item1.BusId]
                              let line = instance.Lines.GetDataFromDayType(daytype)[bus.LineId]
                              where line.Stations.IndexOf(@from) < line.Stations.LastIndexOf(to) select new Tuple<BusDeptTimeInfo,BusDeptTimeInfo,Bus,Line>(busSet.Item1,busSet.Item2, bus, line));
            // -> 最初から見つかったもの と 最後に見つかったものを比較すれば、最低でも行けることは保証(最短かどうかは除いて) *1

            // 提案コスト検索
            IEnumerable<Route> tempResult = null;
            if (method == RouteSeachMethod.DepartureBase)
            {
                tempResult = (from route in tempRoute
                                   let deptTime = Commons.ConvertToTimeSpan(route.Item1.DeptTime)
                                   let arrTime = Commons.ConvertToTimeSpan(route.Item2.DeptTime)
                                   where deptTime <= arrTime // *1の個所では最初と最後をとったが、このDeptInfoが必ず順序が保証されているとは限らない(*1は路線情報で判断)
                                   let costTime = Commons.DiffTimespan(deptTime, arrTime)
                                   orderby costTime descending // 2番目のクエリ:所要時間 (3番目のクエリ:TransferCount)
                                   orderby deptTime ascending  // 1番目のクエリ:到着時間が近い順
                                   let costTimeStr = Commons.ConvertToString(costTime)
                                   select new Route()
                                   {
                                       Pathes = new List<Path>()
                                       {
                                           new Path()
                                           {
                                               DeptNode = new Node() { Station = result.FromStation, Time = route.Item1.DeptTime },
                                               ArrNode = new Node() { Station = result.ToStation, Time = route.Item2.DeptTime },
                                               Method = TransferMethod.Bus,
                                               Line = new LineNameInfo() { Id = route.Item3.LineId, Name = route.Item4.Name, Number = route.Item4.Number },
                                               BusId = route.Item1.BusId,
                                               Time = costTimeStr
                                           }
                                       },
                                       Rank = 1.0,
                                       TotalDeptTime = route.Item1.DeptTime,
                                       TotalArrTime = route.Item2.DeptTime,
                                       TransferCount = 0,
                                       TotalTime = costTimeStr
                                   }).Select((n, ind) =>
                                   {
                                       n.Rank = ind;
                                       return n;
                                   });
            }
            else
            {
                tempResult = (from route in tempRoute
                              let deptTime = Commons.ConvertToTimeSpan(route.Item1.DeptTime)
                              let arrTime = Commons.ConvertToTimeSpan(route.Item2.DeptTime)
                              where deptTime <= arrTime // *1の個所では最初と最後をとったが、このDeptInfoが必ず順序が保証されているとは限らない(*1は路線情報で判断)
                              let costTime = Commons.DiffTimespan(deptTime, arrTime)
                              orderby costTime descending // 2番目のクエリ:所要時間 (3番目のクエリ:TransferCount)
                              orderby deptTime descending  // 1番目のクエリ:到着時間が近い順
                              let costTimeStr = Commons.ConvertToString(costTime)
                              select new Route()
                              {
                                  Pathes = new List<Path>()
                                       {
                                           new Path()
                                           {
                                               DeptNode = new Node() { Station = result.FromStation, Time = route.Item1.DeptTime },
                                               ArrNode = new Node() { Station = result.ToStation, Time = route.Item2.DeptTime },
                                               Method = TransferMethod.Bus,
                                               Line = new LineNameInfo() { Id = route.Item3.LineId, Name = route.Item4.Name, Number = route.Item4.Number },
                                               BusId = route.Item1.BusId,
                                               Time = costTimeStr
                                           }
                                       },
                                  Rank = 1.0,
                                  TotalDeptTime = route.Item1.DeptTime,
                                  TotalArrTime = route.Item2.DeptTime,
                                  TransferCount = 0,
                                  TotalTime = costTimeStr
                              }).Select((n, ind) =>
                              {
                                  n.Rank = ind;
                                  return n;
                              });
            }

            if (count == -1 || count <= 0)
            {
                result.Routes = tempResult.ToList();
            }
            else
            {
                result.Routes = tempResult.Take(count).ToList();
            }

            return result;
        }
Ejemplo n.º 42
0
        public virtual RouteSearchResult SearchRoute(string from, string to, DayType daytype)
        {
            var instance = DBModel.GetInstance();
            var fromStation = instance.Stations.Where(c => c.Key == from).Select(c => c.Value).SingleOrDefault();
            var toStation = instance.Stations.Where(c => c.Key == to).Select(c => c.Value).SingleOrDefault();

            if (fromStation == null || toStation == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            var result = new RouteSearchResult()
            {
                FromStation = new StationIdNamePair() { Id = from, Name = fromStation.Name, Yomi = fromStation.Yomi },
                ToStation = new StationIdNamePair() { Id = to, Name = toStation.Name, Yomi = toStation.Yomi },
                QueryDayType = daytype
            };

            result.Routes = (from busSet in
                                 fromStation.Buses.Where(c => c.DayType == daytype)
                                .Join(toStation.Buses, f => f.BusId, t => t.BusId, (f, t) => new { From = f, To = t })
                             let bus = instance.Buses[busSet.From.BusId]
                             let line = instance.Lines.GetDataFromDayType(daytype)[bus.LineId]
                             where line.Stations.IndexOf(@from) < line.Stations.LastIndexOf(to)
                             let dept = Commons.ConvertToTimeSpan(busSet.From.DeptTime)
                             let arr = Commons.ConvertToTimeSpan(busSet.To.DeptTime)
                             where dept <= arr
                             let time = Commons.ConvertToString(Commons.DiffTimespan(dept, arr))
                             select new Route()
                             {
                                 Pathes = new List<Path>()
                                {
                                    new Path()
                                    {
                                        DeptNode = new Node() { Station = result.FromStation, Time = busSet.From.DeptTime },
                                        ArrNode = new Node() { Station = result.ToStation, Time = busSet.To.DeptTime },
                                        Method = TransferMethod.Bus,
                                        Line = new LineNameInfo() { Id = bus.LineId, Name = line.Name, Number = line.Number },
                                        BusId = busSet.From.BusId,
                                        Time = time
                                    }
                                },
                                 Rank = 1.0,
                                 TotalDeptTime = busSet.From.DeptTime,
                                 TotalArrTime = busSet.To.DeptTime,
                                 TransferCount = 0,
                                 TotalTime = time
                             }).ToList();

            return result;
        }
Ejemplo n.º 43
0
 /// <summary>
 /// Returns the localiztion text of a specified week day type
 /// </summary>
 public static int GetText(DayType dayType)
 {
   switch (dayType)
   {
     case DayType.FirstWorkingDay:
       return GetText(GetDayByIndex(0));
     case DayType.LastWorkingDay:
       return GetText(GetDayByIndex(4));
     case DayType.FirstWeekendDay:
       return GetText(FirstWeekendDay);
     case DayType.LastWeekendDay:
       return GetText(SecondWeekendDay);
     case DayType.WorkingDays:
       return 680;
     case DayType.Record_WorkingDays:
       return 672;
     case DayType.WeekendDays:
       return 1050;
     case DayType.Record_WeekendDays:
       return 1051;
     default:
       return -1;
   }
 }