/// <summary>
        /// Method to create a single event to check for values in the timetracking node.
        ///This contains all the dates that the employees has work.
        /// </summary>
        public void loadUserTimes()
        {
            DatabaseReference user_ttNode = time_trackingNode.GetChild(employee_details.Id);

            user_ttNode.ObserveSingleEvent(DataEventType.Value, (snapshot) =>
            {
                try
                {
                    var data = snapshot.GetValue <NSDictionary>();
                    //Gets the keys for each user in the table.
                    var keys = data.Keys;

                    double employee_payment = 0;
                    //Adds the key to the temporary list.
                    employee_details.FortNightWorkedTime = new TimeSpan(0, 0, 0);
                    foreach (var time in data.Values)
                    {
                        //Gets the information found in the time_tracking node. This also calculates the worked time of the user and stores it into
                        //a list
                        timeTracking            = new TimeTrackingClass();
                        timeTracking.End_Date   = DateTime.Parse(time.ValueForKey(new NSString("end_date")).ToString());
                        timeTracking.Start_Date = DateTime.Parse(time.ValueForKey(new NSString("start_date")).ToString());


                        DateTime currentDate = DateTime.Now;
                        if (currentDate.Month == timeTracking.Start_Date.Month)
                        {
                            if (timeTracking.Start_Date.Day < 15 && currentDate.Day < 15)
                            {
                                TimeSpan worked_time = (timeTracking.End_Date - timeTracking.Start_Date);
                                employee_payment    += Math.Round(worked_time.TotalHours, 2);
                                employee_details.FortNightWorkedTime += worked_time;
                                lst_timetracking.Add(timeTracking);
                            }


                            if (currentDate.Day > 15 && timeTracking.Start_Date.Day > 15)
                            {
                                TimeSpan worked_time = (timeTracking.End_Date - timeTracking.Start_Date);
                                employee_payment    += Math.Round(worked_time.TotalHours, 2);
                                employee_details.FortNightWorkedTime += worked_time;
                                lst_timetracking.Add(timeTracking);
                            }
                        }
                    }
                    employee_payment            = 0;
                    employee_details.WorkedTime = lst_timetracking;
                    lst_timetracking            = new List <TimeTrackingClass>();
                    TableView.ReloadData();
                }
                catch (Exception ex) {}
            });
        }
Пример #2
0
        public bool GetTimeTrackingClass(ref TimeTrackingClass ttc, bool refreshClass = false)
        {
            bool isFill = false;

            if (_ttc == null || refreshClass)
            {
                _ttc   = new TimeTrackingClass();
                isFill = true;
            }
            ttc = _ttc;

            return(isFill);
        }
        /// <summary>
        /// Method to create a single event to check for values in the timetracking node.
        ///This contains all the dates that the employees has work.
        /// </summary>
        public void loadUserTimes()
        {
            time_trackingNode.ObserveSingleEvent(DataEventType.Value, (snapshot) =>
            {
                var data = snapshot.GetValue <NSDictionary>();
                //Gets the keys for each user in the table.
                var keys = data.Keys;
                key_list = new List <string>();
                foreach (var key in keys)
                {
                    double employee_payment = 0;
                    //Looks for the key in the data received from the event and returns it as a dictionary.
                    var user_data = data.ValueForKey(new NSString(key.ToString())) as NSDictionary;
                    //Looks for the key in the users list. Returns an index, if it not found this should return a -1
                    var index = lst_Employees.FindIndex(x => x.Id.Contains(key.ToString()));

                    if (index != -1)
                    {
                        //Looks for the user and returns it as an Employee class object
                        Employee temp_employee = lst_Employees.Find(x => x.Id.Contains(key.ToString()));
                        //Adds the key to the temporary list.
                        key_list.Add(key.ToString());
                        var autogen_keys   = user_data.Keys;
                        var autogen_values = user_data.Values;
                        temp_employee.FortNightWorkedTime = new TimeSpan(0, 0, 0);
                        foreach (var time in autogen_values)
                        {
                            //Gets the information found in the time_tracking node. This also calculates the worked time of the user and stores it into
                            //a list
                            timeTracking            = new TimeTrackingClass();
                            timeTracking.End_Date   = DateTime.Parse(time.ValueForKey(new NSString("end_date")).ToString());
                            timeTracking.Start_Date = DateTime.Parse(time.ValueForKey(new NSString("start_date")).ToString());


                            DateTime currentDate = DateTime.Now;
                            if (currentDate.Month == timeTracking.Start_Date.Month)
                            {
                                if (timeTracking.Start_Date.Day < 15 && currentDate.Day < 15)
                                {
                                    TimeSpan worked_time = (timeTracking.End_Date - timeTracking.Start_Date);
                                    employee_payment    += Math.Round(worked_time.TotalHours, 2);
                                    temp_employee.FortNightWorkedTime += worked_time;
                                    lst_timetracking.Add(timeTracking);
                                }


                                if (currentDate.Day > 15 && timeTracking.Start_Date.Day > 15)
                                {
                                    TimeSpan worked_time = (timeTracking.End_Date - timeTracking.Start_Date);
                                    employee_payment    += Math.Round(worked_time.TotalHours, 2);
                                    temp_employee.FortNightWorkedTime += worked_time;
                                    lst_timetracking.Add(timeTracking);
                                }
                            }
                        }
                        temp_employee.WorkedTime = lst_timetracking;
                        //Finds the employee in the current index and update the information of the employee
                        lst_Employees[index] = temp_employee;
                        employee_payment     = 0;
                        lst_timetracking     = new List <TimeTrackingClass>();
                    }
                }
                TableView.ReloadData();
            });
        }