Exemplo n.º 1
0
        public List <DataVisualisationNoCatSelection> SortByDate(List <DataVisualisationNoCatSelection> flows)
        {
            int n = flows.Count;

            // Start with a big gap,
            // then reduce the gap
            for (int gap = n / 2; gap > 0; gap /= 2)
            {
                // Do a gapped insertion sort for this gap size.
                // The first gap elements a[0..gap-1] are already
                // in gapped order keep adding one more element
                // until the entire array is gap sorted
                for (int i = gap; i < n; i += 1)
                {
                    // add a[i] to the elements that have
                    // been gap sorted save a[i] in temp and
                    // make a hole at position i
                    DateTime temp = flows[i].Date;
                    DataVisualisationNoCatSelection interim = flows[i];

                    // shift earlier gap-sorted elements up until
                    // the correct location for a[i] is found
                    int j;
                    for (j = i; j >= gap && DateTime.Compare(flows[j - gap].Date, temp) < 0; j -= gap)
                    {
                        flows[j] = flows[j - gap];
                    }

                    // put temp (the original a[i])
                    // in its correct location
                    flows[j] = interim;
                }
            }
            return(flows);
        }
        public Data_Window(User User, DateTime start, DateTime end)
        {
            InitializeComponent();
            this.StartDt         = start;
            this.EndDt           = end;
            this.User            = User;
            TextBlock_start.Text = start.ToShortDateString();
            TextBlock_end.Text   = end.ToShortDateString();
            List <DataVisualisationNoCatSelection> dataVisualisations = new List <DataVisualisationNoCatSelection>();

            foreach (Income el in appData.gains)
            {
                if (el.UID == User.UID && DateTime.Compare(el.TransactionDt, start) >= 0 && DateTime.Compare(el.TransactionDt, end) <= 0 && el.Category != null)
                {
                    var data = new DataVisualisationNoCatSelection(el.Amount.ToString(), el.TransactionDt.Date, el.Category.Name);
                    data.Comment = el.Comment;
                    dataVisualisations.Add(data);
                }
            }
            foreach (Spending el in appData.losses)
            {
                if (el.UID == User.UID && DateTime.Compare(el.TransactionDt, start) >= 0 && DateTime.Compare(el.TransactionDt, end) <= 0 && el.Category != null)
                {
                    var data = new DataVisualisationNoCatSelection(el.Amount.ToString(), el.TransactionDt.Date, el.Category.Name);
                    data.Comment = el.Comment;
                    dataVisualisations.Add(data);
                }
            }
            calculations.SortByDate(dataVisualisations);
            spendingsList.ItemsSource = dataVisualisations;
            //TODO show results for all categories

            /*
             * else
             * {
             *  foreach (Income el in appData.gains)
             *  {
             *      if (DateTime.Compare(el.TransactionDt, start) >= 0 && DateTime.Compare(el.TransactionDt, end) <= 0 && el.Category == category)
             *          flows.Add(el);
             *  }
             *  foreach (Spending el in appData.losses)
             *  {
             *      if (DateTime.Compare(el.TransactionDt, start) >= 0 && DateTime.Compare(el.TransactionDt, end) <= 0 && el.Category == category)
             *          flows.Add(el);
             *  }
             *  calculations.SortByDate(flows);
             *  spendingsList.ItemsSource = flows;
             *  //TODO show results for selected category
             * }
             */
            /*List<IFlow> flows = new List<IFlow>();
             * {
             *  foreach(Income el in appData.gains)
             *  {
             *      if (DateTime.Compare(el.TransactionDt,start) >= 0 && DateTime.Compare(el.TransactionDt, end)<=0)
             *          flows.Add(el);
             *  }
             *  foreach(Spending el in appData.losses)
             *  {
             *      if (DateTime.Compare(el.TransactionDt, start) >= 0 && DateTime.Compare(el.TransactionDt, end) <= 0)
             *          flows.Add(el);
             *  }
             *  calculations.SortByDate(flows);
             *  spendingsList.ItemsSource = flows;
             *  //TODO show results for all categories
             * }
             * else
             * {
             *  foreach (Income el in appData.gains)
             *  {
             *      if (DateTime.Compare(el.TransactionDt, start) >= 0 && DateTime.Compare(el.TransactionDt, end) <= 0 && el.Category == category)
             *          flows.Add(el);
             *  }
             *  foreach (Spending el in appData.losses)
             *  {
             *      if (DateTime.Compare(el.TransactionDt, start) >= 0 && DateTime.Compare(el.TransactionDt, end) <= 0 && el.Category == category)
             *          flows.Add(el);
             *  }
             *  calculations.SortByDate(flows);
             *  spendingsList.ItemsSource = flows;
             *  //TODO show results for selected category
             * }
             */
        }