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

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

学点儿c#语言wpf开发的更多相关文章

  1. C语言可以开发哪些项目?

    C语言是我们大多数人的编程入门语言,对其也再熟悉不过了,不过很多初学者在学习的过程中难免会出现迷茫,比如:不知道C语言可以开发哪些项目,可以应用在哪些实际的开发中--,这些迷茫也导致了我们在学习的过程 ...

  2. 工欲善其事,必先利其器 之 WPF篇: 随着开发轨迹来看高效WPF开发的工具和技巧

    之前一篇<工欲善其事,必先利其器.VS2013全攻略(安装,技巧,快捷键,插件)!> 看到很多朋友回复和支持,非常感谢,尤其是一些拍砖的喷油,感谢你们的批评,受益良多. 我第一份工作便是W ...

  3. 手机APP开发:学JAVA转安卓APP开发是不是很容易?

    成都亿合云商小编为您分享:Android开发是以Java语言为基础的,Android 虽然使用Java 语言作为开发工具,但是在实际开发中发现,还是与Java SDK 有一些不同的地方.Android ...

  4. 快速学习C语言三: 开发环境, VIM配置, TCP基础,Linux开发基础,Socket开发基础

    上次学了一些C开发相关的工具,这次再配置一下VIM,让开发过程更爽一些. 另外再学一些linux下网络开发的基础,好多人学C也是为了做网络开发. 开发环境 首先得有个Linux环境,有时候家里机器是W ...

  5. 学了C语言,如何利用CURL写一个下载程序?—用nmake编译CURL并安装

    在这一系列的前一篇文章学了C语言,如何为下载狂人写一个磁盘剩余容量监控程序?中,我们为下载狂人写了一个程序来监视磁盘的剩余容量,防止下载的东西撑爆了硬盘.可是,这两天,他又抱怨他的下载程序不好用,让我 ...

  6. 干货--微信公众平台客户端调试工具-初试WPF开发

    本工具可以由任意一个开发微信公众平台的开发者使用,虽然它本身使用WPF(C#)开发的,但是并不受你想调试的服务所用的语言的影响. 之前一直在做微信公众平台开发,客户端调试是必须做的事情,一直以来都是用 ...

  7. 跨平台、跨语言应用开发,Elements 介绍

    目录 1,Elements 介绍 2,Elements 版本 3,Elements 能干嘛 4,Elements  IDES 5,Elements 工具 1,Elements 介绍 RemObject ...

  8. C语言可以开发哪些项目?(转)

    原文地址:https://www.cnblogs.com/shiyanlou/p/6098661.html 知乎:https://www.zhihu.com/question/20564904 C语言 ...

  9. 循序渐进学.Net Core Web Api开发系列【0】:序言与目录

    一.序言 我大约在2003年时候开始接触到.NET,最初在.NET framework 1.1版本下写过代码,曾经做过WinForm和ASP.NET开发.大约在2010年的时候转型JAVA环境,这么多 ...

随机推荐

  1. jQuery实现隔行变色

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  2. clang: error: no such file or directory: 报错

    clang: error: no such file or directory: '/Users/KuaiYong/Desktop/svn/gamebox_v1.2/SettingViewContro ...

  3. oracle视图V$BH && X$BH的使用列子

    1创建一个测试表,test,并且插入10000行数据:    SQL>  create table test (id int); SQL> begin      2  for i in 1 ...

  4. Calculating simple running totals in SQL Server

    Running total for Oracle: SELECT somedate, somevalue,SUM(somevalue) OVER(ORDER BY somedate ROWS BETW ...

  5. openssl下载

    openssl的windows版本.微信支付开发中退款接口中使用到. http://pan.baidu.com/s/1c0vQy6O

  6. 快速理解Docker - 容器级虚拟化解决方案

    是什么 简单的说Docker是一个构建在LXC之上的,基于进程容器(Processcontainer)的轻量级VM解决方案 拿现实世界中货物的运输作类比, 为了解决各种型号规格尺寸的货物在各种运输工具 ...

  7. EF Code First教程-01 创建一个简单的Code First程序

    1 从nuget中搜索并添加EF 2 在app.config或web.config中添加数据库连接 <connectionStrings> <add name="conns ...

  8. Could not find class XXX referenced from method XXX.<YYY>

    Since some ADT-Version you have to set which libraries / projects should be exported too. Project-Pr ...

  9. Leetcode: Nth Digit

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...

  10. fzu 2146 Easy Game

    http://acm.fzu.edu.cn/problem.php?pid=2146  Problem 2146 Easy Game Accept: 661    Submit: 915Time Li ...