Пример #1
0
        public async Task <IActionResult> Create(ProductsPlansViewModel productsPlansViewModel)
        {
            DayPlan dayPlans = _context.DayPlans.Where(d => d.Date.Equals(productsPlansViewModel.Date)).FirstOrDefault();

            if (dayPlans == null)
            {
                _context.DayPlans.Add(new DayPlan {
                    Date = productsPlansViewModel.Date
                });
                await _context.SaveChangesAsync();

                dayPlans = _context.DayPlans.Where(d => d.Date.Equals(productsPlansViewModel.Date)).FirstOrDefault();
            }
            ProductsPlan productsPlan = productsPlansViewModel.ProductsPlan;

            productsPlan.DayPlanId = dayPlans.DayPlanId;
            if (ModelState.IsValid)
            {
                _context.Add(productsPlan);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DayPlanId"] = new SelectList(_context.DayPlans, "DayPlanId", "Date");
            ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductName");
            return(View(productsPlan));
        }
Пример #2
0
        public void AddDayPlan(DayPlan dayPlan)
        {
            string newId;

            do
            {
                newId = Guid.NewGuid().ToString("n");
            }while (DayPlans.FirstOrDefault(x => x.Id == newId) != null);

            dayPlan.Id = newId;

            foreach (Activity activity in dayPlan.Activities)
            {
                string newActivityId;
                do
                {
                    newActivityId = Guid.NewGuid().ToString("n");
                }while (dayPlan.Activities.FirstOrDefault(x => x.Id == newActivityId) != null);

                activity.Id = newActivityId;
            }

            InsertInCorrectOrder(dayPlan);

            XmlHelper.SaveDataToFile <DayPlan>(FilePath, this.DayPlans);
        }
Пример #3
0
        public async Task AddDayPlan(DayPlan newDayPlan, string travelIdentity)
        {
            var location = await LocationRepository.GetLocation(travelIdentity);

            var dbDayPlan = DayPlanConverter.ToDbDayPlan(newDayPlan);
            await DayPlanRepository.AddDayPlan(dbDayPlan, travelIdentity, location.LocationId);

            foreach (var day in newDayPlan.Days)
            {
                var dbDay = DayPlanConverter.ToDbItinerary(day);
                await DayPlanRepository.AddItinerary(dbDay, newDayPlan.DayPlanId);

                foreach (var item in day.ItineraryItems)
                {
                    var dbItem = DayPlanConverter.ToDbItineraryItem(item);
                    await DayPlanRepository.AddItineraryItem(dbItem, dbDay.ItineraryId);

                    var poi = PoiConverter.ToDbPoi(item.Poi);
                    await PoiRepository.AddPoiToDayItem(poi, item.ItineraryItemId, location.LocationId);

                    if (item.Poi.Attribution != null)
                    {
                        var attributions = item.Poi.Attribution.Select(a => PoiConverter.ToDbAttribution(a)).ToList();
                        await PoiRepository.AddAttributionToPoi(poi.PoiId, attributions);
                    }
                }
            }
        }
Пример #4
0
 public DayPlan UpdateTo(DayPlan plan)
 {
     plan.ExpectEndAt = this.ExpectEndAt;
     plan.PlanType    = this.PlanType;
     plan.Content     = this.Content;
     plan.LoveOrNot   = this.LoveOrNot;
     return(plan);
 }
    private void GetAlternativeRecipe(DayPlan day)
    {
        day.Recipe = day.Recipe !.Name == day.RecipeAlternatives?.Last().Name
                                                                        ? day.RecipeAlternatives?[0]
                                                                        : day.RecipeAlternatives?.SkipWhile(x => x.Name != day.Recipe.Name).Skip(1).First();

        day.Garnish = day.Recipe !.Garnishes.RandomElement();
    }
    private void GetAlternativeGarnish(DayPlan day)
    {
        DayPlanRecipe?lastGarnish = day.Garnish;

        do
        {
            day.Garnish = day.Recipe !.Garnishes.RandomElement();
        }while (day.Garnish == lastGarnish);
    }
    private async Task SetRecipeManuallyAsync(DayPlan day)
    {
        RecipeSelectViewModel?viewModel = container.Resolve <RecipeSelectViewModel>((typeof(DayPlan), day));
        await dialogService.ShowCustomMessageAsync <RecipeSelectView, RecipeSelectViewModel>(content : viewModel);

        if (viewModel.DialogResultOk)
        {
            day.SpecificRecipe = recipeService.GetMapped <DayPlanRecipe>(viewModel.SelectedRecipe !.ID);
        }
    }
Пример #8
0
 private int GetCoordinatePhaseId(DayPlan plan)
 {
     foreach (Phase p in plan.TimingPlan.split.phases)
     {
         if (p.CoordinatePhase)
         {
             return(p.PhaseId);
         }
     }
     return(0);
 }
Пример #9
0
        private void PlansListGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex != -1 && PlansListGridView.CurrentCell.Value.ToString() != "N/A" && e.ColumnIndex != 0)
            {
                IList <DayPlan> dayPlans = intersection.WholeWeeksDayPlan[e.RowIndex + 1];
                DayPlan         dp       = dayPlans[e.ColumnIndex - 1];

                PlanDetailsForm pf = new PlanDetailsForm(intersection, dp);
                pf.ShowDialog();
            }
        }
