public int number_of_contracts(conditionDelegate cond) //return number of contract { var List_contract = from n in dal.Allcontract() where cond(n) select n; return(List_contract.Count()); }
public int numberValidContracts(conditionDelegate cond) { var List_contract = from n in Dal.allContract() where cond(n) select n; return(List_contract.Count()); }
public static List <int> getNewList(List <int> list, conditionDelegate cond) { List <int> list2 = new List <int>(); foreach (int item in list) { if (cond(item)) { list2.Add(item); } } return(list2); }
/// <summary> /// akin to "select * from data where condition(data)" /// </summary> /// <param name="data">Dataset to search.</param> /// <param name="condition"></param> /// <returns>A new dataset representing the information meeting the specified criteria.</returns> public static object[] allFormListWhere(IList data, conditionDelegate condition) { ArrayList items = new ArrayList(); int i; for (i = 0; i < data.Count; i++) { if (condition(data[i])) { items.Add(data[i]); } } return(items.ToArray()); }
/// <summary> /// finds all test acoording to a cirten condition /// </summary> /// <returns></returns> public List <BE.Test> Tests_by_terms(conditionDelegate condition) { List <BE.Test> tests = GetTests(); List <BE.Test> return_tests = new List <BE.Test>(); foreach (BE.Test test in tests) { if (condition(test)) { return_tests.Add(test); } } return(return_tests); }
static void Main(string[] args) { List <int> list = new List <int> { 12, 34, 56, 88, 33, 11 }; conditionDelegate d = condition; List <int> newList = getNewList(list, condition); // list.FindAll(c); foreach (int item in newList) { Console.WriteLine(item); } }
//---------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Test functions /// </summary> public void Add_test(BE.Test test) { List <BE.Trainee> trainees = SearchTrainee(test.Traniee_id, true, false, false); List <BE.Test> tests = SearchTest(test.Traniee_id, false, true, false); conditionDelegate condition = (x) => { return(x.Student_car_Type == test.Student_car_Type); }; //makes sure the student exists if (trainees.Count == 0) { throw new Exception("שגיאה בקבלת נתונים: התלמיד לא קיים במערכת"); } //checks if the student took at least 20 lessons if (trainees[0].Num_of_classes < BE.Configuration.Minimun_lessons) { throw new Exception("שגיאה: התלמיד לא עשה מספיק שיעורים"); } //checks if the date passed if (test.Test_time < DateTime.Now) { throw new Exception("שגיאה בקביעת טסט: התאריך עבר כבר"); } //checks if the student as a test in the last 7 days foreach (BE.Test item in tests) { if ((test.Test_time - item.Test_time) < new TimeSpan(BE.Configuration.Time_between_tests, 0, 0, 0)) { throw new Exception("שגיאה: אי אפשר לקבוע עוד מבחן תוך זמן כלכך קצר"); } } //checks the test to see if the student past the test on the car type foreach (BE.Test item in tests) { if (condition(item) && item.Grade) { throw new Exception("שגיאה: עברת כבר מבחן על סוג רכב זה"); } if (condition(item) && item.Criteria_list.Count == 0) { throw new Exception("שגיאה: עשית כבר מבחן על סוג רכב זה, חכה לתשובה"); } } Func <BE.Test, List <BE.Tester> > find_testers = Find_testers; //finds the tester that can work that day List <BE.Tester> testers = find_testers(test); //if couldnt find any testers he searches for the next time that does have testers if (testers.Count == 0) { DateTime time_new = test.Test_time; while (testers.Count == 0) { if (time_new.Hour + 1 > 14) { time_new = time_new.AddHours(19); } else { time_new = time_new.AddHours(1); } if (time_new.DayOfWeek == DayOfWeek.Friday) { time_new = time_new.AddDays(2); } test.Test_time = time_new; testers = find_testers(test); } // offers a diffrent date for the test throw new Exception("שגיאה בקביעת מבחן: לא נמצא בוחן פנוי בזמן המבוקש\nמומלץ לנסות את התאריך - " + time_new.ToString()); } //if found testers takes the first and adds the test to the list test.Tester_id = testers[0].ID; Dal.Add_test(test); }