Example #1
0
        //My logic in adding attendance in a month for all employees
        //And it takes too long to generate :)
        public void AddOneMonthAttendance(string _date)
        {
            string           _month       = Convert.ToDateTime(_date).Month.ToString();
            string           _year        = Convert.ToDateTime(_date).Year.ToString();
            MyConverters     attDate      = new MyConverters();
            var              dbConn       = new SQLiteConnection(App.DB_PATH);
            List <Employees> myCollection = dbConn.Table <Employees>().ToList <Employees>();
            ObservableCollection <Employees> EmployeesList = new ObservableCollection <Employees>(myCollection);
            int empCount = EmployeesList.Count;

            DateTime tempDate = DateTime.Now;

            tempDate = Convert.ToDateTime(attDate.AttendanceDate(_month, "1", _year));
            int tempDays = 0;

            for (int i = 0; i < tempDate.Day; i++)
            {
                tempDate = tempDate.AddDays(1);
                tempDays = i;
            }

            for (int e = 0; e < empCount; e++)
            {
                for (int i = 0; i <= tempDays; i++)
                {
                    //using (var dbConn = new SQLiteConnection(App.DB_PATH))
                    //{
                    Attendance newAtt = new Attendance(attDate.AttendanceDate(_month, (i + 1).ToString(), _year),
                                                       EmployeesList[e].Name, true);
                    dbConn.RunInTransaction(() => { dbConn.Insert(newAtt); });
                    //}
                }
            }
        }
Example #2
0
        //Generate Attendance for New Employee
        public void GenerateAttendance(string _empName)
        {
            MyConverters attDate = new MyConverters();

            if (DateTime.Now.Day <= 15)
            {
                for (int i = 0; i < 15; i++)
                {
                    using (var dbConn = new SQLiteConnection(App.DB_PATH))
                    {
                        Attendance newAtt = new Attendance(attDate.AttendanceDate(DateTime.Now.Month.ToString(), (i + 1).ToString(), DateTime.Now.Year.ToString()),
                                                           _empName, true);
                        dbConn.RunInTransaction(() => { dbConn.Insert(newAtt); });
                    }
                }
            }
            else
            {
                DateTime tempDate = DateTime.Now;
                tempDate = Convert.ToDateTime(attDate.AttendanceDate(tempDate.Month.ToString(), "1", tempDate.Year.ToString()));
                int tempDays = 0;
                //Get the last number of the Month
                for (int i = 0; i < tempDate.Day; i++)
                {
                    tempDate = tempDate.AddDays(1);
                    tempDays = i;
                }
                for (int i = 0; i <= (tempDays - 15); i++)
                {
                    using (var dbConn = new SQLiteConnection(App.DB_PATH))
                    {
                        Attendance newAtt = new Attendance(attDate.AttendanceDate(DateTime.Now.Month.ToString(), (i + 16).ToString(), DateTime.Now.Year.ToString()),
                                                           _empName, true);
                        dbConn.RunInTransaction(() => { dbConn.Insert(newAtt); });
                    }
                }
            }
        }