Esempio n. 1
0
        private void AddApartment(object param)
        {
            Wizards.EditApartmentWizard eaw = new Wizards.EditApartmentWizard();

            //var result = await DialogHost.Show(eaw, "RootDialog", ExtendedOpenedEventHandler, ExtendedClosingEventHandler);
            SwitchPage.SwitchMainPage(eaw, this);
        }
Esempio n. 2
0
        private void CancelSettlement(object param)
        {
            //var mw = (((((this.Parent as MahApps.Metro.Controls.TransitioningContentControl).Parent as Grid).Parent as DialogHost).Parent as DialogHost).Parent as DialogHost).Parent as Windows.MainWindow;

            var CurrentPage = _settlementPage;

            SwitchPage.SwitchMainPage(CurrentPage, this);
        }
Esempio n. 3
0
        private async void Add(object param)
        {
            Wizards.EditChargeWizard ecw;

            ecw = new Wizards.EditChargeWizard(null);
            
            SwitchPage.SwitchMainPage(ecw, this);
        }
 private void Edit(object param)
 {
     if (SelectedInvoice != null)
     {
         var eiw = new Wizards.EditInvoiceWizard(SelectedInvoice);
         SwitchPage.SwitchMainPage(eiw, this);
     }
 }
Esempio n. 5
0
 private void AcceptDialog(object param)
 {
     if (!IsValid(this as DependencyObject) || (string.IsNullOrEmpty(this.OwnerFirstName) || string.IsNullOrEmpty(this.OwnerSurname) || string.IsNullOrEmpty(this.MailAddress)))
     {
         return;
     }
     SaveDialog(null);
     SwitchPage.SwitchMainPage(new Pages.OwnersPage(), this);
 }
Esempio n. 6
0
        public void WindowSwitchToUrlContainingTest()
        {
            SwitchPage.Go();

            I.Click(SwitchPage.NewWindowSelector);

            I.Switch.Window("/Inp");
            I.Assert.Text("Input Controls Testbed").In("h2");
        }
Esempio n. 7
0
 private void ShowPayments(object param)
 {
     //var mw = (((((this.Parent as MahApps.Metro.Controls.TransitioningContentControl).Parent as Grid).Parent as DialogHost).Parent as DialogHost).Parent as DialogHost).Parent as Windows.MainWindow;
     using (var db = new DB.DomenaDBContext())
     {
         var CurrentPage = new PaymentsPage(db.Apartments.FirstOrDefault(x => x.ApartmentId.Equals(SelectedApartment.ApartmentId)));
         SwitchPage.SwitchMainPage(CurrentPage, this);
     }
 }
        private void Summary(object param)
        {
            if (IsValid(ucSettlement as DependencyObject))
            {
                //var mw = (((((this.Parent as MahApps.Metro.Controls.TransitioningContentControl).Parent as Grid).Parent as DialogHost).Parent as DialogHost).Parent as DialogHost).Parent as Windows.MainWindow;

                var CurrentPage = new SettlementSummaryPage(this);
                SwitchPage.SwitchMainPage(CurrentPage, this);
            }
        }
Esempio n. 9
0
        private async void ShowDetails(object param)
        {
            if (SelectedCharge != null)
            {
                Wizards.PreviewChargeWizard pcw;

                pcw = new Wizards.PreviewChargeWizard(SelectedCharge);

                SwitchPage.SwitchMainPage(pcw, this);
            }
        }
            public bool GetSwitchState(int nodeId)
            {
                SwitchPage page = LoadSwitchPage(NetworkObjectSerializer.Page(nodeId));

                if (page == null)
                {
                    return(false);
                }

                return(page.GetSwitchState(nodeId));
            }
Esempio n. 11
0
        private async void Edit(object param)
        {
            if (SelectedCharge != null)
            {
                Wizards.EditChargeWizard ecw;

                ecw = new Wizards.EditChargeWizard(SelectedCharge);

                SwitchPage.SwitchMainPage(ecw, this);
            }
        }
Esempio n. 12
0
        private void EditOwner(object param)
        {
            Wizards.EditOwnerWizard eow;
            using (var db = new DB.DomenaDBContext())
            {
                var so = db.Owners.Where(x => x.OwnerId.Equals(SelectedOwner.OwnerId)).FirstOrDefault();
                eow = new Wizards.EditOwnerWizard(so);
            }

            SwitchPage.SwitchMainPage(eow, this);
        }
