为项目组写了几个Howto的Case。

本文描述了一个用C#实现类的XML序列化及反序列化。
功能是生成一个类的实例,然后序列化成XML文件形式。
或者将一个已经序列化成文件的XML反序列化成类的实例。

为了充分展示Framework功能,在一个类里面嵌入另一个类,并且XML属性字段混杂。

Student.cs
[code=’c#’]
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace XMLHowto
{
[Serializable,XmlRoot(Namespace=”http://its.hpcc.tongji.edu.cn”)]
public class Student
{
[XmlElement]
public long Number;
[XmlElement]
public string Name;
[XmlElement]
public bool enabled;
[XmlElement]
public Dorm dorm;
}
}
[/code]

Dorm.cs
[code=’c#’]
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace XMLHowto
{
[Serializable, XmlRoot(Namespace = “http://its.hpcc.tongji.edu.cn”)]
public class Dorm
{
[XmlAttribute]
public string Name;
[XmlElement]
public string Number;
}
}
[/code]

Program.cs
[code=’c#’]
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace XMLHowto
{
class Program
{
static void Main(string[] args)
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Student));

//序列化
FileStream fs1 = new FileStream(“./student.xml”, FileMode.Create, FileAccess.Write);
Student student = new Student();
Dorm dorm = new Dorm();

dorm.Name = “der drom”;
dorm.Number = “16-501-1”;

student.dorm = dorm;
student.enabled = true;
student.Number = 222222;
student.Name = “maojun”;

xmlSerializer.Serialize(fs1, student);

//反序列化
FileStream fs2 = new FileStream(“./student2.xml”, FileMode.Open, FileAccess.Read);
Student student2 = (Student)xmlSerializer.Deserialize(fs2);
}
}
}
[/code]

下载:用Visual Studio 2008打开
http://download.nocoo.us/Download/Archive/CSharpHowto/XML.rar

黄昏突然彩霞满天。听说还有双拱彩虹,不过我是迎着太阳的方向,没看见。

[singlepic=14523,500,375]

[singlepic=14524,500,375]

[singlepic=14525,500,375]

为项目组写了几个Howto的Case。

本文描述了一个用C#实现的简单的SQL Server查询。
功能是每次执行插入一行记录,然后输出全部记录。

Program.cs
[code=’c#’]
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;

namespace SQLServerHowto
{
class Program
{
static void Main(string[] args)
{
SqlConnection myConnection = new SqlConnection(“Data Source=itsdbserver;user id=its;password=its;database=ITSTestDB”);
myConnection.Open();

string sql = “insert into news (news) values (@value)”;
SqlCommand sc = new SqlCommand(sql, myConnection);
SqlParameter param = new SqlParameter(“value”, “现在是” + DateTime.Now.ToString() + “,但毛君还是垃圾”);
sc.Parameters.Add(param);

int count = sc.ExecuteNonQuery();
Console.WriteLine(“Line inserted: ” + count.ToString());

string sql2 = “select * from News”;
SqlCommand sc2 = new SqlCommand(sql2, myConnection);
SqlDataReader reader = sc2.ExecuteReader();

while (reader.Read())
{
Console.WriteLine(String.Format(“ID={0}, news={1}”, reader[0], reader[1]));
}
}
}
}
[/code]

下载:用Visual Studio 2008打开
http://download.nocoo.us/Download/Archive/CSharpHowto/SQLServer.rar

为项目组写了几个Howto的Case。

本文描述了一个用C#实现的简单的Windows Form。
功能是先出现一个登陆窗口,然后用户输入用户名密码,登陆窗口隐藏,加载主窗口。

LoginForm.cs
[code=’c#’]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormHowto
{
public partial class LoginForm : Form
{
public LoginForm()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = “”;
textBox2.Text = “”;
}

private void button1_Click(object sender, EventArgs e)
{
MainForm mainForm = new MainForm(textBox1.Text);
this.Hide();
mainForm.Show();
}
}
}
[/code]

下载:用Visual Studio 2008打开
http://download.nocoo.us/Download/Archive/CSharpHowto/WindowsForm.rar

为项目组写了几个Howto的Case。

本文描述了一个用C#实现的简单的Windows Service。
功能是在启动和停止服务的时候,在Windows事件查看器(Event Log)里添加一条log。

在Visual Studio 2008中建立Windows Service项目之后,会自动生成一个Service1的服务,它的名字默认是Service1,我先把它的文件名从Service1.cs改成ITSTestService.cs,然后需要在ITSTestService.cs的设计器视图的属性里,把Service Name改成ITSTestService,不然添加完服务后,启动服务时会报出这样的错误:

由于下列错误,ITS Test Service 服务启动失败:
配置成在该可执行程序中运行的这个服务不能执行该服务。

因为服务安装的名字是Service1。

Windows系统添加服务:
[code=’c#’]sc create ITSTestService binpath= “PATH TO SERVICE EXE” type= share start= auto displayname= “ITS Test Service”[/code]

Windows系统删除服务:
[code=’c#’]sc delete ITSTestService[/code]

ITSTestService.cs
[code=’c#’]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;

namespace WindowsServiceHowto
{
public partial class ITSTestService : ServiceBase
{
public ITSTestService()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
WriteLog(“ITSTestService Started.”);
}

protected override void OnStop()
{
WriteLog(“ITSTestService Stopped.”);
}

private void WriteLog(string eventString)
{
string source;
string log;
source = “ITS Test Windows Service”;
log = “Application”;

if (!EventLog.SourceExists(source))
{
EventLog.CreateEventSource(source, log);
}

EventLog.WriteEntry(source, eventString);
}
}
}
[/code]

下载:用Visual Studio 2008打开
http://download.nocoo.us/Download/Archive/CSharpHowto/WindowsService.rar

中文国家代码顶级域 “中国”将正式启用
除了传统的.cn、.com、.net等英文域名后缀之外,国际互联网将首次出现“中国”这样的非英语域名后缀.
记者昨天获悉,在刚刚闭幕的ICANN(互联网名称与数字地址分配机构)巴黎年会上,ICANN理事会一致通过了一项重要决议,允许使用其他语言包括中文等作为互联网顶级域字符.决议内容包括,“.中国”将于2009年上半年率先写入全球根域名系统,成为首批新设的非拉丁语系字符顶级域之一,即中文国家代 码顶级域“中国域名”将正式启用.
资深业内人士认为,“中国域名”的正式启用,意味着“中国域名”将正式融入国际互联网,作为中华文化在网络上的国家象征登上历史舞台.
简单来说,中文用户今后在浏览器地址栏不仅可以通过输入英文域名lenovo.com.cn来访问联想公司网站,还可以直接输入中国域名“联想.中国”完成这一操作.
对此,ICANN主席特拉什(Peter Dengate Thrush)评价称,这是项历史性决议,它将给互联网样式和运行模式带来巨大变化,将使互联网更为开放,使用方法更为多样化.
ICANN理事、我国互联网知名专家钱华林指出,现在中国有2亿多网民,也就意味着还有10多亿人没有上网.纯中文的“中国域名”并非只为现在的网民准备,更是为未来的数亿中国人所准备.
据介绍,“中国域名”正式进入国际互联网,是中国互联网界多年努力的成果.对中国互联网用户来说,中国域名无疑是以中文为品牌名称的企事业单位在网络上最好的品牌载体.
目前,互联网顶级域名体系只支持包括26个英文字母、连字符和阿拉伯数字0至9 在内的37个字符.此项决议意味着诞生于1983年的域名系统(DNS-Domain Name System)在被英语语种“独霸”25年之后,将真正迎来包括中文在内的世界各大语种顶级域时代.

脑残.中国
打这样的域名真的很舒服么?这样的域名不但击键次数不少,而且很不舒服,因为我要切换输入法打英文句号。
轰轰烈烈的非拉丁域名实行了好多年了,价格依旧地昂贵,却鲜有人使用。中文域名号称主要优点是好记,其实我倒觉得naocan.zhongguo也很好记啊…
互联网普及的今天,网民不会一点点英文好像没法生存,即便不会英文,记上几个TLD应该还是不成问题的吧。
如果真的更新到root DNS去了,我就去开发个插件,把脑残。中国自动改成脑残.中国,一定大卖~

这种事情的感觉比较奇怪。
一直以来,都是经历着一系列的“第一次”的概念,第一次上学,第一次喜欢上一个人,第一次喝酒,第一次喝醉,甚至第一次步入某个饭店。
这次是最后一次,最后一次考试。6+3+3+4+1=17,一个很华丽也很沉重的式子,17年做一件事情,可能是唯一一个比我最骄傲的事情更长的了。可惜今天这个事情就快要结束,而另一件事情却还要撒很长很长,拖到生命和世界的尽头。
回头想想过来的17年,考试真的是无数啊,最终还是有惊无险地到了今天这一步,作为我自己来说已经挺满足了。其实这么多年的学习生涯,在几次拐点上都有Aya的影子,而且我也一直把能够进入山东省实验中学第一届实验班和同济大学读自己喜欢的专业的功劳归结与她。她一直也不承认,只是说都是我努力的结果。
我是双鱼里面最需要爱的驱动的那一种,如果没有高中那些苦苦思恋的日子,如果没有她写的那些鼓励的信,也许今天的我,早就告别了自己最后一次考试。
不过,说不定那样子反而能和她在一起,一直在一起。只要她喜欢,一定会和我在一起~

我不知道,我只是希望能让我们的生活变得更好一点,如果没有这样的生活,那就多挣些钱,留给她或者捐给我们国家那些想实现自己的梦的孩子们。