Beispiel #1
0
        private List <AssociationCountersApartment> GetAllCounters(Administratoro.DAL.Apartments apartment)
        {
            var result = new List <AssociationCountersApartment>();

            for (int i = 0; i < estateCounters.Controls.Count; i++)
            {
                if (estateCounters.Controls[i] is Panel)
                {
                    var mainPanel = (Panel)estateCounters.Controls[i];

                    if (mainPanel.Controls.Count > 2 && mainPanel.Controls[0] is Label &&
                        mainPanel.Controls[2] is DropDownList)
                    {
                        var apCounterId = (Label)mainPanel.Controls[0];
                        var counterId   = (DropDownList)mainPanel.Controls[2];
                        var counterNr   = (TextBox)mainPanel.Controls[3];

                        int apCntId;
                        int apCntIdResult = -1;
                        if (int.TryParse(apCounterId.Text, out apCntId))
                        {
                            apCntIdResult = apCntId;
                        }

                        int cntId;
                        int cntIdResult = -1;
                        if (int.TryParse(counterId.Text, out cntId))
                        {
                            cntIdResult = cntId;
                        }

                        int nrCountersId;
                        int?nrCountersIdResult = null;
                        if (int.TryParse(counterNr.Text, out nrCountersId))
                        {
                            nrCountersIdResult = nrCountersId;
                        }

                        var counter = new AssociationCountersApartment
                        {
                            Id                      = apCntIdResult,
                            Id_Counters             = cntIdResult,
                            Id_Apartment            = apartment.Id,
                            CountersInsideApartment = nrCountersIdResult
                        };

                        result.Add(counter);
                    }
                }
            }

            return(result);
        }
Beispiel #2
0
        private static void UpdateAssociationCountersApartment(int apCounterId, AssociationCountersApartment newApCounter)
        {
            var oldApCounter = GetContext(true).AssociationCountersApartment.FirstOrDefault(c => c.Id == apCounterId);

            if (oldApCounter != null)
            {
                oldApCounter.Id_Counters             = newApCounter.Id_Counters;
                oldApCounter.CountersInsideApartment = newApCounter.CountersInsideApartment;
                GetContext().Entry(oldApCounter).CurrentValues.SetValues(oldApCounter);

                GetContext().SaveChanges();
            }
        }
Beispiel #3
0
        private void PopulateCountersData(Administratoro.DAL.Associations association, Administratoro.DAL.Expenses expense, Administratoro.DAL.Apartments apartment)
        {
            Panel mainPanel = new Panel();

            Label lb = new Label
            {
                Text     = expense.Name,
                CssClass = "col-md-4 col-xs-4"
            };

            DropDownList drp = new DropDownList()
            {
                CssClass = "col-md-4 col-xs-4"
            };

            ListItem defaultNull = new ListItem
            {
                Value = null,
                Text  = " -Fără contor- "
            };

            drp.Items.Add(defaultNull);

            AssociationCountersApartment ac = null;
            var assCounters = association.AssociationCounters.Where(c => c.Id_Expense == expense.Id).ToList();

            if (apartment != null)
            {
                foreach (var assCounter in assCounters)
                {
                    AssociationCountersApartment assApCounter = ApartmentCountersManager.Get(apartment.Id, assCounter.Id);
                    if (assApCounter != null)
                    {
                        ac = assApCounter;
                    }
                }
            }

            if (assCounters.Count != 0)
            {
                Label lbApCounter = new Label
                {
                    Text    = (ac != null) ? ac.Id.ToString() : string.Empty,
                    Visible = false
                };

                int i = 0;
                foreach (var counter in assCounters)
                {
                    ListItem li = new ListItem
                    {
                        Text     = counter.Value,
                        Value    = counter.Id.ToString(),
                        Selected = (ac != null && ac.Id_Counters == counter.Id) || (apartment == null && i == 0)
                    };
                    drp.Items.Add(li);

                    i++;
                }

                TextBox txtNrOfCounters = new TextBox
                {
                    CssClass         = "col-md-4 col-xs-4",
                    AutoCompleteType = AutoCompleteType.Disabled
                };

                if (ac == null)
                {
                    txtNrOfCounters.Text = "0";
                }
                else if (ac.CountersInsideApartment.HasValue)
                {
                    txtNrOfCounters.Text = ac.CountersInsideApartment.ToString();
                }
                else
                {
                    txtNrOfCounters.Text = "1";
                }

                mainPanel.Controls.Add(lbApCounter);
                mainPanel.Controls.Add(lb);
                mainPanel.Controls.Add(drp);
                mainPanel.Controls.Add(txtNrOfCounters);
                mainPanel.Controls.Add(new LiteralControl("<br />"));
                mainPanel.Controls.Add(new LiteralControl("<br />"));
                estateCounters.Visible = true;
                estateCounters.Controls.Add(mainPanel);
            }
        }
Beispiel #4
0
 private static void Add(AssociationCountersApartment apCounter)
 {
     GetContext().AssociationCountersApartment.Add(apCounter);
     GetContext().SaveChanges();
 }
Beispiel #5
0
 private static void Remove(AssociationCountersApartment apRemove)
 {
     GetContext().AssociationCountersApartment.Remove(apRemove);
     GetContext().SaveChanges();
 }