学点儿c#语言wpf开发
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();
}
}
}
学点儿c#语言wpf开发的更多相关文章
- C语言可以开发哪些项目?
C语言是我们大多数人的编程入门语言,对其也再熟悉不过了,不过很多初学者在学习的过程中难免会出现迷茫,比如:不知道C语言可以开发哪些项目,可以应用在哪些实际的开发中--,这些迷茫也导致了我们在学习的过程 ...
- 工欲善其事,必先利其器 之 WPF篇: 随着开发轨迹来看高效WPF开发的工具和技巧
之前一篇<工欲善其事,必先利其器.VS2013全攻略(安装,技巧,快捷键,插件)!> 看到很多朋友回复和支持,非常感谢,尤其是一些拍砖的喷油,感谢你们的批评,受益良多. 我第一份工作便是W ...
- 手机APP开发:学JAVA转安卓APP开发是不是很容易?
成都亿合云商小编为您分享:Android开发是以Java语言为基础的,Android 虽然使用Java 语言作为开发工具,但是在实际开发中发现,还是与Java SDK 有一些不同的地方.Android ...
- 快速学习C语言三: 开发环境, VIM配置, TCP基础,Linux开发基础,Socket开发基础
上次学了一些C开发相关的工具,这次再配置一下VIM,让开发过程更爽一些. 另外再学一些linux下网络开发的基础,好多人学C也是为了做网络开发. 开发环境 首先得有个Linux环境,有时候家里机器是W ...
- 学了C语言,如何利用CURL写一个下载程序?—用nmake编译CURL并安装
在这一系列的前一篇文章学了C语言,如何为下载狂人写一个磁盘剩余容量监控程序?中,我们为下载狂人写了一个程序来监视磁盘的剩余容量,防止下载的东西撑爆了硬盘.可是,这两天,他又抱怨他的下载程序不好用,让我 ...
- 干货--微信公众平台客户端调试工具-初试WPF开发
本工具可以由任意一个开发微信公众平台的开发者使用,虽然它本身使用WPF(C#)开发的,但是并不受你想调试的服务所用的语言的影响. 之前一直在做微信公众平台开发,客户端调试是必须做的事情,一直以来都是用 ...
- 跨平台、跨语言应用开发,Elements 介绍
目录 1,Elements 介绍 2,Elements 版本 3,Elements 能干嘛 4,Elements IDES 5,Elements 工具 1,Elements 介绍 RemObject ...
- C语言可以开发哪些项目?(转)
原文地址:https://www.cnblogs.com/shiyanlou/p/6098661.html 知乎:https://www.zhihu.com/question/20564904 C语言 ...
- 循序渐进学.Net Core Web Api开发系列【0】:序言与目录
一.序言 我大约在2003年时候开始接触到.NET,最初在.NET framework 1.1版本下写过代码,曾经做过WinForm和ASP.NET开发.大约在2010年的时候转型JAVA环境,这么多 ...
随机推荐
- webView、scrollView、TableView,为了防止滚动时出现偏移,底部黑框问题等
if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) {self.automaticallyAd ...
- imx6 android5.1 打开 调试串口
imx6的工板烧录android 5.1的镜像,uboot中能使用debug口,kernel,文件系统中不能使用debug口. 打开kenel和文件系统debug口方法,在uboot的bootargs ...
- 我的工具箱之VNC
下载地址:http://pan.baidu.com/s/1bovEoZ9 这个工具可以连接到Linux并进行可视化操作. 如何搭建VNC环境请见 在centOS上安装VNC 2016年2月26日11: ...
- PHP 开放JSON格式接口实例
转化JSON文件 <?php function arrayRecursive(&$array, $function, $apply_to_keys_also = false) { ; ) ...
- windows开发hadoop文件系统权限错误
org.apache.hadoop.security.AccessControlException: Permission denied: user=Administrator, access=WRI ...
- 这是我定位的Bug
https://github.com/danielgindi/ios-charts/issues/406
- crsctl stat res -t 和 crsctl stat res -init -t
11.2.0.2的grid infrastructure中crsctl stat res命令不再显示如ora.cssd.ora.ctssd.ora.diskmon等基础资源的信息.但是查看这些基础资源 ...
- 关键字 self
self 总是指向调用方法的对象. self总是代表当前类的对象.当它出现在某个方法体中时,它所代表的对象是不确定的,但它的类型是确定的,它所代表的是当前类的实例对象: 当这个方法被调用时,它所代表的 ...
- linux_x86_64 blat安装
blatSrc35.zip下载地址:http://users.soe.ucsc.edu/~kent/src/ 对于下载好的源代码安装包blatSrc35.zip,需进行编译,安装过程如下: 1.用un ...
- linux 命令之 insmod
man insmod: INSMOD(8) insmod INSMOD(8) NAME insmod - Simple program to insert a module into the Linu ...