예제 #1
0
        // 根据班级id,讨论课id,学生id,经度,纬度进行签到 在方法中通过班级id,讨论课id获取当堂课发起签到的位置
        public void InsertAttendanceById(long classId, long seminarId, long userId, double longitude, double latitude)
        {
            if (seminarId.GetType().ToString() != "System.Int64" || classId.GetType().ToString() != "System.Int64" ||
                userId.GetType().ToString() != "System.Int64")
            {
                throw new ArgumentException();//id格式错误
            }
            Location location = _userDao.FindTeacherLocation(classId, seminarId);

            double tLongtitude  = (double)location.Longitude;
            double tLatitude    = (double)location.Latitude;
            double EARTH_RADIUS = 6378.137;//地球半径
            double radLat1      = rad(tLatitude);
            double radLat2      = rad(latitude);
            double a            = radLat1 - radLat2;
            double b            = rad(tLongtitude) - rad(longitude);
            double s            = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(a / 2), 2) +
                                                          Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin(b / 2), 2)));

            s = s * EARTH_RADIUS;
            s = Math.Round(s * 10000) / 10000;//s为经纬度换算出的实际距离(单位km)
            Attendance attendance = new Attendance();

            attendance.ClassInfo.Id = classId;
            attendance.Seminar.Id   = seminarId;
            if (s < 0.1 && location.Status == 1)
            {
                attendance.AttendanceStatus = AttendanceStatus.Present;
            }
            else if (s < 0.1 && location.Status == 0)
            {
                attendance.AttendanceStatus = AttendanceStatus.Late;
            }
            _userDao.AddAttendance(attendance);
        }
예제 #2
0
        // 根据班级id,讨论课id,学生id,经度,纬度进行签到 在方法中通过班级id,讨论课id获取当堂课发起签到的位置
        public void InsertAttendanceById(long classId, long seminarId, long userId, double longitude, double latitude)
        {
            if (seminarId.GetType().ToString() != "System.Int64" || classId.GetType().ToString() != "System.Int64" ||
                userId.GetType().ToString() != "System.Int64")
            {
                throw new ArgumentException();//id格式错误
            }
            Location location = _userDao.FindTeacherLocation(classId, seminarId);

            double tLongtitude = (double)location.Longitude;
            double tLatitude   = (double)location.Latitude;

            if ((int)tLongtitude == (int)longitude && (int)tLatitude == (int)latitude)
            {
                Attendance attendance = new Attendance();
                if (location.Status == 0)
                {
                    attendance.AttendanceStatus = Shared.Models.AttendanceStatus.Late;
                }
                else
                {
                    attendance.AttendanceStatus = Shared.Models.AttendanceStatus.Present;
                }
                attendance.Seminar   = _userDao.GetSeminar(seminarId);
                attendance.ClassInfo = _userDao.GetClass(classId);
                attendance.Student   = _userDao.Find(userId);
                _userDao.AddAttendance(attendance);
            }
        }