private async void autoLogin()
        {
            try
            {
                if (!StaticData.IsLogin && Settings.GetValueOrDefault("username", "") != "" && Settings.GetValueOrDefault("password", "") != "")
                {
                    var httpHelp = new HttpHelp();
                    httpHelp.parameters.Add("username", Settings.GetValueOrDefault("username", ""));
                    httpHelp.parameters.Add("password", Settings.GetValueOrDefault("password", ""));
                    using (var stream = await httpHelp.PostSetCookie(
                               string.Format(StaticData.login,
                                             Settings.GetValueOrDefault("username", ""),
                                             Settings.GetValueOrDefault("password", ""))))
                    {
                        var json   = new DataContractJsonSerializer(typeof(loginresult));
                        var result = json.ReadObject(stream) as loginresult;
                        if (result.success)
                        {
                            StaticData.UserName = result.username;
                            StaticData.UserImg  = result.img;
                            StaticData.IsLogin  = true;
                            denglu.Visibility   = Visibility.Collapsed;
                            zhuce.Visibility    = Visibility.Collapsed;
                            name.Text           = result.username;
                            userlogo.Source     = new BitmapImage(new Uri(StaticData.UserImg, UriKind.RelativeOrAbsolute));
                            zhuxiao.Visibility  = Visibility.Visible;

                            await getunRead();
                        }
                    }
                }
            }
            catch { }
        }
        async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!StaticData.IsLogin && Settings.GetValueOrDefault("username", "") != "" && Settings.GetValueOrDefault("password", "") != "")
                {
                    HttpHelp httpHelp = new HttpHelp();
                    httpHelp.parameters.Add("username", Settings.GetValueOrDefault("username", ""));
                    httpHelp.parameters.Add("password", Settings.GetValueOrDefault("password", ""));
                    using (var stream = await httpHelp.PostSetCookie(StaticData.login))
                    {
                        DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(loginresult));
                        var result = json.ReadObject(stream) as loginresult;
                        if (result.success)
                        {
                            StaticData.UserName = result.username;
                            StaticData.UserImg  = result.img;
                            StaticData.IsLogin  = true;
                            denglu.Visibility   = Visibility.Collapsed;
                            name.Text           = result.username;
                            userlogo.Source     = new BitmapImage(new Uri(StaticData.UserImg, UriKind.RelativeOrAbsolute));
                            zhuxiao.Visibility  = Visibility.Visible;

                            await getunRead();
                        }
                    }
                }
                if ((DateTime.Now.Hour == 23 && DateTime.Now.Minute > 58) || (DateTime.Now.Hour == 0 && DateTime.Now.Minute < 2))
                {
                    ad.Text = "骗你的啦~";
                }
            }
            catch { }
        }
Example #3
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(tbusername.Text))
            {
                MessageBox.Show("用户名不能为空"); return;
            }
            if (string.IsNullOrEmpty(tbpassword.Password))
            {
                MessageBox.Show("密码不能为空"); return;
            }

            indicator.IsVisible = true;
            var httpHelp = new HttpHelp();

            httpHelp.parameters.Add("username", tbusername.Text);
            httpHelp.parameters.Add("password", tbpassword.Password);
            using (var stream = await httpHelp.PostSetCookie(string.Format(StaticData.login, tbusername.Text, tbpassword.Password)))
            {
                if (stream != null)
                {
                    var json   = new DataContractJsonSerializer(typeof(loginresult));
                    var result = json.ReadObject(stream) as loginresult;
                    if (result.success)
                    {
                        Settings.AddOrUpdateValue("username", tbusername.Text);
                        Settings.AddOrUpdateValue("password", tbpassword.Password);
                        StaticData.UserName = result.username;
                        StaticData.UserImg  = result.img;
                        StaticData.IsLogin  = true;
                        if (NavigationService.CanGoBack)
                        {
                            NavigationService.GoBack();
                        }
                    }
                    else if (!string.IsNullOrEmpty(result.result))
                    {
                        MessageBox.Show(result.result);
                    }
                    else
                    {
                        MessageBox.Show("未知异常");
                    }
                }
                else
                {
                    MessageBox.Show("未知异常");
                }
            }

            indicator.IsVisible = false;
        }