public IQueryable<ViewModels.NewsViewModel> Read()
        {
            List<NewsViewModel> ret = new List<NewsViewModel>();
            var qry = db.NewsData;
            foreach (NewsData o in qry)
            {
                NewsViewModel news = new NewsViewModel();

                news.Class = o.Class;
                news.ClassStr = o.ClassStr;
                //if (o.Class == 1)
                //    news.ClassStr = "一般公告";
                //else if (o.Class == 2)
                //    news.ClassStr = "人事公告";
                //else if (o.Class == 3)
                //    news.ClassStr = "獎懲公告";
                //else if (o.Class == 4)
                //    news.ClassStr = "客服公告";
                //else if (o.Class == 5)
                //    news.ClassStr = "研發公告";
                news.Topic = o.Topic;
                news.Content = o.Content;
                news.CreateUserID = o.CreateUserID;
                news.CreateUserName = o.UserData.UserName;
                news.EndDT = o.EndDT;
                news.EndDTStr = o.EndDT.ToString("yyyy/MM/dd");
                news.NewsID = o.NewsID;
                news.Priority = o.Priority;
                if (o.Priority == 1)
                    news.PriorityStr = "一般";
                else if (o.Priority == 2)
                    news.PriorityStr = "重要";
                else if (o.Priority == 3)
                    news.PriorityStr = "極重要";
                news.StartDT = o.StartDT;
                news.StartDTStr = o.StartDT.ToString("yyyy/MM/dd");
                news.isTop = o.isTop;
                if (o.isTop == "T")
                    news.isTopStr = ("◎");
                else
                    news.isTopStr = ("");
                news.CreateDT = o.CreateDT;
                news.HasActtachment = "";
                news.OrderSeq = o.OrderSeq;
                if (db.NewsFiles.Where(x => x.NewsID == o.NewsID).Count() > 0)
                    news.HasActtachment = "@";
                ret.Add(news);
            }
            return ret.AsQueryable();
        }
        public IQueryable<ViewModels.NewsViewModel> ReadIndex(String UID, String type, DateTime StartDate, DateTime EndDate)
        {
            List<NewsViewModel> ret = new List<NewsViewModel>();
            DateTime temp = DateTime.Today.AddDays(1);
            //var qry = db.NewsData.Where(x => x.StartDT.CompareTo(temp) <= 0 && x.EndDT.CompareTo(DateTime.Today) >= 0);
            var qry = db.NewsData.Where(x => x.NewsID != 0);

            if (type == "0")  //全部公告
            {
                qry = qry.Where(x => (x.StartDT.CompareTo(temp) <= 0 && x.EndDT.CompareTo(DateTime.Today) >= 0) || (x.StartDT.CompareTo(StartDate) >= 0 && x.EndDT.CompareTo(EndDate) <= 0));
            }
            else if (type == "1") //有效公告 
            {
                qry = qry.Where(x => x.StartDT.CompareTo(temp) <= 0 && x.EndDT.CompareTo(DateTime.Today) >= 0);
            }
            else //歷史公告
            {
                qry = qry.Where(x => x.StartDT.CompareTo(StartDate) >= 0 && x.EndDT.CompareTo(EndDate) <= 0);
            }


            foreach (NewsData o in qry) {
                NewsViewModel news = new NewsViewModel();

                news.ReadStatusStr = "";
                if(db.ReadNews.Where(x=>x.UserID == UID && x.NewsID == o.NewsID).Count() == 0)
                    news.ReadStatusStr = "未閱讀";

                news.Class = o.Class;
                news.ClassStr = o.ClassStr;
                //if (o.Class == 1)
                //    news.ClassStr = "一般公告";
                //else if (o.Class == 2)
                //    news.ClassStr = "人事公告";
                //else if (o.Class == 3)
                //    news.ClassStr = "獎懲公告";
                //else if (o.Class == 4)
                //    news.ClassStr = "客服公告";
                //else if (o.Class == 5)
                //    news.ClassStr = "研發公告";
                news.Topic = o.Topic;
                news.Content = o.Content;
                news.CreateUserID = o.CreateUserID;
                news.CreateUserName = o.UserData.UserName;
                news.EndDT = o.EndDT;
                news.EndDTStr = o.EndDT.ToString("yyyy/MM/dd");
                news.NewsID = o.NewsID;
                news.Priority = o.Priority;
                if (o.Priority == 1)
                    news.PriorityStr = "一般";
                else if (o.Priority == 2)
                    news.PriorityStr = "重要";
                else if (o.Priority == 3)
                    news.PriorityStr = "極重要";
                news.StartDT = o.StartDT;
                news.StartDTStr = o.StartDT.ToString("yyyy/MM/dd");
                news.isTop = o.isTop;
                if(o.isTop=="T")
                    news.isTopStr = ("◎");
                else
                    news.isTopStr = ("");
                news.CreateDT = o.CreateDT;
                news.HasActtachment = "";
                news.OrderSeq = o.OrderSeq;
                if (db.NewsFiles.Where(x => x.NewsID == o.NewsID).Count() > 0)
                    news.HasActtachment = "@";
                ret.Add(news);
            }
            return ret.AsQueryable().OrderByDescending(x => x.isTop);
        }
        public ViewModels.NewsViewModel Read(int NewsID, String UID)
        {

            NewsViewModel news = new NewsViewModel();
            news.ReadUser="";
            news.NotReadUser="";
            var qry = db.NewsData.Where(x => x.NewsID == NewsID);

            foreach (NewsData o in qry)
            {
                var qry5 = db.UserData.OrderBy(x=>x.UserName);
                int read = 0, notread = 0;
                foreach (UserData u in qry5)
                {
                    if (db.RoleToMeunClass.Where(x => x.MenuFncID == 100 && x.RoleID == u.RoleID).Count() > 0)
                    {
                        if (db.ReadNews.Where(x => x.NewsID == NewsID && x.UserID == u.UserID).Count() > 0)
                        {
                            if (news.ReadUser == "")
                                news.ReadUser = u.UserName;
                            else
                                news.ReadUser += ", " + u.UserName;
                            read++;
                        }
                        else
                        {
                            if (news.NotReadUser == "")
                                news.NotReadUser = u.UserName;
                            else
                                news.NotReadUser += ", " + u.UserName;
                            notread++;
                        }
                    }

                }

                news.NotReadUser += "(共" + notread + "人)";
                news.ReadUser += "(共" + read + "人)";

                //var qry3 = db.ReadNews.Where(x=>x.NewsID == NewsID);
                //foreach(ReadNews g in qry3){
                //    if(news.ReadUser == "")
                //        news.ReadUser = g.UserData.UserName;
                //    else
                //        news.ReadUser += ", " + g.UserData.UserName;
                //}

                //var qry2 = db.RoleToMeunClass.Where(x=>x.MenuFncID == 100).Select(x=>x.RoleID);
                //foreach(String rID in qry2){
                //    var qry4 = db.UserData.Where(x => x.RoleID == rID);
                //    foreach (UserData g in qry4)
                //    {
                //        if (qry3.Where(x => x.UserID == g.UserID).Count() > 0)
                //            continue ;
                //        if (news.NotReadUser == "")
                //            news.NotReadUser = g.UserName;
                //        else
                //            news.NotReadUser += ", " + g.UserName;
                //    }
                //}
                


                news.NewsID = o.NewsID;

                news.Class = o.Class;
                news.ClassStr = o.ClassStr;
                //if (o.Class == 1)
                //    news.ClassStr = "一般公告";
                //else if (o.Class == 2)
                //    news.ClassStr = "人事公告";
                //else if (o.Class == 3)
                //    news.ClassStr = "獎懲公告";
                //else if (o.Class == 4)
                //    news.ClassStr = "客服公告";
                //else if (o.Class == 5)
                //    news.ClassStr = "研發公告";
                news.Topic = o.Topic;
                news.Content = o.Content;
                news.CreateUserID = o.CreateUserID;
                news.CreateUserName = o.UserData.UserName;
                news.EndDT = o.EndDT;
                news.EndDTStr = o.EndDT.ToString("yyyy/MM/dd");
                news.NewsID = o.NewsID;
                news.Priority = o.Priority;
                if (o.Priority == 1)
                    news.PriorityStr = "一般";
                else if (o.Priority == 2)
                    news.PriorityStr = "重要";
                else if (o.Priority == 3)
                    news.PriorityStr = "極重要";
                news.StartDT = o.StartDT;
                news.StartDTStr = o.StartDT.ToString("yyyy/MM/dd");
                news.isTop = o.isTop;
                news.CreateDT = o.CreateDT;

            }
            return news;
        }
        public IQueryable<ViewModels.NewsViewModel> ReadNoContent(String type, DateTime StartDate, DateTime EndDate)
        {
            List<NewsViewModel> ret = new List<NewsViewModel>();
            //var qry = db.NewsData;
            DateTime temp = DateTime.Today.AddDays(1);
            var qry = db.NewsData.Where(x => x.NewsID != 0);

            if (type == "0")  //全部公告
            {
                qry = qry.Where(x => (x.StartDT.CompareTo(temp) <= 0 && x.EndDT.CompareTo(DateTime.Today) >= 0) || (x.StartDT.CompareTo(StartDate) >= 0 && x.EndDT.CompareTo(EndDate) <= 0));
            }
            else if (type == "1") //有效公告 
            {
                qry = qry.Where(x => x.StartDT.CompareTo(temp) <= 0 && x.EndDT.CompareTo(DateTime.Today) >= 0);
            }
            else //歷史公告
            {
                qry = qry.Where(x => x.StartDT.CompareTo(StartDate) >= 0 && x.EndDT.CompareTo(EndDate) <= 0);
            }

            foreach (NewsData o in qry)
            {
                NewsViewModel news = new NewsViewModel();

                news.NotReadUserNum = 0;
                news.ReadUserNum = 0;

                var qry5 = db.UserData.OrderBy(x => x.UserName);
                int read = 0, notread = 0;
                foreach (UserData u in qry5)
                {
                    if (db.RoleToMeunClass.Where(x => x.MenuFncID == 100 && x.RoleID == u.RoleID).Count() > 0)
                    {
                        if (db.ReadNews.Where(x => x.NewsID == o.NewsID && x.UserID == u.UserID).Count() > 0)
                        {
                            news.ReadUserNum++;
                        }
                        else
                        {                            
                            news.NotReadUserNum++;
                        }
                    }

                }

                


                news.Class = o.Class;
                news.ClassStr = o.ClassStr;
                //if (o.Class == 1)
                //    news.ClassStr = "一般公告";
                //else if (o.Class == 2)
                //    news.ClassStr = "人事公告";
                //else if (o.Class == 3)
                //    news.ClassStr = "獎懲公告";
                //else if (o.Class == 4)
                //    news.ClassStr = "客服公告";
                //else if (o.Class == 5)
                //    news.ClassStr = "研發公告";
                news.Topic = o.Topic;
                //news.Content = o.Content;
                news.CreateUserID = o.CreateUserID;
                news.CreateUserName = o.UserData.UserName;
                news.EndDT = o.EndDT;
                news.EndDTStr = o.EndDT.ToString("yyyy/MM/dd");
                news.NewsID = o.NewsID;
                news.Priority = o.Priority;
                if (o.Priority == 1)
                    news.PriorityStr = "一般";
                else if (o.Priority == 2)
                    news.PriorityStr = "重要";
                else if (o.Priority == 3)
                    news.PriorityStr = "極重要";
                news.StartDT = o.StartDT;
                news.StartDTStr = o.StartDT.ToString("yyyy/MM/dd");
                news.isTop = o.isTop;
                if (o.isTop == "T")
                    news.isTopStr = ("◎");
                else
                    news.isTopStr = ("");
                news.CreateDT = o.CreateDT;
                news.HasActtachment = "";
                news.OrderSeq = o.OrderSeq;
                if (db.NewsFiles.Where(x => x.NewsID == o.NewsID).Count() > 0)
                    news.HasActtachment = "@";
                ret.Add(news);
            }
            return ret.AsQueryable();
        }