Exemplo n.º 1
0
        public ActionResult Index(string id, string resourceType)
        {
            DemandModel model = new DemandModel();

            //页码,总数重置
            int page = 1;
            if (!string.IsNullOrEmpty(id))
            {
                Int32.TryParse(id, out page);
            }
            int allCount = 0;
            //model.Demands = demandService.GetDemands(20, page, out allCount);//每页显示20条

            DemandParameters parameters = new DemandParameters();
            parameters.PageCount = 20;
            parameters.PageIndex = page;
            parameters.ResourceType = resourceType;

            model.Demands = demandService.GetDemandsByParameters(parameters, out allCount);

            model.ResourceType = resourceType;
            //分页
            if (model.Demands != null && model.Demands.Count > 0)
            {
                model.PageIndex = page;//当前页数
                model.PageSize = 20;//每页显示多少条
                model.PageStep = 10;//每页显示多少页码
                model.AllCount = allCount;//总条数
                if (model.AllCount % model.PageSize == 0)
                {
                    model.PageCount = model.AllCount / model.PageSize;
                }
                else
                {
                    model.PageCount = model.AllCount / model.PageSize + 1;
                }
            }

            return View(model);
        }
Exemplo n.º 2
0
        public List<Demand> SelectDemandsForWeChatPush(SqlConnection conn, DemandParameters parameters)
        {
            List<Demand> result = new List<Demand>();
            SqlParameter[] sqlParameters = new SqlParameter[]
            {
                new SqlParameter("@Locations", parameters.Locations),
                new SqlParameter("@Categories", parameters.Categories),
                new SqlParameter("@InsertTime", parameters.InsertTime),
                new SqlParameter("@Keywords", parameters.Keywords),
                new SqlParameter("@PageCount", parameters.PageCount)
            };

            Dictionary<string, DataTable> dts;
            dts = DBHelper.GetMuiltiDataFromDB(conn, sp_DemandSelectForWeChatPush, sqlParameters);
            result = DBHelper.DataTableToList<Demand>(dts["0"]);

            return result;
        }
Exemplo n.º 3
0
        public List<Demand> SelectDemandsByParameters(DemandParameters parameters, out int count, SqlConnection conn)
        {
            List<Demand> result = null;

            object Province = DBNull.Value;
            object City = DBNull.Value;
            object Area = DBNull.Value;
            object ResourceType = DBNull.Value;
            object ResourceTypeId = DBNull.Value;
            object StartBudget = DBNull.Value;
            object EndBudget = DBNull.Value;
            object StartTime = DBNull.Value;
            object EndTime = DBNull.Value;

            #region 转化DBNull
            if (!string.IsNullOrEmpty(parameters.Province))
            {
                Province = parameters.Province;
            }
            if (!string.IsNullOrEmpty(parameters.City))
            {
                City = parameters.City;
            }
            if (!string.IsNullOrEmpty(parameters.Area))
            {
                Area = parameters.Area;
            }
            if (!string.IsNullOrEmpty(parameters.ResourceType))
            {
                ResourceType = parameters.ResourceType;
            }
            if (!string.IsNullOrEmpty(parameters.ResourceTypeId))
            {
                ResourceTypeId = parameters.ResourceTypeId;
            }
            if (!string.IsNullOrEmpty(parameters.StartBudget))
            {
                StartBudget = parameters.StartBudget;
            }
            if (!string.IsNullOrEmpty(parameters.EndBudget))
            {
                EndBudget = parameters.EndBudget;
            }
            if (!string.IsNullOrEmpty(parameters.StartTime))
            {
                StartTime = parameters.StartTime;
            }
            if (!string.IsNullOrEmpty(parameters.EndTime))
            {
                EndTime = parameters.EndTime;
            }
            #endregion

            SqlParameter[] sqlParameters = new SqlParameter[]
            {
                new SqlParameter("@PageCount", parameters.PageCount),
                new SqlParameter("@PageIndex", parameters.PageIndex),
                new SqlParameter("@Province", Province),
                new SqlParameter("@City", City),
                new SqlParameter("@Area", Area),
                new SqlParameter("@ResourceType", ResourceType),
                new SqlParameter("@ResourceTypeId", ResourceTypeId),
                new SqlParameter("@StartBudget", StartBudget),
                new SqlParameter("@EndBudget", EndBudget),
                new SqlParameter("@StartTime", StartTime),
                new SqlParameter("@EndTime", EndTime)
            };

            Dictionary<string, DataTable> dts;
            dts = DBHelper.GetMuiltiDataFromDB(conn, sp_DemandSelectByParameters, sqlParameters);
            count = Int32.Parse(dts["0"].Rows[0][0].ToString());
            result = DBHelper.DataTableToList<Demand>(dts["1"]);
            return result;
        }