Пример #10
0
        private DayPlan GetSinglePlanInOneDay(int dayIndex, int planIndex, IList <string> hours, IList <string> minutes, IList <string> actions)
        {
            DayPlan dp       = new DayPlan();
            int     actionNo = Convert.ToInt32(actions[planIndex]);

            dp.DayPlanActionId = actionNo;
            dp.DayPlanName     = DayPlanTable.Rows[3][planIndex + 2].ToString();
            dp.Schedule        = GetDayPlanSchedule(planIndex, hours, minutes);
            dp.TimingPlan      = GetDayPlanTiming(actionNo);
            return(dp);
        }
Пример #11
0
    private async Task SetGarnishManuallyAsync(DayPlan day)
    {
        RecipeSelectViewModel?viewModel = container.Resolve <RecipeSelectViewModel>(
            (typeof(DayPlan), day),
            (typeof(bool), true));                                             // garnishSelect

        await dialogService.ShowCustomMessageAsync <RecipeSelectView, RecipeSelectViewModel>(content : viewModel);

        if (viewModel.DialogResultOk)
        {
            day.Garnish = day.Recipe !.Garnishes.First(x => x.ID == viewModel.SelectedRecipe !.ID);
        }
    }
Пример #12
0
        public DayPlan Create(PlanType type, long UserId, DateTime StartAt)
        {
            DayPlan dayplan = new DayPlan()
            {
                UserId   = CurrentPrincipal.UserId,
                CreateAt = DateTime.Now,
                UpdateAt = DateTime.Now
            };

            CurrentDB.DayPlanTable.Add(dayplan);
            CurrentDB.SaveChanges();
            return(dayplan);
        }
Пример #13
0
        private void InsertInCorrectOrder(DayPlan dayPlan)
        {
            var result = DayPlans.Select((Value, Index) => new { Value, Index }).FirstOrDefault(x => x.Value.Date < dayPlan.Date);

            if (result == null)
            {
                DayPlans.Add(dayPlan);
            }
            else
            {
                DayPlans.Insert(result.Index, dayPlan);
            }
        }
Пример #14
0
        public void RemoveDayPlanActivity(string dayPlanId, string activityId)
        {
            DayPlan dayPlan = DayPlans.FirstOrDefault(x => x.Id == dayPlanId);

            if (dayPlan != null)
            {
                Activity activity = dayPlan.Activities.FirstOrDefault(x => x.Id == activityId);

                if (activity != null)
                {
                    dayPlan.Activities.Remove(activity);
                    XmlHelper.SaveDataToFile <DayPlan>(FilePath, this.DayPlans);
                }
            }
        }
Пример #15
0
        public DayOne.Entities.DayPlan CreatePlan(PlanInput planInput)
        {
            if (planInput == null)
            {
                throw new ArgumentNullException("planInput");
            }

            DayPlan dayplan = planInput;

            dayplan.UserId = this.CurrentPrincipal.UserId;

            dayplan = CurrentDB.DayPlanTable.Add(dayplan);
            CurrentDB.SaveChanges();
            return(dayplan);
        }
