コード例 #1
0
        public ActionResult UserCompletedCourseList(String SearchItem = "0")
        {
            DateTime startdate = DateTime.Now;
            DateTime LastDate  = DateTime.Now;
            UserList user      = new UserList();

            switch (SearchItem)
            {
            //Today
            case ("1"):
                startdate = DateTime.Today;
                LastDate  = DateTime.Now;
                break;

            //Yesterday
            case ("2"):
                startdate = DateTime.Today.AddDays(-1);
                LastDate  = DateTime.Today;
                break;

            //ThisWeek
            case ("3"):
                startdate = user.StartOfWeek(DateTime.Now);
                LastDate  = DateTime.Now;
                break;

            //ThisMonth
            case ("4"):
                startdate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
                LastDate  = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month));
                break;

            //ThisQuarter
            case ("5"):
                var f = (decimal)(DateTime.Now.Month - 1) / 3;
                var s = (int)Math.Floor(f) * 3 + 1;
                var e = (int)(Math.Floor(f) + 1) * 3;
                startdate = new DateTime(DateTime.Now.Year, s, 1);
                LastDate  = new DateTime(DateTime.Now.Year, e, DateTime.DaysInMonth(DateTime.Now.Year, e));
                break;

            //This Year
            case ("6"):
                var year = DateTime.Now.Year;
                startdate = new DateTime(year, 1, 1);
                LastDate  = new DateTime(year, 12, DateTime.DaysInMonth(year, 12));
                break;

            //LastWeek
            case ("7"):
                startdate = user.StartOfWeek(DateTime.Now).AddDays(-7);
                LastDate  = user.EndOfWeek(DateTime.Now).AddDays(-7);
                break;

            //LastTwoWeeks
            case ("8"):
                startdate = user.StartOfWeek(DateTime.Now).AddDays(-14);
                LastDate  = user.EndOfWeek(DateTime.Now).AddDays(-7);
                break;

            //LastMonth
            case ("9"):
                var g = DateTime.Today.AddMonths(-1);
                startdate = new DateTime(g.Year, g.Month, 1);
                LastDate  = new DateTime(g.Year, g.Month, DateTime.DaysInMonth(g.Year, g.Month));
                break;

            //LastTwoMonths
            case ("10"):
                var b = DateTime.Today.AddMonths(-2);
                startdate = new DateTime(b.Year, b.Month, 1);
                LastDate  = new DateTime(b.Year, (b.AddMonths(1)).Month, DateTime.DaysInMonth(b.Year, (b.AddMonths(1)).Month));
                break;

            //PastSixMonths
            case ("11"):
                startdate = DateTime.Now.AddMonths(-6);
                LastDate  = DateTime.Now;
                break;

            //LastYear
            case ("12"):
                var yr = DateTime.Now.Year - 1;
                startdate = new DateTime(yr, 1, 1);
                LastDate  = new DateTime(yr, 12, 31);
                break;

            default:
                startdate = new DateTime(1900, 1, 1);
                LastDate  = DateTime.Now;
                break;
            }

            bool iscompleted = Convert.ToBoolean(1);
            var  query       = (from a in db.video_usuarios
                                where (a.CourseCompletedDate <= LastDate || (a.CourseCompletedDate == null && startdate == new DateTime(1900, 1, 1))) && (a.CourseCompletedDate >= startdate || (a.CourseCompletedDate == null && startdate == new DateTime(1900, 1, 1))) && a.vdeleted == "0" && a.IsCompleted == iscompleted
                                select a).ToList();
            List <UserList> list = new List <UserList>();

            foreach (var i in query)
            {
                list.Add(new UserList
                {
                    id       = i.ncodusua,
                    Name     = i.vfullname,
                    password = i.vcon,
                    //creationDate = i.vcreation,
                    active       = i.vestusuario,
                    Email        = i.vemail,
                    creationDate = i.CourseCompletedDate,
                });
            }
            list = list.OrderByDescending(l => l.creationDate).ToList();
            return(PartialView("/Views/Admin/_UserCompletedCourse.cshtml", list));
        }