Esempio n. 13
0
        private async void EditApartment(object param)
        {
            Wizards.EditApartmentWizard eaw;
            using (var db = new DB.DomenaDBContext())
            {
                var sa = db.Apartments.Include(x => x.MeterCollection.Select(y => y.MeterTypeParent)).Include(x => x.MeterCollection).Where(x => x.ApartmentId.Equals(SelectedApartment.ApartmentId)).FirstOrDefault();
                eaw = new Wizards.EditApartmentWizard(sa);
            }

            //var result = await DialogHost.Show(eaw, "RootDialog", ExtendedOpenedEventHandler, ExtendedClosingEventHandler);
            SwitchPage.SwitchMainPage(eaw, this);
        }
Esempio n. 14
0
        public void SwitchPageObject()
        {
            SwitchPage.Go();

            var switchPage = InputsPage.Switch <SwitchPage>();

            Assert.True(switchPage.Url.EndsWith("Switch"));

            InputsPage.Go();

            // throw because we aren't on the SwitchPage and nothing is navigating us there
            Assert.Throws <FluentException>(() => InputsPage.Switch <SwitchPage>());
        }
Esempio n. 15
0
        public void FrameSwitchTest()
        {
            SwitchPage.Go();

            I.Switch.Frame(SwitchPage.IFrameSelector)
            .Assert.Text("Alerts Testbed").In("h2");

            I.Switch.Frame()
            .Assert.Text("Switch Testbed").In("h2");

            I.Switch.Frame(I.Find(SwitchPage.IFrameSelector))
            .Assert.Text("Alerts Testbed").In("h2");
        }
Esempio n. 16
0
        public void FrameSwitchToNonexistantFrameThrowsTest()
        {
            SwitchPage.Go();

            I.Switch.Frame(SwitchPage.IFrameSelector)
            .Assert.Text("Alerts Testbed").In("h2");

            var ex = Assert.Throws <FluentException>(() => I.Switch.Frame("nonExistentFrame"));

            // actual message is "No frame element found with name or id non existent frame"
            // but not using that in case the format changes.
            StringAssert.Contains("nonExistentFrame", ex.InnerException.Message);
        }
Esempio n. 17
0
        public void SwitchToPopupTest()
        {
            SwitchPage.Go();

            I.Expect.Text("Switch Testbed").In("h2");
            // open pop up
            I.Click(SwitchPage.new_popup);

            I.Switch.Window("Inputs").Expect.Text("Inputs - FluentAutomation Testbed").In("head > title");
            I.Enter("can you see me").In(InputsPage.TextControlSelector);

            // switch back to primary window
            I.Switch.Window().Expect.Text("Switch Testbed").In("h2");
        }
            private SwitchPage LoadSwitchPage(int page)
            {
                lock (_thisLock)
                {
                    if (_switchPages.ContainsKey(page))
                    {
                        return(_switchPages[page]);
                    }

                    if (_dbfactory != null)
                    {
                        try
                        {
                            int from = page * NetworkObjectSerializer.PageSize + 1;
                            int to   = (page + 1) * NetworkObjectSerializer.PageSize;

                            using (DbConnection connection = _dbfactory.CreateConnection())
                            {
                                connection.ConnectionString = _connectionString;
                                DbCommand command = _dbfactory.CreateCommand();
                                command.Connection  = connection;
                                command.CommandText = "select " + _dbNames.DbColName("FDB_OID") + "," + _dbNames.DbColName("STATE") + " from " + _nodeTableName + " where " + _dbNames.DbColName("SWITCH") + "=1 and " + _dbNames.DbColName("FDB_OID") + ">=" + from + " and " + _dbNames.DbColName("FDB_OID") + "<=" + to;
                                connection.Open();

                                DbDataAdapter adapter = _dbfactory.CreateDataAdapter();
                                adapter.SelectCommand = command;
                                DataTable tab = new DataTable();
                                adapter.Fill(tab);

                                SwitchPage switchPage = new SwitchPage();
                                _switchPages.Add(page, switchPage);
                                foreach (DataRow row in tab.Rows)
                                {
                                    switchPage.Add(Convert.ToInt32(row["FDB_OID"]), Convert.ToBoolean(row["STATE"]));
                                }
                                connection.Close();
                                return(switchPage);
                            }
                        }
                        catch { }
                    }
                    return(null);
                }
            }
