Esempio n. 1
0
        //return list of best mache of nanny
        public List <PriorityNanny> PriorityNannyList(Mother m, ref int counter)
        {
            List <PriorityNanny> p = new List <PriorityNanny>();

            int countfailure = 0;
            List <System.Threading.Thread> thds = new List <System.Threading.Thread>();

            foreach (Nanny nan in motherPriorities(m))
            {
                PriorityNanny temp = new PriorityNanny(nan);
                temp.Salary = calculateSalary(nan, m);
                if (!InternetAvailability.IsInternetAvailable())
                {
                    throw new Exception("No internet connection");
                }
                System.Threading.Thread t = new System.Threading.Thread(() =>
                {
                    try
                    {
                        temp.Distance = calculateDistance(m.Address, nan.address);
                        if (temp.Distance == 10000000)//not possible number
                        {
                            countfailure++;
                        }
                        else if (temp.Distance <= m.Max_Distance)
                        {
                            p.Add(temp);
                        }
                    }
                    catch (Exception l)
                    {
                        throw new Exception("Failed to calculate the distance!");
                    }
                });
                t.Start();
                //t.Join();
                thds.Add(t);
            }
            foreach (System.Threading.Thread t in thds)
            {
                t.Join();
            }
            p.Sort((x, y) => x.Distance.CompareTo(y.Distance));
            if (countfailure > 0)
            {
                counter = countfailure;
            }
            return(p);
        }
        private void nannysoptiongrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (isUpdate)
            {
                //nannysoptiongrid.IsEnabled = false;
                return;
            }
            List <PriorityNanny> a    = (List <PriorityNanny>)nannysoptiongrid.ItemsSource;
            PriorityNanny        temp = (from A in a
                                         where A.ID == (int)(nannysoptiongrid.SelectedItem)
                                         select A).FirstOrDefault();

            this.contr.Monthly_payment = temp.Monthly_rate;
            this.contr.Hourly_payment  = temp.Hourly_rate;
            this.contr.discount        = bl.checkForDiscunt((Nanny)temp, bl.GetMotherById(this.contr.Mother_ID));
            this.contr.salary          = temp.Salary;
            this.contr.distance        = temp.Distance;
        }
        public ContractDetails(Window f, Contract contract = null, bool isSaveable = true)
        {
            InitializeComponent();
            bl = FactoryBL.IBLInstance;
            if (isSaveable == false)
            {
                Savebutton.Visibility = Visibility.Collapsed;
            }
            var values = from Mother moth in bl.getMotherList()
                         select new { ID = moth.ID, Name = moth.Firstname + " " + moth.Lastname };

            foreach (var value in values)
            {
                listofMothers.Items.Add(value);
            }
            nannysoptiongrid.AutoGeneratingColumn += nannysoptiongrid_PriorityNannyGeneratingColumns;
            listofMothers.DisplayMemberPath        = "Name";
            listofMothers.SelectedValuePath        = "ID";
            var paymentmethods = from Enum e in Enum.GetValues(typeof(MyEnum.Paymentmethode))
                                 select new { ID = e, Name = e.ToString() };

            foreach (var value in paymentmethods)
            {
                paymentmethod.Items.Add(value);
            }
            paymentmethod.DisplayMemberPath    = "Name";
            paymentmethod.SelectedValuePath    = "ID";
            nannysoptiongrid.SelectedValuePath = "Nanny_ID";
            fr = f;
            workbegindate.DisplayDateStart = DateTime.Today;
            workenddate.DisplayDateStart   = DateTime.Today;
            //this.contr = contract;
            if (contract == null)
            {
                contr = new Contract();
            }
            //details = new ContractT(new Contract(), this);
            else
            {
                contr = contract;
            }
            //details = new ContractT(contr, this);
            isUpdate                     = false;
            this.DataContext             = contr;
            nannysoptiongrid.ItemsSource = null;
            if (contract != null)
            {
                contr    = contract;
                isUpdate = true;
                List <PriorityNanny> lst = new List <PriorityNanny>();
                Nanny         n          = (Nanny)bl.GetNannyById(contr.Nanny_ID);
                PriorityNanny temp       = new PriorityNanny(n);
                temp.Distance = contr.distance;
                temp.Salary   = contr.salary;
                lst.Add(temp);
                nannysoptiongrid.ItemsSource = lst;
                //listofChildren.Items.Add(bl.GetChildById(contr.Child_ID).name);
                //listofChildren.SelectedItem = contr.Child_ID;

                var values2 = from Child child in bl.getChildList()
                              where child.Mother_ID == contr.Mother_ID
                              select new { ID = child.ID, Name = child.name };
                foreach (var value in values2)
                {
                    listofChildren.Items.Add(value);
                }
                listofChildren.DisplayMemberPath = "Name";
                listofChildren.SelectedValuePath = "ID";
                listofChildren.SelectedValue     = contr.Child_ID;
                listofChildren.IsEnabled         = false;
            }
        }