예제 #1
0
        private void CalculateCostsDates()
        {
            var categories = CostCollection.GroupBy(x => x.CategoryName).Select(c => c.First()).Select(x => x.CategoryName);

            foreach (var cat in categories)
            {
                Helpers.CostListView[] costs = CostCollection.Where(x => x.CategoryName.Equals(cat)).OrderBy(x => x.BegginingDate).ToArray();
                costs[costs.Length - 1].EndingDate = new DateTime(1900, 1, 1);
                for (int i = 0; i < costs.Length - 1; i++)
                {
                    costs[i].EndingDate = costs[i + 1].BegginingDate.AddDays(-1);
                }
            }
        }
예제 #2
0
        private void AddNewCost(object param)
        {
            if (SelectedCategoryName == null)
            {
                LabelError = "Wybierz kategorię";
                return;
            }
            if (SelectedUnitName == null)
            {
                LabelError = "Wybierz jednostkę";
                return;
            }
            decimal uc;

            if (!decimal.TryParse(UnitCost, out uc) && uc <= 0)
            {
                LabelError = "Podaj poprawny koszt";
                return;
            }
            if (CostBeggining == null)
            {
                LabelError = "Podaj poprawną datę początku obowiązywania";
                return;
            }
            if (SelectedGroupName == null)
            {
                LabelError = "Wybierz grupę";
                return;
            }
            var q = CostCollection.Where(x => x.BegginingDate.Date.CompareTo(CostBeggining.Date) == 0 && x.CategoryName == SelectedCategoryValue && x.CostGroup == SelectedGroupName).Count();

            if (q > 0)
            {
                LabelError = "Istnieje już rekord z taką samą kategorią i datą";
                return;
            }
            LabelError = null;
            var endingDate = new DateTime(1900, 01, 01);

            var c = new Helpers.CostListView()
            {
                BegginingDate = CostBeggining, CategoryName = SelectedCategoryValue, Cost = uc, CostUnit = SelectedUnitName, EndingDate = endingDate, CostGroup = SelectedGroupName
            };

            CostCollection.Add(c);
            CalculateCostsDates();
        }