예제 #1
0
        private void UpdateGraph()
        {
            if (IsShowGraph == false)
            {
                return;
            }

            List <GraphModel> tempCollection = new List <GraphModel>();

            GraphDataCollection.Clear();

            // Initialize collection
            tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Monday))));
            tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Tuesday))));
            tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Wednesday))));
            tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Thursday))));
            tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Friday))));
            tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Saturday))));
            tempCollection.Add(new GraphModel(DateHelper.ToStringDate(DateHelper.GetDayOfWeek(_selectedDate, DayOfWeek.Sunday))));

            for (int i = 0; i < tempCollection.Count; i++)
            {
                var itemList = ItemCollection.Where(x => x.Date.Equals(tempCollection[i].Date));
                if (itemList.Count() == 0)
                {
                    continue;
                }

                foreach (var model in itemList)
                {
                    if (model.Type == ItemType.Income)
                    {
                        continue;
                    }

                    tempCollection[i].AddItem(model.Type, model.Amount);
                }
            }

            // Save to GraphItemCollection
            GraphItemCollection.Clear();
            var sortedCollection = tempCollection.OrderBy(x => x.Date);

            for (int i = 0; i < sortedCollection.Count(); i++)
            {
                GraphItemCollection.Add(sortedCollection.ElementAt(i));
            }
        }