Ejemplo n.º 1
0
        public async Task <ActionResult> Results(int pageNo = 0)
        {
            if (pageNo < 1)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var results = this.HttpContext.Session.GetSearchResults(_cache);

            if (results == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var systemData = await _cache.GetSystemDataAsync();

            var pageSize = systemData.PageSizeSearchResults;

            if (pageSize <= 0)
            {
                pageSize = 50;
            }

            int numberOfPages = (results.Count / pageSize);

            if (numberOfPages * pageSize < results.Count)
            {
                numberOfPages++;
            }

            var rowsToShow = new List <SearchResultRow>();

            for (int i = 0; (i < pageSize) && ((((pageNo - 1) * pageSize) + i) < results.Count); i++)
            {
                rowsToShow.Add(results[((pageNo - 1) * pageSize) + i]);
            }

            var viewData = new SearchResultsData()
            {
                NumberOfPages      = numberOfPages,
                PageNo             = pageNo,
                PageRows           = rowsToShow,
                NumberOfResultRows = results.Count,
                SearchParameters   = this.HttpContext.Session.GetSearchTerms(_cache)
            };

            return(View(viewData));
        }
Ejemplo n.º 2
0
        private SearchResultsData Search(SearchEntityData model)
        {
            SearchResultsData searchResultsData = new SearchResultsData();
            string            entityName        = model.Entity;
            string            key = Common.GetKeyByEntityName(entityName);
            int total             = 0;

            try
            {
                DataTable dt = Common.GetRecordFromPage(entityName, key, model.Page, model.PageSize, out total);
                searchResultsData.MsgDesc = "success";
                searchResultsData.MsgID   = "000";

                SearchResultsData.Result2 result2 = new SearchResultsData.Result2();

                result2.Page     = Convert.ToString(model.Page);
                result2.Pagesize = Convert.ToString(model.PageSize);
                result2.Total    = Convert.ToString(total);

                int allpage = 0;
                if (model.PageSize != 0)
                {
                    allpage = (total / model.PageSize);
                    allpage = ((total % model.PageSize) != 0 ? allpage + 1 : allpage);
                    allpage = (allpage == 0 ? 1 : allpage);
                }

                result2.TotalPage = Convert.ToString(allpage);
                result2.DataList  = dt;
                if ((model.PageSize * model.Page + dt.Rows.Count) < total)
                {
                    result2.IsMore = "Y";
                }
                else
                {
                    result2.IsMore = "N";
                }
                searchResultsData.Result = result2;
            }
            catch (Exception ex)
            {
                searchResultsData.MsgDesc = "Fail message:" + ex.Message;
                searchResultsData.MsgDesc = "004";
            }

            return(searchResultsData);
        }
Ejemplo n.º 3
0
        public string Operater(string applydata)
        {
            ResultData        resultData        = new ResultData();
            SearchResultsData searchResultsData = new SearchResultsData();

            if (string.IsNullOrEmpty(applydata))
            {
                resultData.MsgDesc = "applydata is not empty";
                resultData.MsgId   = "001";
            }
            else
            {
                var model = JsonConvert.DeserializeObject <ApplyDataPar>(applydata);
                if (model == null)
                {
                    resultData.MsgDesc = "applydata is error";
                    resultData.MsgId   = "002";
                }
                else
                {
                    if (model.Username != Common.ApplyDataUserName || model.Password != Common.ApplyDataUserPwd)
                    {
                        resultData.MsgDesc = "username is error or password is error";
                        resultData.MsgId   = "003";
                    }
                    else
                    {
                        string type = model.Type;
                        if (type == "C")
                        {
                            resultData = Add(model);
                        }
                        else if (type == "U")
                        {
                            resultData = Update(model);
                        }
                        else if (type == "D")
                        {
                            resultData = Delete(model);
                        }
                    }
                }

                //search
                var searchModel = JsonConvert.DeserializeObject <SearchEntityData>(applydata);
                if (searchModel == null)
                {
                    searchResultsData.MsgDesc = "applydata is error";
                    searchResultsData.MsgID   = "002";
                }
                else
                {
                    if (searchModel.Username != Common.ApplyDataUserName || searchModel.Password != Common.ApplyDataUserPwd)
                    {
                        searchResultsData.MsgDesc = "username is error or password is error";
                        searchResultsData.MsgID   = "003";
                    }
                    else
                    {
                        string type = searchModel.Type;
                        if (type == "R")
                        {
                            searchResultsData = Search(searchModel);
                            return(JsonConvert.SerializeObject(searchResultsData));
                        }
                    }
                }
            }
            return(JsonConvert.SerializeObject(resultData));
        }