Пример #16
0
        /// <summary>
        /// Get all plan in one day
        /// </summary>
        /// <param name="dayIndex">Index of the day</param>
        /// <param name="dayPlanData"></param>
        /// <param name="phaseTimeOptionsData"></param>
        /// <param name="patternsData"></param>
        /// <param name="splitsExpandedData"></param>
        /// <returns></returns>
        private IList <DayPlan> GetOneDayDayPlans(int dayIndex)
        {
            IDictionary <string, List <string> > dayPlanDic = GetDayPlanDetailsInfo(dayIndex, DayPlanData);

            IList <string> hours   = dayPlanDic["hours"];
            IList <string> minutes = dayPlanDic["minutes"];
            IList <string> actions = dayPlanDic["actions"];

            IList <DayPlan> dayPlans = new List <DayPlan>();

            //Each dayplan
            for (int planIndex = 0; planIndex < hours.Count(); planIndex++)
            {
                DayPlan sdp = GetSinglePlanInOneDay(dayIndex, planIndex, hours, minutes, actions);
                dayPlans.Add(sdp);
            }
            return(dayPlans);
        }
Пример #17
0
        public async Task <IActionResult> Edit(int id, ProductsPlansViewModel productsPlansViewModel)
        {
            if (id != productsPlansViewModel.ProductsPlan.ProductPlan)
            {
                return(NotFound());
            }
            DayPlan dayPlans = _context.DayPlans.Where(d => d.Date.Equals(productsPlansViewModel.Date)).FirstOrDefault();

            if (dayPlans == null)
            {
                _context.DayPlans.Add(new DayPlan {
                    Date = productsPlansViewModel.Date
                });
                await _context.SaveChangesAsync();

                dayPlans = _context.DayPlans.Where(d => d.Date.Equals(productsPlansViewModel.Date)).FirstOrDefault();
            }
            ProductsPlan productsPlan = productsPlansViewModel.ProductsPlan;

            productsPlan.DayPlanId = dayPlans.DayPlanId;
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(productsPlan);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductsPlanExists(productsPlan.ProductPlan))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DayPlanId"] = new SelectList(_context.DayPlans, "DayPlanId", "Date");
            ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductName");
            return(View(productsPlan));
        }
Пример #18
0
        public void AddDayPlanActivity(Activity activity, string dayPlanId)
        {
            DayPlan dayPlan = DayPlans.FirstOrDefault(x => x.Id == dayPlanId);

            if (dayPlan != null)
            {
                string newId;
                do
                {
                    newId = Guid.NewGuid().ToString("n");
                }while (dayPlan.Activities.FirstOrDefault(x => x.Id == newId) != null);

                activity.Id = newId;

                dayPlan.Activities.Add(activity);

                XmlHelper.SaveDataToFile <DayPlan>(FilePath, this.DayPlans);
            }
        }
Пример #19
0
        private void PatternDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex != -1 && PatternDataGridView.CurrentCell.Value.ToString() != "N/A")
            {
                //IList<DayPlan> dayPlans = intersection.WholeWeeksDayPlan[e.RowIndex + 1];
                //DayPlan dp = dayPlans[e.ColumnIndex];

                DayPlan dp = new DayPlan();
                dp.DayPlanName     = PatternDataGridView.CurrentCell.Value.ToString();
                dp.DayPlanActionId = e.RowIndex * 9 + e.ColumnIndex + 1;
                //Schedule sc = new Schedule(DateTime.Now, DateTime.Now);
                //sdp.Schedule = sc;
                TimingPlan tp = intersection.AllTimings[e.RowIndex * 9 + e.ColumnIndex];
                dp.TimingPlan = tp;

                PlanDetailsForm pf = new PlanDetailsForm(intersection, dp);
                pf.ShowDialog();
            }
        }
