public static async Task<HotFeed> GetHotFeed(int type_id, string article_id)
        {
            var vault = new Windows.Security.Credentials.PasswordVault();
            var credentialList = vault.FindAllByResource(resourceName);
            credentialList[0].RetrievePassword();
            List<KeyValuePair<String, String>> paramList = new List<KeyValuePair<String, String>>();
            //paramList.Add(new KeyValuePair<string, string>("stuNum", appSetting.Values["stuNum"].ToString()));
            //paramList.Add(new KeyValuePair<string, string>("idNum", appSetting.Values["idNum"].ToString()));
            paramList.Add(new KeyValuePair<string, string>("stuNum", credentialList[0].UserName));
            paramList.Add(new KeyValuePair<string, string>("idNum", credentialList[0].Password.ToString()));
            paramList.Add(new KeyValuePair<string, string>("type_id", type_id.ToString()));
            paramList.Add(new KeyValuePair<string, string>("article_id", article_id.ToString()));
            string response = await NetWork.getHttpWebRequest(api, paramList);
            Debug.WriteLine(response);
            try
            {
                if (response != "" || response != "[]")
                {
                    JObject bbddfeeds = JObject.Parse(response);
                    if (bbddfeeds["status"].ToString() == "200")
                    {
                        JObject feed = (JObject)bbddfeeds["data"][0];
                        HotFeed f = new HotFeed();
                        f.GetAttributes(feed);
                        return f;
                    }
                }
            }
            catch (Exception) { }
            return null;

        }
        public static async Task <HotFeed> GetHotFeed(int type_id, string article_id)
        {
            var vault          = new Windows.Security.Credentials.PasswordVault();
            var credentialList = vault.FindAllByResource(resourceName);

            credentialList[0].RetrievePassword();
            List <KeyValuePair <String, String> > paramList = new List <KeyValuePair <String, String> >();

            //paramList.Add(new KeyValuePair<string, string>("stuNum", appSetting.Values["stuNum"].ToString()));
            //paramList.Add(new KeyValuePair<string, string>("idNum", appSetting.Values["idNum"].ToString()));
            paramList.Add(new KeyValuePair <string, string>("stuNum", credentialList[0].UserName));
            paramList.Add(new KeyValuePair <string, string>("idNum", credentialList[0].Password.ToString()));
            paramList.Add(new KeyValuePair <string, string>("type_id", type_id.ToString()));
            paramList.Add(new KeyValuePair <string, string>("article_id", article_id.ToString()));
            string response = await NetWork.getHttpWebRequest(api, paramList);

            Debug.WriteLine(response);
            try
            {
                if (response != "" || response != "[]")
                {
                    JObject bbddfeeds = JObject.Parse(response);
                    if (bbddfeeds["status"].ToString() == "200")
                    {
                        JObject feed = (JObject)bbddfeeds["data"][0];
                        HotFeed f    = new HotFeed();
                        f.GetAttributes(feed);
                        return(f);
                    }
                }
            }
            catch (Exception) { }
            return(null);
        }
