首发:个人博客,更新&纠错&回复

visual studio 2015,界面越来越漂亮了。

比起swift和python啥的,还是c#外观上更像java,windows的界面编程,wpf的方式跟android等编程也蛮像,声明式的界面定义,界面和controller类当然绑定,总之玩着很爽就是了。

现在在想的问题是想个啥主题做着……

下面的代码是学习关键点时练的,老规矩,界面交互+web请求+数据库访问——

using MySql.Data.MySqlClient;
using qdf_test_wpf_1;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication2
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

private void button_Click(object sender, RoutedEventArgs e)
        {

//进行web请求
            HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create("http://427studio.net/api/blog");
            httpRequest.Timeout = 2000;
            httpRequest.Method = "GET";
            HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
            StreamReader sr = new StreamReader(httpResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("utf-8"));
            string result = sr.ReadToEnd();
            result = result.Replace("\r", "").Replace("\n", "").Replace("\t", "");
            int status = (int)httpResponse.StatusCode;
            sr.Close();

//解析json
            List<Person> ps = JSON.parse<List<Person>>(result);
            foreach (Person p in ps)
            {
                Console.WriteLine(p.title);
            }
            jsonCount.Content = "js数组长度:" + ps.Count();

//数据库连接
            string str = "Server=那啥;User ID=那啥;Password=那啥;Database=那啥;CharSet=那啥;";
            MySqlConnection conn = new MySqlConnection(str);//实例化链接
            conn.Open();//开启连接
            string strcmd = "select id, name from admin_user";
            MySqlCommand cmd = new MySqlCommand(strcmd, conn);
            MySqlDataReader reader = cmd.ExecuteReader();
            int rowCount = 0;
            while (reader.Read())
            {
                String title = reader.GetString("name");
                //Console.WriteLine(title);

rowCount++;
            }
            dbCount.Content = "数据库记录行数:" + rowCount;
            reader.Close();
            conn.Close();

//文件系统
            FileStream fs = new FileStream("test.txt", FileMode.OpenOrCreate);
            StreamWriter sw = new StreamWriter(fs);
            sw.Write("由wpf程序写入!");
            sw.Close();
        }
    }
}

长期欢迎项目合作机会介绍,项目收入10%用于酬谢介绍人。新浪微博:@冷镜,QQ:908789432

最新文章

  1. Entity Framework 6 Recipes 2nd Edition(10-9)译 -&gt; 在多对多关系中为插入和删除使用存储过程
  2. c 头文件&lt;ctype.h&gt;(二)
  3. EasyUI的combobox控件使用onchange 问题
  4. 更改yum源地址
  5. ubuntu16.04安装重启后显示黑屏
  6. 【NOIP2013】货车运输
  7. Android app Splash页的替代方案
  8. 部分常用Express方法详解
  9. 用LinqToExcel处理有标题表格的数据
  10. 【CF 189A Cut Ribbon】dp
  11. SQL Server中锁与事务隔离级别
  12. 利用数据库触发器让字段与自增长Id相关联
  13. [MySQL]在安装windows版MySQL时遇到过如下问题Error Nr.1045和Error.Nr.2003,相应解决办法如下
  14. golang debug调试
  15. springboot实现国际化
  16. Cordova学习
  17. tensorflow训练了10万次,运行完毕,对这个word2vec终于有点感觉了
  18. 20145226夏艺华 《Java程序设计》第9周学习总结
  19. Android存储Json到本地,和读取本地Json
  20. Jquery Json解析

热门文章

  1. JMeter学习-005-JMeter 主要组件概要介绍及执行顺序
  2. http://blog.csdn.net/yunhua_lee/article/details/52710894
  3. LeetCode Lowest Common Ancestor of a Binary Tree
  4. python字典循环小点
  5. uwsgi 启动脚本 每隔三小时重启
  6. Redis一些基本的操作
  7. MVC 上传文件并展示
  8. ADO.net 扩展属性
  9. php面向对象(OOP)编程完全教程
  10. 如何不切换windows登陆用户,更换用户名访问共享文件夹