Exemple #1
0
        private async void loadBoardList(myParam myparam)
        {

            secName.Text = myparam.boardname;
            string response;
            httputils myhttputils = new httputils();
            response = await myhttputils.GetAsync("http://bbs.jiangnan.edu.cn/rainstyle/boards_json.php?sec=" + myparam.boardid);
            System.Diagnostics.Debug.WriteLine(response);
            if (response.Contains("Error:"))
            {
                MessageDialog md = new MessageDialog("连接错误");
                await md.ShowAsync();
            }
            else
            {
                JsonObject boardlistJson = JsonObject.Parse(response);
                JsonArray boardlistArray = boardlistJson["boards"].GetArray();
                foreach (var singleboard in boardlistArray)
                {
                    string boardname = singleboard.GetObject()["name"].GetString();
                    string boardid = singleboard.GetObject()["id"].GetString();
                    ListViewItem single = new ListViewItem();
                    TextBlock singleText = new TextBlock();
                    singleText.Text = boardname;
                    singleText.Tag = boardid;
                    singleText.FontSize = 32;
                    single.Content = singleText;
                    ListView1.Items.Add(single);
                }
            }
        }
Exemple #2
0
        private async void logoutButton_Click(object sender, RoutedEventArgs e)
        {
            loadStarted();
            httputils myhttputils = new httputils();
            string message = await myhttputils.GetAsync("http://bbs.jiangnan.edu.cn/rainstyle/apilogout.php");
            loadCompleted();
            if (message == "{\"status\":0}")
            {
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

                localSettings.Values["logined"] = "false";
                MessageDialog md = new MessageDialog("注销成功");
                await md.ShowAsync();
            }
            else
            {
                MessageDialog md = new MessageDialog("连接错误");
                await md.ShowAsync();
            }
        }
        private async void loadThread()
        {
            string response;
            httputils myhttputils = new httputils();
            response = await myhttputils.GetAsync("http://bbs.jiangnan.edu.cn/rainstyle/thread_json.php?boardName=" + myparam.threadboard + "&ID=" + myparam.threadid +"&page="+pageNum);

            //string filename = myparam.threadboard + "-" + myparam.threadid + "-page1" + ".html";
            System.Diagnostics.Debug.WriteLine(response);
            //System.Diagnostics.Debug.WriteLine(filename);

            if (response.Contains("Error:"))
            {
                MessageDialog md = new MessageDialog("连接错误");
                await md.ShowAsync();
            }
            else if (response.Contains("{\"status\":0") == false)
            {
                MessageDialog md = new MessageDialog("网站数据错误");
                await md.ShowAsync();
            }
            else
            {

                JsonObject contentJson = JsonObject.Parse(response);

                JsonArray contentArray = contentJson["posts"].GetArray();
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

                string myHtml;
                myHtml = "<!DOCTYPE html>\n";
                myHtml = myHtml + "<html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\">\n";
                myHtml = myHtml + "<head>\n";
                myHtml = myHtml + "<meta charset=\"utf-8\" />\n";
                myHtml = myHtml + "<title>" + myparam.threadname + "</title>\n";
                myHtml = myHtml + "<link rel=\"stylesheet\" type=\"text/css\" href=\"ms-appx-web:///Assets/mystyle.css\" />";
                if (localSettings.Values.ContainsKey("IfOverrideLink") == true)
                {
                    Object value = localSettings.Values["IfOverrideLink"];
                    if (value.ToString() == "true")
                    {
                        myHtml = myHtml + "<script src=\"ms-appx-web:///Assets/jquery-1.11.3.min.js\" type=\"text/javascript\" language=\"javascript\"></script>";
                        myHtml = myHtml + "<script src=\"ms-appx-web:///Assets/myjs.js\" type=\"text/javascript\" language=\"javascript\"></script>";
                    }
                }

                myHtml = myHtml + "</head>\n";
                myHtml = myHtml + "<body>\n";
                myHtml = myHtml + "<h1>" + myparam.threadname + "</h1>";
                foreach (var single in contentArray)
                {
                    myHtml = myHtml + "<div>\n";
                    string singleThreadHtml = single.GetObject()["content"].GetString();
                    myHtml = myHtml + singleThreadHtml;
                    myHtml = myHtml + "</div>\n";
                    myHtml = myHtml + "<hr />\n";

                }
                myHtml = myHtml + "</body>\n";
                myHtml = myHtml + "</html>\n";
                myHtml = myHtml.Replace("js/xheditor-1.1.9/xheditor_emot/default/", "ms-appx-web:///Assets/em/");
                myHtml = myHtml.Replace("emot/jn/", "ms-appx-web:///Assets/em/");
                myHtml = myHtml.Replace("downip.php", "http://bbs.jiangnan.edu.cn/rainstyle/bbscon.php");


                if (localSettings.Values.ContainsKey("IfLoadImg") == true)
                {
                    Object value2 = localSettings.Values["IfLoadImg"];
                    if (value2.ToString() == "true")
                    {
                        if (localSettings.Values.ContainsKey("imgQuality") == true)
                        {
                            Object value3 = localSettings.Values["imgQuality"];
                            if (value3.ToString() == "origin")
                            {
                                myHtml = myHtml.Replace("/attachments/", "http://bbs.jiangnan.edu.cn/attachments/");
                            }
                            else if (value3.ToString() == "mid")
                            {
                                myHtml = myHtml.Replace("/attachments/", "https://jnrainbbs-bookjnrain.rhcloud.com/attachments-mid/");
                            }
                            else
                            {
                                myHtml = myHtml.Replace("/attachments/", "https://jnrainbbs-bookjnrain.rhcloud.com/attachments-small/");
                            }
                        }
                        else
                        {
                            myHtml = myHtml.Replace("/attachments/", "http://bbs.jiangnan.edu.cn/attachments/");
                        }                        
                    }
                }
                System.Diagnostics.Debug.WriteLine(myHtml);

                /*StorageFolder d = await ApplicationData.Current.LocalFolder.CreateFolderAsync("folder", CreationCollisionOption.OpenIfExists);
                StorageFile htmlFile = await d.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
                await FileIO.WriteTextAsync(htmlFile, myHtml);
                System.Diagnostics.Debug.WriteLine(ApplicationData.Current.LocalFolder.Path);
                Uri filepath = new Uri("ms-appdata:///local/folder/"+filename);
                //WebView1.Navigate(filepath);*/
                WebView1.NavigateToString(myHtml);


            }
        }