Пример #3
0
 public static async Task <List <HotFeed> > GetHot(int type = 0, int page = 0, int size = 15, int typeid = 5)
 {
     //TODO:未登陆时 不添加参数stuNum和idNum
     return(await Task.Run(async() =>
     {
         List <KeyValuePair <String, String> > paramList = new List <KeyValuePair <String, String> >();
         try
         {
             var vault = new Windows.Security.Credentials.PasswordVault();
             var credentialList = vault.FindAllByResource(resourceName);
             credentialList[0].RetrievePassword();
             if (credentialList.Count > 0)
             {
                 //paramList.Add(new KeyValuePair<string, string>("stuNum", appSetting.Values["stuNum"].ToString()));
                 //paramList.Add(new KeyValuePair<string, string>("idNum", appSetting.Values["idNum"].ToString()));
                 paramList.Add(new KeyValuePair <string, string>("stuNum", credentialList[0].UserName));
                 paramList.Add(new KeyValuePair <string, string>("idNum", credentialList[0].Password));
             }
         }
         catch
         {
         }
         paramList.Add(new KeyValuePair <string, string>("page", page.ToString()));
         paramList.Add(new KeyValuePair <string, string>("size", size.ToString()));
         if (typeid != 0)
         {
             paramList.Add(new KeyValuePair <string, string>("type_id", typeid.ToString()));
         }
         string response = await NetWork.getHttpWebRequest(feedsapi[type], paramList);
         //response = Utils.ConvertUnicodeStringToChinese(response);
         List <HotFeed> feeds = new List <HotFeed>();
         try
         {
             if (response != "" || response != "[]")
             {
                 JArray hotfeed = JArray.Parse(response);
                 for (int i = 0; i < hotfeed.Count; i++)
                 {
                     JObject hot = (JObject)hotfeed[i];
                     if (hot["status"].ToString() == "200")
                     {
                         JObject data = (JObject)hot["data"];
                         HotFeed f = new HotFeed();
                         f.GetAttributes(data);
                         feeds.Add(f);
                     }
                 }
             }
         }
         catch (Exception) { }
         return feeds;
     }));
 }
        protected override DataTemplate SelectTemplateCore(System.Object item, DependencyObject container)
        {
            FrameworkElement element = container as FrameworkElement;

            if (element != null && item != null)
            {
                HotFeed h = item as HotFeed;
                if (h != null && h.content.contentbase != null)
                {
                    return(nBBDDTemplate);
                }
                else
                {
                    return(BBDDTemplate);
                }
            }
            return(null);
        }