Esempio n. 19
0
        public void WindowSwitchTest()
        {
            SwitchPage.Go();

            I.Click(SwitchPage.NewWindowSelector);

            I.Switch.Window("Inputs - FluentAutomation Testbed");

            I.Assert.Text("Input Controls Testbed").In("h2");

            I.Switch.Window()
            .Assert.Text("Switch Testbed").In("h2");

            I.Switch.Window("/Inputs")
            .Assert.Text("Input Controls Testbed").In("h2");

            I.Switch.Window()
            .Assert.Text("Switch Testbed").In("h2");
        }
Esempio n. 20
0
        private void SaveDialog(object param)
        {
            if (!IsValid(this as DependencyObject) || SelectedBuilding == null || ChargeDate == null)
            {
                return;
            }

            var charges = new List <Charge>();

            using (var db = new DB.DomenaDBContext())
            {
                var apartments = db.Apartments.Where(x => !x.IsDeleted && x.SoldDate == null && x.BuildingId == SelectedBuilding.BuildingId).ToList();

                foreach (var ap in apartments)
                {
                    var newCharge = new LibDataModel.Charge();
                    newCharge.SettlementId = Guid.Empty;
                    newCharge.ChargeId     = Guid.NewGuid();
                    newCharge.ApartmentId  = ap.ApartmentId;
                    newCharge.CreatedDate  = DateTime.Today;
                    newCharge.ChargeDate   = ChargeDate;
                    newCharge.IsClosed     = false;
                    newCharge.IsDeleted    = false;
                    newCharge.OwnerId      = ap.OwnerId;

                    db.Charges.Add(newCharge);
                    charges.Add(newCharge);
                }
                db.SaveChanges();
            }

            foreach (var c in charges)
            {
                ChargesOperations.RecalculateCharge(c);
            }

            SwitchPage.SwitchMainPage(new Pages.ChargesPage(), this);
        }
Esempio n. 21
0
 private void AddBuildingCharge(object param)
 {
     Wizards.AddBuildingCharge abc;
     abc = new Wizards.AddBuildingCharge();
     SwitchPage.SwitchMainPage(abc, this);
 }
