Пример #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);
            }
        }
Пример #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);
        }
Пример #3
0
        /// <summary>
        /// method to find the average price of the service paid by the residents
        /// </summary>
        /// <param name="residentlist"></param>
        /// <param name="servicelist"></param>
        /// <returns></returns>
        public static double AveragePrice(ResidentList residentlist, ServiceList servicelist)
        {
            double average = 0;
            double sum     = Calcs.TotalAmountPaid(residentlist, servicelist);

            average = sum / residentlist.getCount();

            return(average);
        }
Пример #4
0
        /// <summary>
        /// method to find the total sum of paid cash by the residents
        /// </summary>
        /// <param name="residentlist"></param>
        /// <param name="servicelist"></param>
        /// <returns></returns>
        public static double TotalAmountPaid(ResidentList residentlist, ServiceList servicelist)
        {
            double amount = 0;

            for (residentlist.Beginning(); residentlist.Exist(); residentlist.Next())
            {
                amount += HowMuchPaid(residentlist.Get(), servicelist);
            }
            return(amount);
        }
Пример #5
0
        /// <summary>
        /// to find out which resident didnt pay for the chosen month
        /// </summary>
        /// <param name="residentlist"></param>
        /// <param name="servicelist"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        public static ResidentList DidntPay(ResidentList residentlist, ServiceList servicelist, string month, string serviceid)
        {
            ResidentList notpaidservices = new ResidentList();

            for (residentlist.Beginning(); residentlist.Exist(); residentlist.Next())
            {
                if (residentlist.Get().Month != month || residentlist.Get().ServiceId != serviceid)
                {
                    notpaidservices.PutData(residentlist.Get());
                }
            }
            return(notpaidservices);
        }
Пример #6
0
 /// <summary>
 /// method to remove people, who didnt pay for the month and service
 /// </summary>
 /// <param name="residentlist"></param>
 /// <param name="notpaidservices"></param>
 /// <returns></returns>
 public static ResidentList ResidentRemoval(ResidentList residentlist, ResidentList notpaidservices)
 {
     for (residentlist.Beginning(); residentlist.Exist(); residentlist.Next())
     {
         for (notpaidservices.Beginning(); notpaidservices.Exist(); notpaidservices.Next())
         {
             if (residentlist.Get() == notpaidservices.Get())
             {
                 residentlist.Remove(residentlist.GetNode());
             }
         }
     }
     return(residentlist);
 }
Пример #7
0
        /// <summary>
        /// printing initial data to txt file
        /// </summary>
        /// <param name="residents">residents</param>
        public static void PrintResidents(ResidentList residents)
        {
            string        file  = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "App_Data");
            List <string> lines = new List <string>();

            lines.Add("Initial data \nResidents:");
            residents.Beginning();
            lines.Add(new string('-', residents.Get().StringFormat().Length));
            lines.Add(residents.Get().StringFormat());
            lines.Add(new string('-', residents.Get().StringFormat().Length));
            for (residents.Beginning(); residents.Exist(); residents.Next())
            {
                lines.Add(residents.Get().ToString());
            }
            residents.Beginning();
            lines.Add(new string('-', residents.Get().StringFormat().Length));
            File.AppendAllLines((file + "/Rezultatai.txt"), lines);
        }
Пример #8
0
        /// <summary>
        /// to find the list of the residents who paid less than average for the services
        /// </summary>
        /// <param name="residentlist"></param>
        /// <param name="servicelist"></param>
        /// <returns></returns>
        public static ResidentList PaidLessThanAvg(ResidentList residentlist, ServiceList servicelist)
        {
            ResidentList residentaverage = new ResidentList();

            residentlist.Beginning();
            double avg = Calcs.AveragePrice(residentlist, servicelist);

            residentlist.Beginning();

            for (residentlist.Beginning(); residentlist.Exist(); residentlist.Next())
            {
                if (Calcs.HowMuchPaid(residentlist.Get(), servicelist) < avg)
                {
                    residentaverage.PutData(residentlist.Get());
                }
            }
            return(residentaverage);
        }
Пример #9
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);
        }
Пример #10
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);
            }
        }