Exemplo n.º 1
0
        /// <summary>
        /// inserting residents
        /// </summary>
        /// <param name="table"></param>
        /// <param name="residents"></param>
        public static void InsertResidents(Table table, ResidentList residents)
        {
            for (residents.Beginning(); residents.Exist(); residents.Next())
            {
                Resident temp = residents.Get();

                TableCell residentname    = new TableCell();
                TableCell residentsurname = new TableCell();
                TableCell residentaddress = new TableCell();
                TableCell residentmonth   = new TableCell();
                TableCell residentID      = new TableCell();
                TableCell residentamount  = new TableCell();

                residentname.Text    = temp.Name;
                residentsurname.Text = temp.Surname;
                residentaddress.Text = temp.Address;
                residentmonth.Text   = temp.Month;
                residentID.Text      = temp.ServiceId;
                residentamount.Text  = temp.Amount.ToString();

                TableRow row = new TableRow();

                row.Cells.Add(residentname);
                row.Cells.Add(residentsurname);
                row.Cells.Add(residentaddress);
                row.Cells.Add(residentmonth);
                row.Cells.Add(residentID);
                row.Cells.Add(residentamount);

                table.Rows.Add(row);
            }
        }
Exemplo n.º 2
0
        //
        /// <summary>
        /// to find out which resident paid the least amount
        /// </summary>
        /// <param name="residentlist"></param>
        /// <param name="servicelist"></param>
        /// <returns></returns>
        public static Resident LeastPaid(ResidentList residentlist, ServiceList servicelist)
        {
            residentlist.Beginning();
            Resident temp      = residentlist.Get();
            Resident resident  = new Resident();
            Resident residents = new Resident();
            double   temp1     = Calcs.HowMuchPaid(temp, servicelist);
            double   temp2     = 0;

            if (residentlist.getCount() == 1)
            {
                residents = new Resident(residentlist.Get().Name, residentlist.Get().Surname, servicelist.Get().Title, residentlist.Get().Month);
                return(residents);
            }

            for (residentlist.Beginning(); residentlist.Exist(); residentlist.Next())
            {
                temp2 = Calcs.HowMuchPaid(residentlist.Get(), servicelist);
                if (temp2 < temp1)
                {
                    resident = new Resident(residentlist.Get().Name, residentlist.Get().Surname, servicelist.Get().Title, residentlist.Get().Month);
                    temp1    = temp2;
                }
            }
            return(resident);
        }
Exemplo n.º 3
0
        /// <summary>
        /// method to find out how much did the resident pay
        /// </summary>
        /// <param name="resident"></param>
        /// <param name="servicelist"></param>
        /// <returns></returns>
        public static double HowMuchPaid(Resident resident, ServiceList servicelist)
        {
            for (servicelist.Beginning(); servicelist.Exist(); servicelist.Next())
            {
                if (resident.ServiceId == servicelist.Get().ID)
                {
                    return(resident.Amount * servicelist.Get().Price);
                }
            }

            return(0);
        }
Exemplo n.º 4
0
        /// <summary>
        /// method to read residents data from file
        /// </summary>
        /// <param name="path">file path</param>
        /// <returns></returns>
        public static ResidentList ReadResidents(string path)
        {
            ResidentList residentlist = new ResidentList();

            using (StreamReader reader = new StreamReader(path))
            {
                string line = null;
                while (null != (line = reader.ReadLine()))
                {
                    string[] Values    = line.Split(';');
                    string   name      = Values[0];
                    string   surname   = Values[1];
                    string   address   = Values[2];
                    string   month     = Values[3];
                    string   serviceid = Values[4];
                    int      amount    = int.Parse(Values[5]);
                    Resident resident  = new Resident(name, surname, address, month, serviceid, amount);
                    residentlist.PutData(resident);
                }
            }
            return(residentlist);
        }
Exemplo n.º 5
0
        /// <summary>
        /// table for the residents who paid less than avg
        /// </summary>
        /// <param name="table"></param>
        /// <param name="residents">residents</param>
        public static void TableInsertLessAvg(Table table, ResidentList residents)
        {
            for (residents.Beginning(); residents.Exist(); residents.Next())
            {
                Resident temp = residents.Get();

                TableCell name    = new TableCell();
                TableCell surname = new TableCell();
                TableCell address = new TableCell();

                name.Text    = temp.Name;
                surname.Text = temp.Surname;
                address.Text = temp.Address;

                TableRow row = new TableRow();

                row.Cells.Add(name);
                row.Cells.Add(surname);
                row.Cells.Add(address);

                table.Rows.Add(row);
            }
        }