Пример #20
0
        private void SetDayPlayDetailsOnUI(DayPlan dp)
        {
            cycleValueLabel.Text    = dp.TimingPlan.CycleLength.ToString();
            offsetValueLabel.Text   = dp.TimingPlan.Offset.ToString();
            sequenceValueLabel.Text = dp.TimingPlan.SequenceNumber.ToString();

            if (dp.Schedule != null)
            {
                scheduleStartLabel.Text = "From: " + dp.Schedule.StartTime.TimeOfDay.ToString();
                scheduleEndLabel.Text   = "To: " + dp.Schedule.EndTime.TimeOfDay.ToString();
            }

            string sequenceString = ControllerInfoTool.SequenceIndexToSequence(dp.TimingPlan.SequenceNumber);

            if (sequenceString.Length > 0)
            {
                ring1Label.Text = sequenceString.Split(':')[0];
                ring2Label.Text = sequenceString.Split(':')[1];
            }
            patternNoValueLabel.Text = dp.DayPlanActionId.ToString();
        }
Пример #21
0
        public async Task <DayPlan> AddDayPlan(DayPlan newPlan, string travelIdentity, string locationId)
        {
            await GraphClient.ConnectAsync();

            try
            {
                var resp = await GraphClient.Cypher
                           .Match("(travel:Travel)", "(location:Location)")
                           .Where((Location location) => location.LocationId == locationId)
                           .AndWhere((Travel travel) => travel.TravelId == travelIdentity)
                           .Create("(plan:DayPlan $plan)")
                           .WithParam("plan", newPlan)
                           .Create("(travel)-[r:HasDayPlan]->(plan)")
                           .Create("(location)-[k:HasDayPlan]->(plan)")
                           .Return(plan => plan.As <DayPlan>())
                           .ResultsAsync;

                if (resp.Any())
                {
                    return(resp.First());
                }
                else
                {
                    return(null);
                }
            }
            catch (ClientException ce)
            {
                if (ce.Message.Contains("already exists", StringComparison.InvariantCultureIgnoreCase))
                {
                    newPlan.DayPlanId = new Guid().ToString();
                    return(await AddDayPlan(newPlan, travelIdentity, locationId));
                }
                else
                {
                    throw ce;
                }
            }
        }
Пример #22
0
        public DataTable getPlanTableWithIntersection(Intersection intersection, DayPlan dp)
        {
            IList <string> pns = new List <string>(new string[] { "Phase 1", "Phase 2", "Phase 3", "Phase 4", "Phase 5", "Phase 6", "Phase 7", "Phase 8", "Phase 9", "Phase 10", "Phase 11", "Phase 12", "Phase 13", "Phase 14", "Phase 15", "Phase 16" });
            //Add columns
            DataTable dt = new DataTable();

            dt.Columns.Add("Data Type");
            foreach (string p in pns)
            {
                dt.Columns.Add(p);
            }

            Split s = dp.TimingPlan.split;
            IDictionary <string, double> wp = intersection.PresetInfo.WalkInfo;
            IDictionary <string, double> pp = intersection.PresetInfo.PedClearance;
            IDictionary <string, double> yp = intersection.PresetInfo.YellowCtl;
            IDictionary <string, double> rp = intersection.PresetInfo.RedCtr;

            //Add Rows
            dt.Rows.Add("Split", s.phases[0].Length, s.phases[1].Length, s.phases[2].Length, s.phases[3].Length, s.phases[4].Length, s.phases[5].Length, s.phases[6].Length, s.phases[7].Length, s.phases[8].Length, s.phases[9].Length, s.phases[10].Length, s.phases[11].Length, s.phases[12].Length, s.phases[13].Length, s.phases[14].Length, s.phases[15].Length);
            dt.Rows.Add("Walk", wp[pns[0]], wp[pns[1]], wp[pns[2]], wp[pns[3]], wp[pns[4]], wp[pns[5]], wp[pns[6]], wp[pns[7]], wp[pns[8]], wp[pns[9]], wp[pns[10]], wp[pns[11]], wp[pns[12]], wp[pns[13]], wp[pns[14]], wp[pns[15]]);
            dt.Rows.Add("Ped Clear", pp[pns[0]], pp[pns[1]], pp[pns[2]], pp[pns[3]], pp[pns[4]], pp[pns[5]], pp[pns[6]], pp[pns[7]], pp[pns[8]], pp[pns[9]], pp[pns[10]], pp[pns[11]], pp[pns[12]], pp[pns[13]], pp[pns[14]], pp[pns[15]]);
            dt.Rows.Add("Yellow Ctrl", yp[pns[0]], yp[pns[1]], yp[pns[2]], yp[pns[3]], yp[pns[4]], yp[pns[5]], yp[pns[6]], yp[pns[7]], yp[pns[8]], yp[pns[9]], yp[pns[10]], yp[pns[11]], yp[pns[12]], yp[pns[13]], yp[pns[14]], yp[pns[15]]);
            dt.Rows.Add("Red Ctrl", rp[pns[0]], rp[pns[1]], rp[pns[2]], rp[pns[3]], rp[pns[4]], rp[pns[5]], rp[pns[6]], rp[pns[7]], rp[pns[8]], rp[pns[9]], rp[pns[10]], rp[pns[11]], rp[pns[12]], rp[pns[13]], rp[pns[14]], rp[pns[15]]);

            for (int i = 0; i < dp.TimingPlan.split.phases.Count; i++)
            {
                Phase ph = dp.TimingPlan.split.phases[i];
                if (ph.CoordinatePhase == true)
                {
                    dt.Columns[pns[i]].ColumnName = pns[i] + "*";
                    break;
                }
            }
            return(dt);
        }