Exemple #4
0
        private async void clearButton_Click(object sender, RoutedEventArgs e)
        {
            loadStarted();
            httputils myhttputils = new httputils();
            string message = await myhttputils.GetAsync("http://bbs.jiangnan.edu.cn/rainstyle/apilogout.php");
            string message2= await myhttputils.GetAsync("https://jnrainbbs-bookjnrain.rhcloud.com/clear/" + accountTextBox.Text + "/" + passwdTextBox.Password);
            loadCompleted();
            if (message == "{\"status\":0}")
            {
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

                localSettings.Values["logined"] = "false";
                System.Diagnostics.Debug.WriteLine("注销成功");
            }
            if (message2 == "清除成功")
            {
                MessageDialog md = new MessageDialog("可以了");
                await md.ShowAsync();
            }
            else
            {
                MessageDialog md = new MessageDialog("连接错误或密码不正确");
                await md.ShowAsync();
            }
        }
Exemple #5
0
        private async void loginButton_Click(object sender, RoutedEventArgs e)
        {
            loadStarted();
            httputils myhttputils = new httputils();
            string response = await myhttputils.PostStringAsync("http://bbs.jiangnan.edu.cn/rainstyle/apilogin.php", "uid=" + accountTextBox.Text + "&psw=" + passwdTextBox.Password);
            System.Diagnostics.Debug.WriteLine(response);
            loadCompleted();
            if (response.Contains("Error"))
            {
                MessageDialog md = new MessageDialog("登录失败");
                await md.ShowAsync();
            }
            else if((response.Contains("status")==false))
            {
                MessageDialog md = new MessageDialog("502 Bad Gateway");
                await md.ShowAsync();
            }
            else
            {
                JsonObject myJson = JsonObject.Parse(response);
                System.Diagnostics.Debug.WriteLine(response);
                string status = myJson.GetObject()["status"].GetNumber().ToString();
                if (status == "0")
                {
                    //Windows.Web.Http.Headers.HttpResponseHeaderCollection responseHeaders = myhttputils.responseHeaders;
                    //默认登录信息保存一天,可以自行计算
                    var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

                    localSettings.Values["logined"] = "true";

                    MessageDialog md = new MessageDialog("登录成功");
                    await md.ShowAsync();
                    Frame.GoBack();
                }
                else
                {
                    MessageDialog md = new MessageDialog("登录失败");
                    await md.ShowAsync();
                }
            }
        }
        private async void loadThreadList()
        {
            ListView1.Items.Clear();
            boardName.Text = myparam.boardname;
            httputils myhttputils = new httputils();
            string response = await myhttputils.GetAsync("http://bbs.jiangnan.edu.cn/rainstyle/board_json.php?name=" + myparam.boardid + "&page="+pageNum);
            System.Diagnostics.Debug.WriteLine(response);
            if (response.Contains("Error:"))
            {
                MessageDialog md = new MessageDialog("连接错误");
                await md.ShowAsync();
            }
            else if (response.Contains("{\"status\":0") == false)
            {
                MessageDialog md = new MessageDialog("网站数据错误");
                await md.ShowAsync();
            }
            else
            {
                JsonObject contentJson = JsonObject.Parse(response);
                JsonArray contentArray = contentJson["posts"].GetArray();
                foreach (var single in contentArray)
                {
                    myParam2 myparam2 = new myParam2();
                    JsonObject myjson = single.GetObject();

                    try
                    {
                        string threadTitle = myjson["title"].GetString();
                        string threadBoard = myjson["board"].GetString();
                        string threadId=String.Empty;
                        if (myjson["id"].ValueType.ToString() == "Number")
                        {
                            threadId = myjson["id"].GetNumber().ToString();
                        }
                        else if (myjson["id"].ValueType.ToString() == "String")
                        {
                            threadId = myjson["id"].GetString();
                        }
                        myparam2.threadboard = threadBoard;
                        myparam2.threadid = threadId;
                        myparam2.threadname = threadTitle;
                        ListViewItem singleItem = new ListViewItem();
                        TextBlock singleText = new TextBlock();
                        singleText.TextWrapping = TextWrapping.Wrap;
                        singleText.Text = threadTitle;
                        singleText.Tag = myparam2;
                        singleText.FontSize = 24;
                        singleItem.Content = singleText;
                        ListView1.Items.Add(singleItem);
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(e.Message);
                    }

                }

            }
        }
        private async void sendBtn_Click(object sender, RoutedEventArgs e)
        {
            progressring1.IsActive = true;
            sendBtn.IsEnabled = false;
            cancelBtn.IsEnabled = false;
            ContentTextBox.IsEnabled = false;
            if (typeTextBlock.Text == "发表主题")
            {

                TitleTextBox.IsEnabled = false;

                httputils myhttputils = new httputils(); 
                string response = await myhttputils.PostStringAsync("http://bbs.jiangnan.edu.cn/rainstyle/apipost.php", "subject=" + TitleTextBox.Text + "&Content=" + ContentTextBox.Text + "&board=" + myparam.boardid + "&signature=-1&ID=&groupID=&reID=0");
                progressring1.IsActive = false;
                System.Diagnostics.Debug.WriteLine(response);
                JsonObject myJson = JsonObject.Parse(response);
                string status = myJson.GetObject()["status"].GetNumber().ToString();
                if (status == "0")
                {
                    MessageDialog md = new MessageDialog("发布成功");
                    await md.ShowAsync();
                    Frame.GoBack();
                }
                else if (status == "1")
                {
                    MessageDialog md = new MessageDialog("游客不能发帖!");
                    await md.ShowAsync();
                    sendBtn.IsEnabled = true;
                    cancelBtn.IsEnabled = true;
                    TitleTextBox.IsEnabled = true;
                    ContentTextBox.IsEnabled = true;
                }
                else
                {
                    MessageDialog md = new MessageDialog("发布失败");
                    await md.ShowAsync();
                    sendBtn.IsEnabled = true;
                    cancelBtn.IsEnabled = true;
                    TitleTextBox.IsEnabled = true;
                    ContentTextBox.IsEnabled = true;
                }
            }
            else
            {
                httputils myhttputils = new httputils();
                string response = await myhttputils.PostStringAsync("http://bbs.jiangnan.edu.cn/rainstyle/apipost.php", "subject=" + TitleTextBox.Text + "&Content=" + ContentTextBox.Text + "&board=" + myparam2.threadboard + "&signature=-1&ID=" + myparam2.threadid + "&groupID=" + myparam2.threadid + "&reID=" + myparam2.threadid);
                progressring1.IsActive = false;
                System.Diagnostics.Debug.WriteLine(response);
                JsonObject myJson = JsonObject.Parse(response);
                string status = myJson.GetObject()["status"].GetNumber().ToString();
                if (status == "0")
                {
                    MessageDialog md = new MessageDialog("发布成功");
                    await md.ShowAsync();
                    Frame.GoBack();
                }
                else
                {
                    MessageDialog md = new MessageDialog("发布失败");
                    await md.ShowAsync();
                    sendBtn.IsEnabled = true;
                    cancelBtn.IsEnabled = true;
                    ContentTextBox.IsEnabled = true;
                }
            }

            

        }
        private async void uploadButton_Click(object sender, RoutedEventArgs e)
        {
            if (uploadButton.Tag.ToString() == "0")
            {
                MessageDialog md = new MessageDialog("请先选择图片并压缩");
                await md.ShowAsync();
            }
            else
            {
                uploadStarted();
                httputils myhttputils = new httputils();                
                var wb = (WriteableBitmap)Image1.Source;

                //Stream fs = new System.IO.MemoryStream(wb.ToByteArray());

                //SaveToLocalFolderAsync(fs, "scaled.jpg");
                
                StorageFolder x = await  ApplicationData.Current.LocalFolder.CreateFolderAsync("images",CreationCollisionOption.OpenIfExists);      
                StorageFile file = await x.CreateFileAsync("scaled.jpg", CreationCollisionOption.ReplaceExisting);
                using (var s = await file.OpenStreamForWriteAsync())
                {
                    await wb.ToStreamAsJpeg(s.AsRandomAccessStream());
                    //s.Write(wb.ToByteArray(), 0, wb.ToByteArray().Length);
                    //s.Flush();
                }

                string response;
                //try
                //{
                response = await myhttputils.upload("http://bbs.jiangnan.edu.cn/attachments/upload.php", "ms-appdata:///local/images/scaled.jpg");
                //response = await myhttputils.upload("http://bbs.jiangnan.edu.cn/attachments/upload.php", "ms-appx:///Assets/xx.jpg");
                //}
                //catch(Exception exp){
                //    System.Diagnostics.Debug.WriteLine(exp.Message);
                //}

                if (response.Contains("上传成功"))
                {
                    MessageDialog md = new MessageDialog("上传成功");
                    await md.ShowAsync();
                    int ub, lb;
                    ub = response.IndexOf("[pic:");
                    if (response.Contains("png"))
                    {
                        lb = response.IndexOf(".png]")+5;
                    }
                    else if (response.Contains("PNG"))
                    {
                        lb = response.IndexOf(".PNG]") + 5;
                    }
                    else
                    {
                        lb = response.IndexOf(".jpg]")+5;
                    }
                    
                    response = response.Substring(ub, lb - ub);
                    newpostPage.convalue = response;

                    foreach (var page in Frame.BackStack)
                    {
                        System.Diagnostics.Debug.WriteLine(page.ToString());
                        System.Diagnostics.Debug.WriteLine(page.SourcePageType);
                        if (page.SourcePageType.ToString() == "jnrainbbs.uploadPage")
                        {

                            Frame.BackStack.Remove(page);

                        }
                    }

                    Frame.GoBack();
                }
                else
                {
                    MessageDialog md = new MessageDialog("上传失败");
                    await md.ShowAsync();
                }
                uploadCompleted();

            }
        }