コード例 #2
0
        public List <UserList> GetreportBysearch(String SearchItem = "0", int page = 0, string sort = "")
        {
            if (page > 0 || !string.IsNullOrEmpty(sort))
            {
                return(Session["reportlist"] as List <UserList>);
            }
            else
            {
                DateTime startdate = DateTime.Now;
                DateTime LastDate  = DateTime.Now;
                UserList user      = new UserList();

                switch (SearchItem)
                {
                //Today
                case ("1"):
                    startdate = DateTime.Today;
                    LastDate  = DateTime.Now;
                    break;

                //Yesterday
                case ("2"):
                    startdate = DateTime.Today.AddDays(-1);
                    LastDate  = DateTime.Today;
                    break;

                //ThisWeek
                case ("3"):
                    startdate = user.StartOfWeek(DateTime.Now);
                    LastDate  = DateTime.Now;
                    break;

                //ThisMonth
                case ("4"):
                    startdate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
                    LastDate  = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month));
                    break;

                //ThisQuarter
                case ("5"):
                    var f = (decimal)(DateTime.Now.Month - 1) / 3;
                    var s = (int)Math.Floor(f) * 3 + 1;
                    var e = (int)(Math.Floor(f) + 1) * 3;
                    startdate = new DateTime(DateTime.Now.Year, s, 1);
                    LastDate  = new DateTime(DateTime.Now.Year, e, DateTime.DaysInMonth(DateTime.Now.Year, e));
                    break;

                //This Year
                case ("6"):
                    var year = DateTime.Now.Year;
                    startdate = new DateTime(year, 1, 1);
                    LastDate  = new DateTime(year, 12, DateTime.DaysInMonth(year, 12));
                    break;

                //LastWeek
                case ("7"):
                    startdate = user.StartOfWeek(DateTime.Now).AddDays(-7);
                    LastDate  = user.EndOfWeek(DateTime.Now).AddDays(-7);
                    break;

                //LastTwoWeeks
                case ("8"):
                    startdate = user.StartOfWeek(DateTime.Now).AddDays(-14);
                    LastDate  = user.EndOfWeek(DateTime.Now).AddDays(-7);
                    break;

                //LastMonth
                case ("9"):
                    var g = DateTime.Today.AddMonths(-1);
                    startdate = new DateTime(g.Year, g.Month, 1);
                    LastDate  = new DateTime(g.Year, g.Month, DateTime.DaysInMonth(g.Year, g.Month));
                    break;

                //LastTwoMonths
                case ("10"):
                    var b = DateTime.Today.AddMonths(-2);
                    startdate = new DateTime(b.Year, b.Month, 1);
                    LastDate  = new DateTime(b.Year, (b.AddMonths(1)).Month, DateTime.DaysInMonth(b.Year, (b.AddMonths(1)).Month));
                    break;

                //PastSixMonths
                case ("11"):
                    startdate = DateTime.Now.AddMonths(-6);
                    LastDate  = DateTime.Now;
                    break;

                //LastYear
                case ("12"):
                    var yr = DateTime.Now.Year - 1;
                    startdate = new DateTime(yr, 1, 1);
                    LastDate  = new DateTime(yr, 12, 31);
                    break;

                default:
                    startdate = new DateTime(1900, 1, 1);
                    LastDate  = DateTime.Now;
                    break;
                }

                var query = (from a in db.video_usuarios
                             where (a.vcreation <= LastDate) && (a.vcreation >= startdate) && a.vdeleted == "0"
                             select a).ToList();
                List <UserList> list = new List <UserList>();
                foreach (var i in query)
                {
                    list.Add(new UserList
                    {
                        id           = i.ncodusua,
                        Name         = i.vfullname,
                        password     = i.vcon,
                        creationDate = i.vcreation,
                        active       = i.vestusuario,
                        Email        = i.vemail
                    });
                }
                list = list.OrderByDescending(l => l.creationDate).ToList();
                Session["reportlist"] = list;
                return(list);
            }
        }