Пример #23
0
 public Task UpdateDayPlanningItem(DayPlan dayPlan)
 {
     throw new NotImplementedException();
 }
Пример #24
0
 public Task AddDayPlan([FromBody] DayPlan plan, string travelIdentity)
 {
     return(_travelService.AddDayPlan(plan, travelIdentity));
 }
Пример #25
0
 private void DeleteRecipeManually(DayPlan day) => day.SpecificRecipe = null;
Пример #26
0
 public PlanDetailsForm(Intersection intersection, DayPlan dp)
 {
     InitializeComponent();
     SetDayPlayDetailsOnUI(dp);
     planDetailsDataGridView.DataSource = getPlanTableWithIntersection(intersection, dp);
 }
Пример #27
0
        private void CreateIntersectionTimingWorkSheet(Intersection intersection)
        {
            Worksheet timingSheet;

            timingSheet      = (Worksheet)xlWorkBook.Worksheets.Add();
            timingSheet.Name = FixNameToOfficialFormat(intersection.Name);

            // Create Schedule Frame
            timingSheet.Cells[1, 1] = intersection.Name;

            // Header
            IList <string> scheduleColumnNames = new List <string>();

            scheduleColumnNames.Add("Week days");
            scheduleColumnNames.Add("Plan 1");
            scheduleColumnNames.Add("Plan 2");
            scheduleColumnNames.Add("Plan 3");
            scheduleColumnNames.Add("Plan 4");
            scheduleColumnNames.Add("Plan 5");
            scheduleColumnNames.Add("Plan 6");
            scheduleColumnNames.Add("Plan 7");
            scheduleColumnNames.Add("Plan 8");

            // Index
            for (int i = 1; i <= scheduleColumnNames.Count; i++)
            {
                timingSheet.Cells[2, i] = scheduleColumnNames[i - 1];
            }

            // Content
            for (int i = 1; i <= intersection.WholeWeeksDayPlan.Count; i++)
            {
                IList <DayPlan> plans = intersection.WholeWeeksDayPlan[i];
                timingSheet.Cells[i + 2, 1] = i.ToString();
                for (int j = 1; j <= 8; j++)
                {
                    string displayStr = "N/A";
                    if (j <= plans.Count)
                    {
                        DayPlan p          = plans[j - 1];
                        string  startTime  = GetTimeHourAndMinuteString(p.Schedule.StartTime);
                        string  endTime    = GetTimeHourAndMinuteString(p.Schedule.EndTime);
                        string  patternStr = p.DayPlanActionId.ToString();
                        displayStr = startTime + " - " + endTime + " (" + patternStr + ")";
                    }
                    timingSheet.Cells[i + 2, j + 1] = displayStr;
                }
            }
            //
            //

            // Create intersection common info frame
            int intersectionCommonFrameOffset = 10;

            timingSheet.Cells[intersectionCommonFrameOffset + 1, 1] = "Type/Phases";
            timingSheet.Cells[intersectionCommonFrameOffset + 2, 1] = "walk";
            timingSheet.Cells[intersectionCommonFrameOffset + 3, 1] = "Ped Clear";
            timingSheet.Cells[intersectionCommonFrameOffset + 4, 1] = "Yellow Ctr";
            timingSheet.Cells[intersectionCommonFrameOffset + 5, 1] = "Red Ctr";
            IList <string> planNames = new List <string>(new string[] { "Phase 1", "Phase 2", "Phase 3", "Phase 4", "Phase 5", "Phase 6", "Phase 7", "Phase 8", "Phase 9", "Phase 10", "Phase 11", "Phase 12", "Phase 13", "Phase 14", "Phase 15", "Phase 16" });

            for (int i = 0; i < planNames.Count; i++)
            {
                timingSheet.Cells[intersectionCommonFrameOffset + 1, i + 2] = planNames[i];
                timingSheet.Cells[intersectionCommonFrameOffset + 2, i + 2] = intersection.PresetInfo.WalkInfo[planNames[i]].ToString();
                timingSheet.Cells[intersectionCommonFrameOffset + 3, i + 2] = intersection.PresetInfo.PedClearance[planNames[i]].ToString();
                timingSheet.Cells[intersectionCommonFrameOffset + 4, i + 2] = intersection.PresetInfo.YellowCtl[planNames[i]].ToString();
                timingSheet.Cells[intersectionCommonFrameOffset + 5, i + 2] = intersection.PresetInfo.RedCtr[planNames[i]].ToString();
            }

            // Create Patterns Frames
            int patternsFrameOffset = intersectionCommonFrameOffset + 6;
            int patternFrameHeight  = 5;

            // Find patterns need to display
            IList <DayPlan> displayPatterns = FindPatternsNeedToDisplay(intersection);

            for (int i = 0; i < displayPatterns.Count; i++)
            {
                DayPlan p = displayPatterns[i];

                // Pre info
                timingSheet.Cells[patternFrameHeight * i + patternsFrameOffset + 1, 1] = "Pattern: " + p.DayPlanActionId;
                timingSheet.Cells[patternFrameHeight * i + patternsFrameOffset + 1, 2] = "Cycle Length: " + p.TimingPlan.CycleLength;
                timingSheet.Cells[patternFrameHeight * i + patternsFrameOffset + 1, 3] = "Offset: " + p.TimingPlan.Offset;
                timingSheet.Cells[patternFrameHeight * i + patternsFrameOffset + 1, 4] = "Ring1: " + ControllerInfoTool.GetRing1StringBySequenceIndex(p.TimingPlan.SequenceNumber);
                timingSheet.Cells[patternFrameHeight * i + patternsFrameOffset + 1, 5] = "Ring2: " + ControllerInfoTool.GetRing2StringBySequenceIndex(p.TimingPlan.SequenceNumber);

                // Header info
                int coordinatePhaseId = GetCoordinatePhaseId(p);
                timingSheet.Cells[patternFrameHeight * i + patternsFrameOffset + 2, 1] = "Type/Phases";
                timingSheet.Cells[patternFrameHeight * i + patternsFrameOffset + 3, 1] = "Split";

                //Content
                for (int j = 0; j < planNames.Count; j++)
                {
                    timingSheet.Cells[patternFrameHeight * i + patternsFrameOffset + 2, j + 2] = planNames[j];
                    if (j + 1 == coordinatePhaseId)
                    {
                        timingSheet.Cells[patternFrameHeight * i + patternsFrameOffset + 2, j + 2] = planNames[j] + "*";
                    }

                    timingSheet.Cells[patternFrameHeight * i + patternsFrameOffset + 3, j + 2] = p.TimingPlan.split.phases[j].Length;
                }
            }
        }