Esempio n. 22
0
        private void AssinarMensagens()
        {
            MessagingCenter.Subscribe <ActivityIndicatorPage>(this, "GoActivity", (msg) =>
            {
                //App.Current.MainPage = new Navigation.Pagina1();
                Detail = new ActivityIndicatorPage();

                //Esconder a master
                IsPresented = false;
            });

            MessagingCenter.Subscribe <ProgressBarPage>(this, "GoProgressBar", (msg) =>
            {
                Detail = new ProgressBarPage();
                //Esconder a master
                IsPresented = false;
            });

            MessagingCenter.Subscribe <BoxViewPage>(this, "GoBoxView", (msg) =>
            {
                Detail = new BoxViewPage();
                //Esconder a master
                IsPresented = false;
            });

            MessagingCenter.Subscribe <LabelPage>(this, "GoLabel", (msg) =>
            {
                Detail = new LabelPage();
                //Esconder a master
                IsPresented = false;
            });

            MessagingCenter.Subscribe <ButtonPage>(this, "GoButton", (msg) =>
            {
                Detail = new ButtonPage();
                //Esconder a master
                IsPresented = false;
            });

            MessagingCenter.Subscribe <EntryEditorPage>(this, "GoEntryEditor", (msg) =>
            {
                Detail = new EntryEditorPage();
                //Esconder a master
                IsPresented = false;
            });

            MessagingCenter.Subscribe <DatePickerPage>(this, "GoDatePicker", (msg) =>
            {
                Detail = new DatePickerPage();
                //Esconder a master
                IsPresented = false;
            });

            MessagingCenter.Subscribe <TimePickerPage>(this, "GoTimePicker", (msg) =>
            {
                Detail = new TimePickerPage();
                //Esconder a master
                IsPresented = false;
            });

            MessagingCenter.Subscribe <PickerPage>(this, "GoPickerPage", (msg) =>
            {
                Detail = new PickerPage();
                //Esconder a master
                IsPresented = false;
            });

            MessagingCenter.Subscribe <SearchBarPage>(this, "GoSearchPage", (msg) =>
            {
                Detail = new SearchBarPage();
                //Esconder a master
                IsPresented = false;
            });

            MessagingCenter.Subscribe <SliderStepperPage>(this, "GoSliderStepper", (msg) =>
            {
                Detail = new SliderStepperPage();
                //Esconder a master
                IsPresented = false;
            });

            MessagingCenter.Subscribe <SwitchPage>(this, "GoSwitch", (msg) =>
            {
                Detail = new SwitchPage();
                //Esconder a master
                IsPresented = false;
            });

            MessagingCenter.Subscribe <ImagePage>(this, "GoImagePage", (msg) =>
            {
                Detail = new ImagePage();
                //Esconder a master
                IsPresented = false;
            });

            MessagingCenter.Subscribe <ListViewPage>(this, "GoListView", (msg) =>
            {
                Detail = new ListViewPage();
                //Esconder a master
                IsPresented = false;
            });

            MessagingCenter.Subscribe <TableViewPage>(this, "GoTableViewPage", (msg) =>
            {
                Detail = new TableViewPage();
                //Esconder a master
                IsPresented = false;
            });

            MessagingCenter.Subscribe <WebViewPage>(this, "GoWebView", (msg) =>
            {
                Detail = new WebViewPage();
                //Esconder a master
                IsPresented = false;
            });
        }
        private void TrocaTelaCommand()
        {
            var pageActivity = new ActivityIndicatorPage();

            GoActivityIndicator = new Command(() =>
            {
                MessagingCenter.Send <ActivityIndicatorPage>(pageActivity, "GoActivity");
            });

            var pageProgressBar = new ProgressBarPage();

            GoProgressBar = new Command(() =>
            {
                MessagingCenter.Send <ProgressBarPage>(pageProgressBar, "GoProgressBar");
            });

            var pageBoxView = new BoxViewPage();

            GoBoxView = new Command(() =>
            {
                MessagingCenter.Send <BoxViewPage>(pageBoxView, "GoBoxView");
            });

            var pageLabel = new LabelPage();

            GoLabel = new Command(() =>
            {
                MessagingCenter.Send <LabelPage>(pageLabel, "GoLabel");
            });

            var pageButton = new ButtonPage();

            GoButton = new Command(() =>
            {
                MessagingCenter.Send <ButtonPage>(pageButton, "GoButton");
            });

            var pageEntryEditor = new EntryEditorPage();

            GoEntryEditor = new Command(() =>
            {
                MessagingCenter.Send <EntryEditorPage>(pageEntryEditor, "GoEntryEditor");
            });

            var pageDatePicker = new DatePickerPage();

            GoDatePicker = new Command(() =>
            {
                MessagingCenter.Send <DatePickerPage>(pageDatePicker, "GoDatePicker");
            });

            var pageTimePicker = new TimePickerPage();

            GoTimePicker = new Command(() =>
            {
                MessagingCenter.Send <TimePickerPage>(pageTimePicker, "GoTimePicker");
            });

            var pagePickerPage = new PickerPage();

            GoPickerPage = new Command(() =>
            {
                MessagingCenter.Send <PickerPage>(pagePickerPage, "GoPickerPage");
            });

            var pageSearchBar = new SearchBarPage();

            GoSearchPage = new Command(() =>
            {
                MessagingCenter.Send <SearchBarPage>(pageSearchBar, "GoSearchPage");
            });

            var pageSliderStepper = new SliderStepperPage();

            GoSliderStepper = new Command(() =>
            {
                MessagingCenter.Send <SliderStepperPage>(pageSliderStepper, "GoSliderStepper");
            });

            var pageSwitch = new SwitchPage();

            GoSwitch = new Command(() =>
            {
                MessagingCenter.Send <SwitchPage>(pageSwitch, "GoSwitch");
            });

            var imagePage = new ImagePage();

            GoImagePage = new Command(() =>
            {
                MessagingCenter.Send <ImagePage>(imagePage, "GoImagePage");
            });

            var listView = new ListViewPage();

            GoListView = new Command(() =>
            {
                MessagingCenter.Send <ListViewPage>(listView, "GoListView");
            });

            var tablePage = new TableViewPage();

            GoTableViewPage = new Command(() =>
            {
                MessagingCenter.Send <TableViewPage>(tablePage, "GoTableViewPage");
            });

            var webView = new WebViewPage();

            GoWebView = new Command(() =>
            {
                MessagingCenter.Send <WebViewPage>(webView, "GoWebView");
            });
        }
 private void CancelDialog(object param)
 {
     SwitchPage.SwitchMainPage(new Pages.InvoicesPage(), this);
 }
 private void IrParaPaginaSwitch(object s, EventArgs e)
 {
     Detail = new SwitchPage();
 }
