コード例 #1
0
        public ActionResult GetTaskData(bool _search, string sidx, string sord, int page, int rows)
        {
            this.Internationalization();

            try
            {
                int curUserId = 0;
                TugDataEntities db = new TugDataEntities();
                curUserId = Session.GetDataFromSession<int>("userid");
                    if (_search == true)
                    {
                        string s = Request.QueryString["filters"];
                        return Json(new { code = Resources.Common.ERROR_CODE, message = Resources.Common.ERROR_MESSAGE }, JsonRequestBehavior.AllowGet);
                    }
                    else
                    {
                        var objs = db.proc_needapprove(curUserId).OrderByDescending(u=>u.LastUpDate).ToList();
                        //List<NeedApprove> objs = new List<NeedApprove>();
                        //SqlParameter[] prams = new SqlParameter[1];
                        //prams[0] = new SqlParameter("@userID", curUserId);
                        //objs = db.Database.SqlQuery<NeedApprove>("exec dbo.proc_needapprove @userID", prams).ToList();
                        int totalRecordNum = objs.Count;
                        if (page != 0 && totalRecordNum % rows == 0) page -= 1;
                        int pageSize = rows;
                        int totalPageNum = (int)Math.Ceiling((double)totalRecordNum / pageSize);
                        //var page_objs = objs.Skip((page - 1) * rows).Take(rows).ToList();
                        var jsonData = new { page = page, records = totalRecordNum, total = totalPageNum, rows = objs };
                        return Json(jsonData, JsonRequestBehavior.AllowGet);
                    }
            }
            catch (Exception)
            {
                return Json(new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE });
            }
        }