// /// <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); }
/// <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); } }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); } }