Esempio n. 26
0
        private void AddOwner(object param)
        {
            Wizards.EditOwnerWizard eow = new Wizards.EditOwnerWizard();

            SwitchPage.SwitchMainPage(eow, this);
        }
Esempio n. 27
0
        public void Accept(object param)
        {
            // Edit building
            if (_localBuildingCopy != null)
            {
                using (var db = new DB.DomenaDBContext())
                {
                    var selectedBuilding = db.Buildings.Include(x => x.CostCollection).Include(x => x.MeterCollection).FirstOrDefault(x => x.BuildingId == _localBuildingCopy.BuildingId);

                    #region MasterData

                    selectedBuilding.BuildingNumber = masterDataView.BuildingRoadNumber;
                    selectedBuilding.City           = masterDataView.BuildingCity;
                    selectedBuilding.FullName       = masterDataView.BuildingFullName;
                    selectedBuilding.Name           = masterDataView.BuildingName;
                    selectedBuilding.RoadName       = masterDataView.BuildingRoadName;
                    selectedBuilding.ZipCode        = masterDataView.BuildingZipCode;

                    #endregion

                    #region Charges

                    while (selectedBuilding.CostCollection.Count > 0)
                    {
                        db.Entry(selectedBuilding.CostCollection[0]).State = EntityState.Deleted;
                    }

                    List <BuildingChargeBasis> costs = new List <BuildingChargeBasis>();
                    foreach (var c in chargesView.CostCollection)
                    {
                        var catId = db.CostCategories.Where(x => x.CategoryName.Equals(c.CategoryName)).FirstOrDefault().BuildingChargeBasisCategoryId;
                        var cost  = new BuildingChargeBasis {
                            BuildingChargeBasisId = Guid.NewGuid(), BegginingDate = c.BegginingDate.Date, EndingDate = c.EndingDate.Date, CostPerUnit = c.Cost, BuildingChargeBasisDistribution = c.CostUnit.EnumValue, BuildingChargeBasisCategoryId = catId, BuildingChargeGroupNameId = c.CostGroup.BuildingChargeGroupNameId
                        };
                        costs.Add(cost);
                    }
                    selectedBuilding.CostCollection = costs;

                    var buildingBankAddresses = db.BuildingChargeGroupBankAccounts.Where(x => x.Building.BuildingId == selectedBuilding.BuildingId).ToList();

                    //Add new
                    foreach (var bba in chargesView.GroupBankAccounts)
                    {
                        if (!buildingBankAddresses.Any(x => x.BuildingChargeGroupBankAccountId == bba.BuildingChargeGroupBankAccountId))
                        {
                            bba.Building = selectedBuilding;
                            db.BuildingChargeGroupBankAccounts.Add(bba);
                            db.Entry(bba.GroupName).State = EntityState.Unchanged;
                            db.Entry(bba.Building).State  = EntityState.Unchanged;
                        }
                    }
                    //Remove necessary
                    for (int i = buildingBankAddresses.Count - 1; i >= 0; i--)
                    {
                        if (!chargesView.GroupBankAccounts.Any(x => x.BuildingChargeGroupBankAccountId.Equals(buildingBankAddresses[i].BuildingChargeGroupBankAccountId)))
                        {
                            buildingBankAddresses[i].IsDeleted = true;
                        }
                        else
                        {
                            // Change names
                            buildingBankAddresses[i].BankAccount = chargesView.GroupBankAccounts.FirstOrDefault(x => x.BuildingChargeGroupBankAccountId == buildingBankAddresses[i].BuildingChargeGroupBankAccountId).BankAccount;
                            buildingBankAddresses[i].GroupName   = chargesView.GroupBankAccounts.FirstOrDefault(x => x.BuildingChargeGroupBankAccountId == buildingBankAddresses[i].BuildingChargeGroupBankAccountId).GroupName;

                            //db.Entry(buildingBankAddresses[i].Building).State = EntityState.Unchanged;
                            db.Entry(buildingBankAddresses[i].GroupName).State = EntityState.Unchanged;
                        }
                    }

                    #endregion

                    #region Meters

                    //Add new
                    foreach (var m in countersView.MetersCollection)
                    {
                        if (!selectedBuilding.MeterCollection.Any(x => x.MeterId.Equals(m.MeterId)))
                        {
                            selectedBuilding.MeterCollection.Add(m);
                        }
                    }
                    //Remove necessary
                    for (int i = selectedBuilding.MeterCollection.Count - 1; i >= 0; i--)
                    {
                        if (!countersView.MetersCollection.Any(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)))
                        {
                            selectedBuilding.MeterCollection.RemoveAt(i);
                        }
                        else
                        {
                            // Change names
                            selectedBuilding.MeterCollection[i].Name = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).Name;
                            if (selectedBuilding.MeterCollection[i].LastMeasure != countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).LastMeasure)
                            {
                                var nm = new MetersHistory
                                {
                                    MeterHistoryId = Guid.NewGuid(),
                                    Apartment      = null,
                                    ApartmentMeter = null,
                                    Building       = selectedBuilding,
                                    MeterType      = selectedBuilding.MeterCollection[i],
                                    ModifiedDate   = DateTime.Now,
                                    NewValue       = selectedBuilding.MeterCollection[i].LastMeasure,
                                    OldValue       = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).LastMeasure,
                                };
                                db.MetersHistories.Add(nm);
                                db.Entry(nm.Building).State = EntityState.Unchanged;

                                selectedBuilding.MeterCollection[i].LastMeasure = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).LastMeasure;
                            }
                            selectedBuilding.MeterCollection[i].IsBuilding  = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).IsBuilding;
                            selectedBuilding.MeterCollection[i].IsApartment = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).IsApartment;
                        }
                    }

                    #endregion

                    #region Invoices

                    foreach (var inv in invoicesView.BuildingInvoiceBindings)
                    {
                        var binding = db.BuildingInvoceBindings.FirstOrDefault(x => x.BindingId == inv.BindingId);
                        if (binding == null) // add new
                        {
                            db.BuildingInvoceBindings.Add(
                                new BuildingInvoiceBinding()
                            {
                                BindingId       = inv.BindingId,
                                Building        = selectedBuilding,
                                Distribution    = inv.Distribution,
                                InvoiceCategory = inv.InvoiceCategory,
                                IsDeleted       = inv.IsDeleted,
                            });
                            db.Entry(inv.InvoiceCategory).State = EntityState.Unchanged;
                            //db.Entry(selectedBuilding).State = EntityState.Unchanged;
                        }
                        else // edit existing
                        {
                            binding.Distribution                = inv.Distribution;
                            binding.InvoiceCategory             = inv.InvoiceCategory;
                            binding.IsDeleted                   = inv.IsDeleted;
                            db.Entry(inv.InvoiceCategory).State = EntityState.Unchanged;
                        }
                    }

                    // Mark IsDeleted deleted entries
                    var bindings = db.BuildingInvoceBindings.Where(x => !x.IsDeleted && x.Building.BuildingId == selectedBuilding.BuildingId);
                    foreach (var b in bindings)
                    {
                        if (!invoicesView.BuildingInvoiceBindings.Any(x => x.BindingId == b.BindingId))
                        {
                            b.IsDeleted = true;
                        }
                    }

                    #endregion

                    db.SaveChanges();

                    // Add meters to building

                    #region Meters

                    selectedBuilding = db.Buildings.Include(x => x.CostCollection).Include(x => x.MeterCollection).FirstOrDefault(x => x.BuildingId == _localBuildingCopy.BuildingId);

                    if (selectedBuilding.MeterCollection != null || selectedBuilding.MeterCollection.Count > 0)
                    {
                        foreach (var a in db.Apartments.Include(x => x.MeterCollection).Where(x => !x.IsDeleted && x.BuildingId == selectedBuilding.BuildingId))
                        {
                            if (a.MeterCollection == null || a.MeterCollection.Count == 0)
                            {
                                a.MeterCollection = new List <ApartmentMeter>();
                                foreach (var m in selectedBuilding.MeterCollection.Where(x => !x.IsDeleted && x.IsApartment))
                                {
                                    a.MeterCollection.Add(new ApartmentMeter()
                                    {
                                        IsDeleted = m.IsDeleted, MeterTypeParent = m, MeterId = Guid.NewGuid(), LegalizationDate = DateTime.Today.AddDays(-1)
                                    });
                                }
                            }
                            else if (a.MeterCollection != null && a.MeterCollection.Count > 0)
                            {
                                for (int i = selectedBuilding.MeterCollection.Count - 1; i >= 0; i--)
                                {
                                    if (!a.MeterCollection.Any(x => x.MeterTypeParent.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)) && selectedBuilding.MeterCollection[i].IsApartment)
                                    {
                                        a.MeterCollection.Add(new ApartmentMeter()
                                        {
                                            MeterId = Guid.NewGuid(), MeterTypeParent = selectedBuilding.MeterCollection[i], IsDeleted = false, LastMeasure = 0, LegalizationDate = DateTime.Today.AddDays(-1)
                                        });
                                    }
                                    else if (selectedBuilding.MeterCollection[i].IsApartment)
                                    {
                                        a.MeterCollection.FirstOrDefault(x => x.MeterTypeParent.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).IsDeleted = false;
                                    }
                                }
                                for (int i = a.MeterCollection.Count - 1; i >= 0; i--)
                                {
                                    if (!selectedBuilding.MeterCollection.Any(x => x.MeterId.Equals(a.MeterCollection[i].MeterTypeParent.MeterId)))
                                    {
                                        a.MeterCollection.RemoveAt(i);
                                    }
                                }
                            }
                        }
                        db.SaveChanges();
                    }

                    #endregion
                }
            }
            // New building
            else
            {
                using (var db = new DB.DomenaDBContext())
                {
                    var selectedBuilding = new Building()
                    {
                        BuildingId = Guid.NewGuid(),
                    };

                    #region MasterData

                    selectedBuilding.BuildingNumber = masterDataView.BuildingRoadNumber;
                    selectedBuilding.City           = masterDataView.BuildingCity;
                    selectedBuilding.FullName       = masterDataView.BuildingFullName;
                    selectedBuilding.Name           = masterDataView.BuildingName;
                    selectedBuilding.RoadName       = masterDataView.BuildingRoadName;
                    selectedBuilding.ZipCode        = masterDataView.BuildingZipCode;

                    #endregion

                    db.Buildings.Add(selectedBuilding);
                    db.SaveChanges();

                    selectedBuilding = db.Buildings.Include(x => x.CostCollection).Include(x => x.MeterCollection).FirstOrDefault(x => x.BuildingId == selectedBuilding.BuildingId);

                    #region Charges

                    while (selectedBuilding.CostCollection.Count > 0)
                    {
                        db.Entry(selectedBuilding.CostCollection[0]).State = EntityState.Deleted;
                    }

                    List <BuildingChargeBasis> costs = new List <BuildingChargeBasis>();
                    foreach (var c in chargesView.CostCollection)
                    {
                        var catId = db.CostCategories.Where(x => x.CategoryName.Equals(c.CategoryName)).FirstOrDefault().BuildingChargeBasisCategoryId;
                        var cost  = new BuildingChargeBasis {
                            BuildingChargeBasisId = Guid.NewGuid(), BegginingDate = c.BegginingDate.Date, EndingDate = c.EndingDate.Date, CostPerUnit = c.Cost, BuildingChargeBasisDistribution = c.CostUnit.EnumValue, BuildingChargeBasisCategoryId = catId, BuildingChargeGroupNameId = c.CostGroup.BuildingChargeGroupNameId
                        };
                        costs.Add(cost);
                    }
                    selectedBuilding.CostCollection = costs;

                    var buildingBankAddresses = db.BuildingChargeGroupBankAccounts.Where(x => x.Building.BuildingId == selectedBuilding.BuildingId).ToList();

                    //Add new
                    foreach (var bba in chargesView.GroupBankAccounts)
                    {
                        if (!buildingBankAddresses.Any(x => x.BuildingChargeGroupBankAccountId == bba.BuildingChargeGroupBankAccountId))
                        {
                            bba.Building = selectedBuilding;
                            db.BuildingChargeGroupBankAccounts.Add(bba);
                            db.Entry(bba.GroupName).State = EntityState.Unchanged;
                            db.Entry(bba.Building).State  = EntityState.Unchanged;
                        }
                    }
                    //Remove necessary
                    for (int i = buildingBankAddresses.Count - 1; i >= 0; i--)
                    {
                        if (!chargesView.GroupBankAccounts.Any(x => x.BuildingChargeGroupBankAccountId.Equals(buildingBankAddresses[i].BuildingChargeGroupBankAccountId)))
                        {
                            buildingBankAddresses[i].IsDeleted = true;
                        }
                        else
                        {
                            // Change names
                            buildingBankAddresses[i].BankAccount = chargesView.GroupBankAccounts.FirstOrDefault(x => x.BuildingChargeGroupBankAccountId == buildingBankAddresses[i].BuildingChargeGroupBankAccountId).BankAccount;
                            buildingBankAddresses[i].GroupName   = chargesView.GroupBankAccounts.FirstOrDefault(x => x.BuildingChargeGroupBankAccountId == buildingBankAddresses[i].BuildingChargeGroupBankAccountId).GroupName;

                            //db.Entry(buildingBankAddresses[i].Building).State = EntityState.Unchanged;
                            db.Entry(buildingBankAddresses[i].GroupName).State = EntityState.Unchanged;
                        }
                    }

                    #endregion

                    #region Meters

                    //Add new
                    foreach (var m in countersView.MetersCollection)
                    {
                        if (!selectedBuilding.MeterCollection.Any(x => x.MeterId.Equals(m.MeterId)))
                        {
                            selectedBuilding.MeterCollection.Add(m);
                        }
                    }
                    //Remove necessary
                    for (int i = selectedBuilding.MeterCollection.Count - 1; i >= 0; i--)
                    {
                        if (!countersView.MetersCollection.Any(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)))
                        {
                            selectedBuilding.MeterCollection.RemoveAt(i);
                        }
                        else
                        {
                            // Change names
                            selectedBuilding.MeterCollection[i].Name = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).Name;
                            if (selectedBuilding.MeterCollection[i].LastMeasure != countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).LastMeasure)
                            {
                                var nm = new MetersHistory
                                {
                                    MeterHistoryId = Guid.NewGuid(),
                                    Apartment      = null,
                                    ApartmentMeter = null,
                                    Building       = selectedBuilding,
                                    MeterType      = selectedBuilding.MeterCollection[i],
                                    ModifiedDate   = DateTime.Now,
                                    NewValue       = selectedBuilding.MeterCollection[i].LastMeasure,
                                    OldValue       = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).LastMeasure,
                                };
                                db.MetersHistories.Add(nm);
                                db.Entry(nm.Building).State = EntityState.Unchanged;

                                selectedBuilding.MeterCollection[i].LastMeasure = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).LastMeasure;
                            }
                            selectedBuilding.MeterCollection[i].IsBuilding  = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).IsBuilding;
                            selectedBuilding.MeterCollection[i].IsApartment = countersView.MetersCollection.FirstOrDefault(x => x.MeterId.Equals(selectedBuilding.MeterCollection[i].MeterId)).IsApartment;
                        }
                    }

                    #endregion

                    #region Invoices

                    foreach (var inv in invoicesView.BuildingInvoiceBindings)
                    {
                        var binding = db.BuildingInvoceBindings.FirstOrDefault(x => x.BindingId == inv.BindingId);
                        if (binding == null) // add new
                        {
                            db.BuildingInvoceBindings.Add(
                                new BuildingInvoiceBinding()
                            {
                                BindingId       = inv.BindingId,
                                Building        = selectedBuilding,
                                Distribution    = inv.Distribution,
                                InvoiceCategory = inv.InvoiceCategory,
                                IsDeleted       = inv.IsDeleted,
                            });
                            db.Entry(inv.InvoiceCategory).State = EntityState.Unchanged;
                            //db.Entry(selectedBuilding).State = EntityState.Unchanged;
                        }
                        else // edit existing
                        {
                            binding.Distribution                = inv.Distribution;
                            binding.InvoiceCategory             = inv.InvoiceCategory;
                            binding.IsDeleted                   = inv.IsDeleted;
                            db.Entry(inv.InvoiceCategory).State = EntityState.Unchanged;
                        }
                    }

                    // Mark IsDeleted deleted entries
                    var bindings = db.BuildingInvoceBindings.Where(x => !x.IsDeleted && x.Building.BuildingId == selectedBuilding.BuildingId);
                    foreach (var b in bindings)
                    {
                        if (!invoicesView.BuildingInvoiceBindings.Any(x => x.BindingId == b.BindingId))
                        {
                            b.IsDeleted = true;
                        }
                    }

                    #endregion

                    db.SaveChanges();
                }
            }

            SwitchPage.SwitchMainPage(new Pages.BuildingsPage(), this);
        }
Esempio n. 28
0
 private void SellApartment(object param)
 {
     Wizards.SellApartmentWizard saw = new Wizards.SellApartmentWizard(SelectedApartment);
     SwitchPage.SwitchMainPage(saw, this);
 }
 public void Cancel(object param)
 {
     SwitchPage.SwitchMainPage(new Pages.BuildingsPage(), this);
 }
 private void CancelDialog(object param)
 {
     SwitchPage.SwitchMainPage(new Pages.MonthlyChargesPage(), this);
 }