Exemplo n.º 1
0
 private void  getData(PostModel postModel,PostTrendTable trend)
 {
      string name = trend.Describe.Substring(trend.Describe.LastIndexOf(' ')+1);
      string Num = trend.Describe.Substring(6);
      Num = Num.Substring(0, Num.IndexOf(' '));
      if (Constant.getDic_Danwei().Keys.Contains(name))
      {
          postModel.Describe = "Post " + Num + " " + Constant.getDic_Danwei()[name] + " " + name;
      }
      else
      {
          if (Int32.Parse(Num) > 1) postModel.Describe += "s";
      }
      
         Affect  affect;
         if (!Constant.getDictionary_Affect().ContainsKey(name))
         {
             affect = Constant.getDictionary_Affect()["other"];
         }
         else
         {
             affect = Constant.getDictionary_Affect()[name];
         }
         if (affect.carbon_emissions != 0)
         {
             postModel.Co2 = affect.carbon_emissions * Int32.Parse(Num);
         }
         if (affect.electricity != 0)
         {
             postModel.Electric = affect.electricity *Int32.Parse(Num);
         }
         if (affect.gasoline != 0)
         {
             postModel.Forest = affect.gasoline * Int32.Parse(Num); 
         }
        
         list_PostModel.Add(postModel);
 }
Exemplo n.º 2
0
        private void dealWithPostTrend()
        {
            List<PostTrendTable> list_PostTrends = new List<PostTrendTable>();
            foreach (int i in list_FriendId)
            {
                // TimeSpan span=24*nowTime.Subtract(DateTime.Parse(c.Time)).Days+nowTime.Subtract(DateTime.Parse(c.Time)).Hours;
                foreach (PostTrendTable trends in db.PostTrends)
                {
                    int days = nowTime.Subtract(DateTime.Parse(trends.Time)).Duration().Days;
                    int hour = nowTime.Subtract(DateTime.Parse(trends.Time)).Duration().Hours;
                    DateTime d = DateTime.Parse(trends.Time);
                    int hours = 24 * nowTime.Subtract(DateTime.Parse(trends.Time)).Duration().Days + nowTime.Subtract(DateTime.Parse(trends.Time)).Duration().Hours;
                    //if (trends.UserId == i && hours <= 200)
                        list_PostTrends.Add(trends);
                }
            }
            foreach (PostTrendTable trend in db.PostTrends)
            {
              //  UserTable user = db.Users.First(c => c.Id == trend.UserId);
                PostModel postModel = new PostModel()
                {
                    Describe = trend.Describe,
                    Name = trend.Name,
                    PostAffect = trend.PostAffect,
                    Time = trend.Time,
                    UserId=trend.UserId,
                };
                //string s = trend.Describe.Substring(0, trend.Describe.LastIndexOf(' ') - 1);
                //string name = trend.Describe.Substring(trend.Describe.LastIndexOf(' ') + 1);
                //if (Constant.getDic_Danwei().Keys.Contains(name))
                //{
                //    name = Constant.getDic_Danwei()[name] + " " + name;
                //}
                //postModel.Describe = s + " " + name;
               getData(postModel, trend);

               
            }
            
        }