Esempio n. 1
0
        public static CostCollection GetCollection()
        {
            CostCollection tempList = null;

            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("usp_GetCost", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    myCommand.Parameters.AddWithValue("@QueryId", SelectTypeEnum.GetCollection);

                    myConnection.Open();
                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            tempList = new CostCollection();
                            while (myReader.Read())
                            {
                                tempList.Add(FillDataRecord(myReader));
                            }
                        }
                        myReader.Close();
                    }
                }
            }
            return(tempList);
        }
Esempio n. 2
0
        private void BindCostList()
        {
            CostCollection costList = new CostCollection();

            costList = CostDAL.GetCollection();

            rptCostList.DataSource = costList;
            rptCostList.DataBind();
        }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 4
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();
        }
Esempio n. 5
0
        public EditLegacyBuildingWizard(Building SelectedBuilding = null)
        {
            InitializeComponent();
            DataContext = this;

            MetersCollection = new ObservableCollection <MeterType>();
            InitializeCategoriesList();
            InitializeUnitsList();
            InitializeCostCollection();
            CostBeggining = DateTime.Today;
            if (SelectedBuilding != null)
            {
                _buildingLocalCopy = new Building(SelectedBuilding);

                BuildingName       = SelectedBuilding.Name;
                BuildingCity       = SelectedBuilding.City;
                BuildingZipCode    = SelectedBuilding.ZipCode;
                BuildingRoadName   = SelectedBuilding.RoadName;
                BuildingRoadNumber = SelectedBuilding.BuildingNumber;

                foreach (var c in SelectedBuilding.CostCollection)
                {
                    var clv = new Helpers.CostListView {
                        BegginingDate = c.BegginingDate.Date, EndingDate = c.EndingDate.Date, Cost = c.CostPerUnit, CostUnit = UnitsNames.Where(x => x.EnumValue == c.BuildingChargeBasisDistribution).FirstOrDefault(), CategoryName = CategoriesNames.Where(x => x.BuildingChargeBasisCategoryId.Equals(c.BuildingChargeBasisCategoryId)).FirstOrDefault().CategoryName, CostGroup = GroupNames.Where(x => x.BuildingChargeGroupNameId == c.BuildingChargeGroupNameId).FirstOrDefault()
                    };
                    CostCollection.Add(clv);
                }
                MetersCollection = new ObservableCollection <MeterType>(SelectedBuilding.MeterCollection);
            }
            if (_buildingLocalCopy != null)
            {
                GroupBankAccounts = new ObservableCollection <BuildingChargeGroupBankAccount>(GroupBankAccountsTotal.Where(x => !x.IsDeleted && x.Building.BuildingId == _buildingLocalCopy.BuildingId).ToList());
            }
            else
            {
                GroupBankAccounts = new ObservableCollection <BuildingChargeGroupBankAccount>();
            }
        }
Esempio n. 6
0
 private void DeleteCost(object param)
 {
     CostCollection.Remove(SelectedCost);
     CalculateCostsDates();
 }