Exemplo n.º 4
0
        public List<Demand> SelectDemandsForWeChatPush(List<DemandSubscriptionDetail> subscriptionDetails, DateTime lastPushTime, int pageCount = 0)
        {
            List<Demand> result = new List<Demand>();

            var conn = DBHelper.GetSqlConnection();
            try
            {
                conn.Open();

                var categories = string.Empty;
                var locations = string.Empty;
                var keywords = string.Empty;

                foreach (var detail in subscriptionDetails)
                {
                    if (detail.SubscriptionType == DemandSubscriptionType.Area.ToString())
                    {
                        locations += detail.SubscriptionValue + ",";
                    }
                    else if (detail.SubscriptionType == DemandSubscriptionType.Category.ToString())
                    {
                        categories += detail.SubscriptionValue + ",";
                    }
                    else if (detail.SubscriptionType == DemandSubscriptionType.Keywords.ToString())
                    {
                        keywords += detail.SubscriptionValue + ",";
                    }
                    else
                    {
                        // nothing to do.
                    }
                }

                // Removes last comma.
                if (categories.Length > 0)
                {
                    categories = categories.Substring(0, categories.Length - 1);
                }
                if (locations.Length > 0)
                {
                    locations = locations.Substring(0, locations.Length - 1);
                }
                if (keywords.Length > 0)
                {
                    keywords = keywords.Substring(0, keywords.Length - 1);
                }

                DemandParameters parameters = new DemandParameters()
                {
                    Categories = categories,
                    Locations = locations,
                    Keywords = keywords,
                    InsertTime = lastPushTime,
                    PageCount = pageCount
                };

                result = demandDao.SelectDemandsForWeChatPush(conn, parameters);
            }
            catch (Exception e)
            {
                LogService.Log("SelectDemandsForWeChatPush", e.ToString());
            }
            finally
            {
                conn.Close();
            }

            return result;
        }
Exemplo n.º 5
0
        /// <summary>
        /// 据城市查询需求列表
        /// </summary>
        public List<Demand> GetDemandsByParameters(DemandParameters parameters, out int count)
        {
            List<Demand> result = new List<Demand>();

            count = 0;
            var conn = DBHelper.GetSqlConnection();
            try
            {
                conn.Open();
                int tempCount = 0;
                result = demandDao.SelectDemandsByParameters(parameters, out tempCount, conn);
                count = tempCount;
            }
            catch (Exception e)
            {
                LogService.Log("查询需求列表", e.ToString());
            }
            finally
            {
                conn.Close();
            }

            return result;
        }
Exemplo n.º 6
0
        public ActionResult Index(string page, string LastResourceType, string ResourceType, string ResourceTypeId, string area, string starttime, string endtime, string startbudget, string endbudget)
        {
            DemandModel model = new DemandModel();

            string city = string.Empty;
            if (!string.IsNullOrEmpty(CurrentCityId))
            {
                city = CurrentCityId;
            }
            int tempPage = 1;
            if (!string.IsNullOrEmpty(page))
            {
                Int32.TryParse(page, out tempPage);
            }

            // 每次更换需求列别需要重置需求类型选中的值
            if (string.IsNullOrEmpty(ResourceType))
            {
                ResourceTypeId = string.Empty;
            }
            if (!(LastResourceType ?? string.Empty).Equals(ResourceType, StringComparison.CurrentCultureIgnoreCase))
            {
                ResourceTypeId = string.Empty;
            }
            LastResourceType = ResourceType;

            //-------------------------------初始化页面参数(不含分页)-----------------------
            model.PageIndex = tempPage;
            model.LastResourceType = LastResourceType ?? string.Empty;
            model.ResourceType = ResourceType ?? string.Empty;
            model.ResourceTypeId = ResourceTypeId ?? string.Empty;
            model.City = city;
            model.Area = area ?? string.Empty;
            model.StartBudget = startbudget ?? string.Empty;
            model.EndBudget = endbudget ?? string.Empty;
            model.StartTime = starttime ?? string.Empty;
            model.EndTime = endtime ?? string.Empty;

            //-------------------------------初始化SQL查询参数-----------------------
            DemandParameters parameters = new DemandParameters();
            parameters.PageCount = 10;//每页显示10条 (与下面保持一致)
            parameters.PageIndex = tempPage;
            parameters.ResourceType = model.ResourceType;
            parameters.ResourceTypeId = model.ResourceTypeId;
            parameters.City = model.City;
            parameters.Area = model.Area;
            parameters.StartBudget = model.StartBudget;
            parameters.EndBudget = model.EndBudget;
            parameters.StartTime = model.StartTime;
            parameters.EndTime = model.EndTime;

            if (!string.IsNullOrEmpty(city))
            {
                model.Areas = cityService.GetAreasByCityId(city, true);
            }

            int allCount = 0;
            //需求分页列表,每页10条
            model.Demands = demandService.GetDemandsByParameters(parameters, out allCount);
            //分页
            if (model.Demands != null && model.Demands.Count > 0)
            {
                model.PageIndex = tempPage;//当前页数
                model.PageSize = 10;//每页显示多少条
                model.PageStep = 5;//每页显示多少页码
                model.AllCount = allCount;//总条数
                if (model.AllCount % model.PageSize == 0)
                {
                    model.PageCount = model.AllCount / model.PageSize;
                }
                else
                {
                    model.PageCount = model.AllCount / model.PageSize + 1;
                }
            }

            return View(model);
        }