Пример #5
0
        private async void liskButton_Click(object sender, RoutedEventArgs e)
        {
            //TODO:未登陆时 不能点赞
            //if (appSetting.Values.ContainsKey("idNum"))
            try
            {
                var vault          = new Windows.Security.Credentials.PasswordVault();
                var credentialList = vault.FindAllByResource(resourceName);
                credentialList[0].RetrievePassword();
                if (credentialList.Count > 0)
                {
                    var b = sender as Button;

                    string num_id = b.TabIndex.ToString();
                    Debug.WriteLine(num_id);
                    Debug.WriteLine("id " + num_id.Substring(2));
                    string like_num = "";
                    try
                    {
                        if (int.Parse(num_id[0].ToString()) < 5) //hot
                        {
                            HotFeed hotfeed = ViewModel.HotFeeds.First(p => p.article_id.Equals(num_id.Substring(2)));
                            if (hotfeed.is_my_Like == "true" || hotfeed.is_my_Like == "True")
                            {
                                like_num = await CommunityFeedsService.setPraise(hotfeed.type_id, num_id.Substring(2), false);

                                if (like_num != "")
                                {
                                    hotfeed.like_num   = like_num;
                                    hotfeed.is_my_Like = "false";
                                    if (ViewModel.BBDD.Count(p => p.id.Equals(num_id.Substring(2))) != 0)
                                    {
                                        BBDDFeed s = ViewModel.BBDD.First(p => p.id.Equals(num_id.Substring(2)));
                                        if (s != null)
                                        {
                                            s.like_num   = like_num;
                                            s.is_my_like = "false";
                                        }
                                    }
                                }
                            }
                            else
                            {
                                like_num = await CommunityFeedsService.setPraise(hotfeed.type_id, num_id.Substring(2), true);

                                if (like_num != "")
                                {
                                    hotfeed.like_num   = like_num;
                                    hotfeed.is_my_Like = "true";
                                    if (ViewModel.BBDD.Count(p => p.id.Equals(num_id.Substring(2))) != 0)
                                    {
                                        BBDDFeed s = ViewModel.BBDD.First(p => p.id.Equals(num_id.Substring(2)));
                                        if (s != null)
                                        {
                                            s.like_num   = like_num;
                                            s.is_my_like = "true";
                                        }
                                    }
                                }
                            }
                        }
                        else if (num_id[0] == '5') //bbdd
                        {
                            BBDDFeed bbddfeed = ViewModel.BBDD.First(p => p.id.Equals(num_id.Substring(2)));
                            if (bbddfeed.is_my_like == "true" || bbddfeed.is_my_like == "True")
                            {
                                like_num = await CommunityFeedsService.setPraise(bbddfeed.type_id, num_id.Substring(2), false);

                                if (like_num != "")
                                {
                                    bbddfeed.like_num   = like_num;
                                    bbddfeed.is_my_like = "false";
                                    if (ViewModel.HotFeeds.Count(p => p.article_id.Equals(num_id.Substring(2))) != 0)
                                    {
                                        HotFeed h = ViewModel.HotFeeds.First(p => p.article_id.Equals(num_id.Substring(2)));
                                        if (h != null)
                                        {
                                            h.like_num   = like_num;
                                            h.is_my_Like = "false";
                                        }
                                    }
                                }
                            }
                            else
                            {
                                like_num = await CommunityFeedsService.setPraise(bbddfeed.type_id, num_id.Substring(2), true);

                                if (like_num != "")
                                {
                                    bbddfeed.like_num   = like_num;
                                    bbddfeed.is_my_like = "true";
                                    if (ViewModel.HotFeeds.Count(p => p.article_id.Equals(num_id.Substring(2))) != 0)
                                    {
                                        HotFeed h = ViewModel.HotFeeds.First(p => p.article_id.Equals(num_id.Substring(2)));
                                        if (h != null)
                                        {
                                            h.like_num   = like_num;
                                            h.is_my_Like = "true";
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Debug.WriteLine("点赞异常");
                    }
                }
                else
                {
                    var msgPopup = new Data.loginControl("您还没有登录 无法点赞~");
                    msgPopup.LeftClick  += (s, c) => { Frame rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(LoginPage)); };
                    msgPopup.RightClick += (s, c) => { Debug.WriteLine("您可以先去社区逛一逛~"); };
                    msgPopup.ShowWIndow();
                }
            }
            catch
            {
                var msgPopup = new Data.loginControl("您还没有登录 无法点赞~");
                msgPopup.LeftClick  += (s, c) => { Frame rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(LoginPage)); };
                msgPopup.RightClick += (s, c) => { Debug.WriteLine("您可以先去社区逛一逛~"); };
                msgPopup.ShowWIndow();
            }
        }
Пример #6
0
        private async void LikeButton_Click(object sender, RoutedEventArgs e)
        {
            //TODO:未登陆时 不能点赞
            //if (appSetting.Values.ContainsKey("idNum"))
            try
            {
                var vault          = new Windows.Security.Credentials.PasswordVault();
                var credentialList = vault.FindAllByResource(resourceName);
                credentialList[0].RetrievePassword();
                if (credentialList.Count > 0)
                {
                    var    b      = sender as Button;
                    string num_id = b.TabIndex.ToString();
                    Debug.WriteLine(num_id);
                    Debug.WriteLine("id " + num_id.Substring(2));
                    string like_num = "";
                    if (ViewModel.BBDD != null)
                    {
                        BBDDFeed bbddfeed = ViewModel.BBDD;
                        if (bbddfeed.is_my_like == "true" || bbddfeed.is_my_like == "True")
                        {
                            like_num = await CommunityFeedsService.setPraise(bbddfeed.type_id, num_id.Substring(2), false);

                            if (like_num != "")
                            {
                                bbddfeed.like_num   = like_num;
                                bbddfeed.is_my_like = "false";
                                //if (args is HotFeed)
                                //{
                                //    HotFeed h = args as HotFeed;
                                //    h.like_num = like_num;
                                //    h.is_my_Like = "false";
                                //}
                            }
                        }
                        else
                        {
                            like_num = await CommunityFeedsService.setPraise(bbddfeed.type_id, num_id.Substring(2), true);

                            if (like_num != "")
                            {
                                bbddfeed.like_num   = like_num;
                                bbddfeed.is_my_like = "true";
                                //if (args is HotFeed)
                                //{
                                //    HotFeed h = args as HotFeed;
                                //    h.like_num = like_num;
                                //    h.is_my_Like = "true";
                                //}
                            }
                        }
                    }

                    if (ViewModel.hotfeed != null)
                    {
                        HotFeed hotfeed = ViewModel.hotfeed;
                        if (hotfeed.is_my_Like == "true" || hotfeed.is_my_Like == "True")
                        {
                            like_num = await CommunityFeedsService.setPraise(hotfeed.type_id, num_id.Substring(2), false);

                            if (like_num != "")
                            {
                                hotfeed.like_num   = like_num;
                                hotfeed.is_my_Like = "false";
                                //if (args is HotFeed)
                                //{
                                //    HotFeed h = args as HotFeed;
                                //    h.like_num = like_num;
                                //    h.is_my_Like = "false";
                                //}
                            }
                        }
                        else
                        {
                            like_num = await CommunityFeedsService.setPraise(hotfeed.type_id, num_id.Substring(2), true);

                            if (like_num != "")
                            {
                                hotfeed.like_num   = like_num;
                                hotfeed.is_my_Like = "true";
                                //if (args is HotFeed)
                                //{
                                //    HotFeed h = args as HotFeed;
                                //    h.like_num = like_num;
                                //    h.is_my_Like = "true";
                                //}
                            }
                        }
                    }
                }
                else
                {
                    var msgPopup = new Data.loginControl("您还没有登录 无法点赞~");
                    msgPopup.LeftClick  += (s, c) => { Frame rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(LoginPage)); };
                    msgPopup.RightClick += (s, c) => { new MessageDialog("您可以先四处逛一逛~"); };
                    msgPopup.ShowWIndow();
                }
            }
            catch
            {
                var msgPopup = new Data.loginControl("您还没有登录 无法点赞~");
                msgPopup.LeftClick  += (s, c) => { Frame rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(LoginPage)); };
                msgPopup.RightClick += (s, c) => { new MessageDialog("您可以先四处逛一逛~"); };
                msgPopup.ShowWIndow();
            }
        }
        public static async Task<List<HotFeed>> GetHot(int type = 0, int page = 0, int size = 15, int typeid = 5)
        {
            //TODO:未登陆时 不添加参数stuNum和idNum
            return await Task.Run(async () =>
           {
               List<KeyValuePair<String, String>> paramList = new List<KeyValuePair<String, String>>();
               try
               {

                   var vault = new Windows.Security.Credentials.PasswordVault();
                   var credentialList = vault.FindAllByResource(resourceName);
                   credentialList[0].RetrievePassword();
                   if (credentialList.Count > 0)
                   {
                       //paramList.Add(new KeyValuePair<string, string>("stuNum", appSetting.Values["stuNum"].ToString()));
                       //paramList.Add(new KeyValuePair<string, string>("idNum", appSetting.Values["idNum"].ToString()));
                       paramList.Add(new KeyValuePair<string, string>("stuNum", credentialList[0].UserName));
                       paramList.Add(new KeyValuePair<string, string>("idNum", credentialList[0].Password));
                   }
               }
               catch
               {

               }
               paramList.Add(new KeyValuePair<string, string>("page", page.ToString()));
               paramList.Add(new KeyValuePair<string, string>("size", size.ToString()));
               if (typeid != 0)
                   paramList.Add(new KeyValuePair<string, string>("type_id", typeid.ToString()));
               string response = await NetWork.getHttpWebRequest(feedsapi[type], paramList);
               //response = Utils.ConvertUnicodeStringToChinese(response);
               List<HotFeed> feeds = new List<HotFeed>();
               try
               {
                   if (response != "" || response != "[]")
                   {
                       JArray hotfeed = JArray.Parse(response);
                       for (int i = 0; i < hotfeed.Count; i++)
                       {
                           JObject hot = (JObject)hotfeed[i];
                           if (hot["status"].ToString() == "200")
                           {
                               JObject data = (JObject)hot["data"];
                               HotFeed f = new HotFeed();
                               f.GetAttributes(data);
                               feeds.Add(f);
                           }
                       }
                   }
               }
               catch (Exception) { }
               return feeds;
           });
        }