/* * private bool CheckUnitDependencies(string name) { * short id = GlobalSettings.Wrapper.namesToIds[name]; * BuildingsNames bnames = null; * if (GlobalSettings.Wrapper.harvestersMap.ContainsKey(id)) * bnames = GlobalSettings.Wrapper.harvestersMap[id].BuildingDependency; * else if (GlobalSettings.Wrapper.mcvsMap.ContainsKey(id)) * bnames = GlobalSettings.Wrapper.mcvsMap[id].BuildingDependency; * else if (GlobalSettings.Wrapper.tanksMap.ContainsKey(id)) * bnames = GlobalSettings.Wrapper.tanksMap[id].BuildingDependency; * else if (GlobalSettings.Wrapper.troopersMap.ContainsKey(id)) * bnames = GlobalSettings.Wrapper.troopersMap[id].BuildingDependency; * if (bnames == null) * throw new Exception(name + "not found in building-unit dependencies!"); * return CheckBuildingUnitDeps(bnames); * }*/ private bool CheckUnitDependencies(short id) { BuildingsNames bnames = null; if (GlobalSettings.Wrapper.harvestersMap.ContainsKey(id)) { bnames = GlobalSettings.Wrapper.harvestersMap[id].BuildingDependency; } else if (GlobalSettings.Wrapper.mcvsMap.ContainsKey(id)) { bnames = GlobalSettings.Wrapper.mcvsMap[id].BuildingDependency; } else if (GlobalSettings.Wrapper.tanksMap.ContainsKey(id)) { bnames = GlobalSettings.Wrapper.tanksMap[id].BuildingDependency; } else if (GlobalSettings.Wrapper.troopersMap.ContainsKey(id)) { bnames = GlobalSettings.Wrapper.troopersMap[id].BuildingDependency; } if (bnames == null) { throw new Exception(id + "not found in building-unit dependencies!"); } return(CheckBuildingUnitDeps(bnames)); }
public EditInvoiceWizard(Invoice invoice = null) { DataContext = this; InitializeComponent(); InitializeBuildingsList(); InitializeCategoriesList(); InitializeContractorsList(); if (invoice != null) { _lic = invoice; SelectedBuildingName = BuildingsNames.Where(x => x.BuildingId.Equals(_lic.BuildingId)).FirstOrDefault(); SelectedCategoryName = CategoriesNames.Where(x => x.CategoryId.Equals(_lic.InvoiceCategoryId)).FirstOrDefault(); InvoiceDate = _lic.InvoiceDate.Date; InvoiceCreatedDate = _lic.InvoiceCreatedDate.Date; InvoiceNumber = _lic.InvoiceNumber; SelectedContractorsName = ContractorsNames.Where(x => x.Name.Equals(_lic.ContractorName)).FirstOrDefault(); IsSettled = _lic.IsSettled ? SettlementOptions.Where(x => x == "Tak").FirstOrDefault() : SettlementOptions.Where(x => x == "Nie").FirstOrDefault(); Title = _lic.Title; CostAmountVariable = _lic.CostAmountVariable.ToString(); CostAmountVariableGross = _lic.CostAmountVariableGross.ToString(); SelectedVariableVat = VatCollection.FirstOrDefault(x => x.Rate == _lic.VariableVat); CostAmountConst = _lic.CostAmountConst.ToString(); CostAmountConstGross = _lic.CostAmountConstGross.ToString(); SelectedConstVat = VatCollection.FirstOrDefault(x => x.Rate == _lic.ConstVat); return; } InvoiceDate = DateTime.Today; InvoiceCreatedDate = DateTime.Today; }
private bool CheckBuildingUnitDeps(BuildingsNames bnames) { foreach (string name in bnames) { short idname = GlobalSettings.Wrapper.namesToIds[name]; if (!_gameLogic.hasBuilding(idname)) { return(false); } } return(true); }
public PaymentsPage(Apartment apartment) { DataContext = this; InitializeCollection(); InitializeLists(); InitializeApartmentsNumbers(); SelectedPayments = new List <PaymentDataGrid>(); InitializeComponent(); GroupByBuilding = true; using (var db = new DB.DomenaDBContext()) { var apar = db.Apartments.FirstOrDefault(x => x.ApartmentId.Equals(apartment.ApartmentId)); SelectedBuildingName = BuildingsNames.FirstOrDefault(x => x.BuildingId.Equals(apar.BuildingId)); SelectedApartmentNumber = apar.ApartmentNumber; SelectedOwnerName = OwnersNames.FirstOrDefault(x => x.OwnerId.Equals(apar.OwnerId)); } }
public ChargesPage(Apartment apartment) { DataContext = this; InitializeCollection(); InitializeCategories(); InitializeLists(); InitializeApartmentsNumbers(); SelectedChargesList = new List<ChargeDataGrid>(); InitializeComponent(); GroupByBuilding = false; ShowClosed = true; using (var db = new DB.DomenaDBContext()) { SelectedBuildingName = BuildingsNames.FirstOrDefault(x => x.BuildingId.Equals(apartment.BuildingId)); SelectedApartmentNumber = ApartmentsNumbers.FirstOrDefault(x => x == apartment.ApartmentNumber); SelectedOwnerName = OwnersNames.FirstOrDefault(x => x.OwnerId.Equals(apartment.OwnerId)); ; } }
public EditPaymentWizard(Payment _payment = null) { DataContext = this; InitializeComponent(); InitializeBuildingList(); InitializeApartmentsNumbers(); _lpc = _payment; if (_payment != null) { CanEdit = false; PaymentRegistrationDate = _payment.PaymentRegistrationDate; PaymentAmount = _payment.PaymentAmount.ToString(); SelectedBuildingName = BuildingsNames.FirstOrDefault(x => x.BuildingId.Equals(_apartmentsOC.FirstOrDefault(a => a.ApartmentId.Equals(_payment.ApartmentId)).BuildingId)); SelectedApartmentNumber = ApartmentsNumbers.FirstOrDefault(x => x.ApartmentId.Equals(_payment.ApartmentId)); OwnerMailAddress = _ownersOC.FirstOrDefault(x => x.OwnerId.Equals(SelectedApartmentNumber.OwnerId)).MailAddress; SelectedGroupName = _groupNamesDB.FirstOrDefault(x => x.BuildingChargeGroupNameId == _payment.ChargeGroup.BuildingChargeGroupNameId); return; } CanEdit = true; PaymentRegistrationDate = DateTime.Today; }
private void PrepareData(Apartment apartment, int year) { var owner = OwnersList.FirstOrDefault(x => x.OwnerId == apartment.OwnerId); var building = BuildingsNames.FirstOrDefault(x => x.BuildingId == apartment.BuildingId); OwnerName = owner.OwnerName; BuildingFullName = building.FullName; ApartmentNumber = apartment.ApartmentNumber.ToString(); Locators = apartment.Locators.ToString(); ApartmentTotalArea = (apartment.AdditionalArea + apartment.ApartmentArea).ToString() + " m2"; using (var db = new DB.DomenaDBContext()) { var apArea = db.Apartments.Where(x => x.BuildingId == apartment.BuildingId && !x.IsDeleted).Select(x => x.ApartmentArea).DefaultIfEmpty(0).Sum(); var addArea = db.Apartments.Where(x => x.BuildingId == apartment.BuildingId && !x.IsDeleted).Select(x => x.AdditionalArea).DefaultIfEmpty(0).Sum(); OwnedPercentage = (Math.Floor(((apartment.AdditionalArea + apartment.ApartmentArea) / (apArea + addArea) * 100) * 100) / 100).ToString() + "%"; var groups = db.Invoices.Where(x => !x.IsDeleted && x.BuildingId == apartment.BuildingId).Select(x => x.InvoiceCategoryId).Distinct().ToList(); var dataGridGroups = new List <InvoiceCategory>(); var settleableGroups = db.BuildingInvoceBindings.Include(x => x.Building).Include(x => x.InvoiceCategory).Where(x => !x.IsDeleted && x.Building.BuildingId == building.BuildingId).ToList(); foreach (var g in groups) { if (settleableGroups.Any(x => x.InvoiceCategory.CategoryId == g)) { dataGridGroups.Add(db.InvoiceCategories.FirstOrDefault(x => x.CategoryId == g)); } } int i = 1; CostsCollection = new ObservableCollection <AnalysisDataGrid>(); // var buildingTotalArea = apArea + addArea; var apartmentsCount = db.Apartments.Where(x => !x.IsDeleted && x.BuildingId == apartment.BuildingId).Count(); var totalLocators = db.Apartments.Where(x => !x.IsDeleted && x.BuildingId == apartment.BuildingId).Select(x => x.Locators).DefaultIfEmpty(0).Sum(); foreach (var inv in dataGridGroups) { var cc = new AnalysisDataGrid() { Id = i.ToString(), Group = inv.CategoryName, TotalCost = Math.Floor(db.Invoices.Where(x => x.InvoiceDate.Year == year && !x.IsDeleted && x.BuildingId == apartment.BuildingId && x.InvoiceCategoryId == inv.CategoryId && x.IsSettled).Select(x => x.CostAmountGross).DefaultIfEmpty(0).Sum() * 100) / 100, IsRepairFund = inv.CategoryId == InvoiceCategory.RepairFundInvoiceCategoryId, }; double scale; switch (settleableGroups.FirstOrDefault(x => x.InvoiceCategory.CategoryId == inv.CategoryId).Distribution) { default: break; case CostDistribution.PerAdditionalArea: scale = Math.Floor(10000 * (apartment.AdditionalArea / addArea)) / 10000; cc.ApartmentCost = Math.Floor(100 * (cc.TotalCost * Convert.ToDecimal(scale))) / 100; break; case CostDistribution.PerApartment: scale = Math.Floor(10000 * (1 / (double)apartmentsCount)) / 10000; cc.ApartmentCost = Math.Floor(100 * (cc.TotalCost * Convert.ToDecimal(scale))) / 100; break; case CostDistribution.PerApartmentArea: scale = Math.Floor(10000 * (apartment.ApartmentArea / apArea)) / 10000; cc.ApartmentCost = Math.Floor(100 * (cc.TotalCost * Convert.ToDecimal(scale))) / 100; break; case CostDistribution.PerApartmentTotalArea: scale = Math.Floor(10000 * ((apartment.ApartmentArea + apartment.AdditionalArea) / buildingTotalArea)) / 10000; cc.ApartmentCost = Math.Floor(100 * (cc.TotalCost * Convert.ToDecimal(scale))) / 100; break; case CostDistribution.PerLocators: scale = Math.Floor(10000 * ((double)apartment.Locators / (double)totalLocators)) / 10000; cc.ApartmentCost = Math.Floor(100 * (cc.TotalCost * Convert.ToDecimal(scale))) / 100; break; } CostsCollection.Add(cc); i++; } CostsCollection.Add(new AnalysisDataGrid() { Id = i.ToString(), Group = "Razem: ", TotalCost = CostsCollection.Where(x => !x.IsRepairFund).Sum(x => x.TotalCost), ApartmentCost = CostsCollection.Where(x => !x.IsRepairFund).Sum(x => x.ApartmentCost), IsRepairFund = false, }); } }