随笔分类 -  .NET

摘要:C# 用Linq的方式实现对Xml文件的基本操作(创建xml文件、增删改查xml文件节点信息)http://www.cnblogs.com/mingmingruyuedlut/archive/2011/01/27/1946239.html修改了一下里面一部分 try{//定义并从xml文件中加载节点(根节点)XElementrootNode=XElement.Load(xmlPath);varquery=fromrssFeedinrootNode.Descendants("User")selectnew{name=rssFeed.Element("name&quo 阅读全文
posted @ 2011-04-18 18:29 韩天伟 阅读(358) 评论(0) 推荐(0) 编辑
摘要:将一个已知的XML放到XDocument 对象当中使用LINQ 查询非常的容易,下面是一个例子。查找XML文档中的所有PERSONA元素显示结果个数,并遍历输出其值publicvoidMyDescendants(){XDocumentxdoc=XDocument.Load(Server.MapPath("hamlet.xml"));//查找元素名为PERSONA的元素varquery=frompeopleinxdoc.Descendants("PERSONA")selectpeople.Value;//people是符合条件元素结果集而people.Va 阅读全文
posted @ 2011-04-18 18:17 韩天伟 阅读(432) 评论(0) 推荐(0) 编辑
摘要:一次筛选 IList<Model>list=(IList<Model>)dataGridView2.DataSource;varquery=fromstudentinlist//wherestudent.FormCode.StartsWith(textBox3.Text.Trim())wherestudent.FormCode.Contains(textBox3.Text.Trim())//wherestudent.FormCode.EndsWith(textBox3.Text.Trim())selectstudent; dataGridView2.DataSource 阅读全文
posted @ 2011-04-12 09:51 韩天伟 阅读(1241) 评论(0) 推荐(0) 编辑
摘要:Like的操作,有点像in,但是,方向变了。什么意思呢。就是你给定一个字符串,去寻找数据中某个字段包含这个字符串。就是给定的字符串是某字段的子集。Sql Script是这么写的。Selec * from table where id like '%AD%'Selec * from table where id like '%AD'Selec * from table where id like 'AD%'上面的%是通配符,表示,该字段含有某个值,不知道的位置使用%代替。第一个是表示中间一段是AD,两头不清楚。第二个是结尾是AD,前面的不清楚。第三 阅读全文
posted @ 2011-04-08 18:00 韩天伟 阅读(18905) 评论(5) 推荐(3) 编辑
摘要:Winform中DataGridView绑定IList数据源后的排序的控件也是从网上看到的方法,我封装好了使用方法:使用方法:IList<Model> aaa = new List<Model>();aaa = Getr();dataGridView1.DataSource = new ZiZhuDi.IListdataGridViewSort.BindingCollection<Model>(aaa);下载地址:http://download.csdn.net/source/3142910 阅读全文
posted @ 2011-03-30 22:08 韩天伟 阅读(469) 评论(0) 推荐(0) 编辑
摘要:首先,实现ICompare接口public class ObjectPropertyCompare<T> : IComparer<T> { private PropertyDescriptor property; private ListSortDirection direction; // 构造函数 public ObjectPropertyCompare(PropertyDescriptor property, ListSortDirection direction) { this.property = property; this.direction = dire 阅读全文
posted @ 2011-03-30 17:12 韩天伟 阅读(5141) 评论(3) 推荐(0) 编辑
摘要:1、数据绑定的问题: 当DataGridView的DataSource绑定的为DataTable时,当DataTable的内容发生改变时,DataGridView中的内容会自动跟随DataTable改变而不用重新绑定数据源; 而把List<T>绑定到DataGridView则不然,当List<T>的内容发生改变是,需要先设置DataGridView的DataSource属性为new List<T>(), 然后再把作过改动的List<T>重新赋于DataGridView的DataSource。 (注:不能设置DataGridView的DataSou 阅读全文
posted @ 2011-03-30 12:56 韩天伟 阅读(473) 评论(0) 推荐(0) 编辑
摘要:声明:本文内容主要译自Nauman Leghari的Using log4net,亦加入了个人的一点心得(节3.1.4)。请在这里下载示例代码 1 简介 1.1 Log4net的优点: 几乎所有的大型应用都会有自己的用于跟踪调试的API。因为一旦程序被部署以后,就不太可能再利用专门的调试工具了。然而一个管理员可能需要有一套强大的日志系统来诊断和修复配置上的问题。 经验表明,日志记录往往是软件开发周期中的重要组成部分。它具有以下几个优点:它可以提供应用程序运行时的精确环境,可供开发人员尽快找到应用程序中的Bug;一旦在程序中加入了Log 输出代码,程序运行过程中就能生成并输出日志信息而无需人工干预 阅读全文
posted @ 2011-03-29 18:32 韩天伟 阅读(256) 评论(0) 推荐(0) 编辑
摘要:本文的内容包括:1,文件基本操作:搜索,创建,复制,剪切,删除,重命名。2,File和FileInfo3,搜索:文件名和子目录4,复制的方法:File和FileInfo5,剪切:同盘和不同盘6,重命名:利用FileInfo.MoveTo实现重命名。7,删除:到回收站和彻底删除。8,多线程时遇到的问题,以及解决办法。 文件的基本操作包括搜索,创建,复制,剪切,删除,重命名等。在C#中可以使用File的一系列静态方法,也可以是FileInfo对象的方法来达到同样的功能。关于File和FileInfo的概念就不多说了,到处都有,当然官方的是最权威的。这里重点介绍每个操作的一些注意点。搜索搜索文件可以 阅读全文
posted @ 2011-03-28 13:30 韩天伟 阅读(5398) 评论(0) 推荐(1) 编辑
摘要:privatevoidtimer1_Tick(objectsender,EventArgse){DateTimedt=DateTime.Now;label1.Text=dt.ToString();}privatevoidForm1_Load(objectsender,EventArgse){timer1.Enabled=true;}Timer,Interval设为1000,反正显示也是1秒一秒来的 阅读全文
posted @ 2011-03-18 17:33 韩天伟 阅读(4421) 评论(0) 推荐(0) 编辑
摘要:DataTabletable=(DataTable)dataGridView1.DataSource;//过滤例句table.DefaultView.RowFilter="SIDlike'*"+txtCondition.Text.ToString()+"*' 阅读全文
posted @ 2011-03-18 09:00 韩天伟 阅读(606) 评论(0) 推荐(0) 编辑
摘要:C# datagridview 取某行中的某值,方法1:string aa;aa=dataGridView1.CurrentRow.Cells["XX"].Value.ToString();//XX:某一列的字段名,即SQL语句中的取得内容。方法2:String str = this.DataGridView.SelectedCells[0].Value.ToString();方法1经测试过没有问题,方法2没有测试过。 阅读全文
posted @ 2011-03-18 08:57 韩天伟 阅读(4960) 评论(0) 推荐(0) 编辑
摘要:代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--usingSystem.IO;//写入StreamWritersw=newStreamWriter(@"C:\temp123.txt");sw.WriteLine("----------------hello----------------");sw.WriteLine("内容");sw.WriteLine("----------------hello----------------");sw.F 阅读全文
posted @ 2011-01-11 17:38 韩天伟 阅读(5724) 评论(0) 推荐(0) 编辑
摘要:像QQ、百度hi等等即时通讯软件都有这种功能,就是你点击客户端的一些按钮,打开的网页都是已经登录了的,因为客户端已经登录过了,不用在网页上重新登录一遍。  今天在百度知道上一个网友遇到这个问题,我就花时间研究一下,帮忙解决了。  用C#实现起来也比较简单(但有一个条件,网页登陆的时候不能有验证码),就是先用HttpWebRequest登陆获取到cookie值,然后再把cookie写到浏览器的cookie目录,最后再打开浏览器。以下为实现代码,对于有什么问题欢迎留言。代码Code highlighting produced by Actipro CodeHighlighter (freeware 阅读全文
posted @ 2010-12-17 13:02 韩天伟 阅读(2002) 评论(2) 推荐(0) 编辑
摘要:代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--Randomrandom=newRandom();stringstrRandom=(random.Next(1,int.MaxValue).ToString()+"000").Substring(0,4);stringorderId="name"+DateTime.Now.ToString("yyyyMMddHHmmssffff")+strRandom;、 阅读全文
posted @ 2010-12-16 23:26 韩天伟 阅读(411) 评论(0) 推荐(0) 编辑
摘要:代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.IO;usingSystem.Diagnostics;usingSystem.Runtime.InteropServices;namespaceEcan{publicclassEcanDOS{//引入API函数[DllImportAttribute("u 阅读全文
posted @ 2010-12-16 23:03 韩天伟 阅读(750) 评论(1) 推荐(0) 编辑
摘要:假设当前页完整地址是:http://www.test.com/aaa/bbb.aspx?id=5&name=kelli"http://"是协议名"www.test.com"是域名"aaa"是站点名"bbb.aspx"是页面名(文件名)"id=5&name=kelli"是参数【1】获取 完整url (协议名+域名+站点名+文件名+参数)string url=Request.Url.T... 阅读全文
posted @ 2010-11-24 14:57 韩天伟 阅读(1562) 评论(0) 推荐(0) 编辑
摘要:代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--//加密CookiesResponse.Cookies["askCRM"]["USERID"]=Tools.Encrypt(strUserName.Trim(),Tools.myKey);//解密st... 阅读全文
posted @ 2010-11-24 14:56 韩天伟 阅读(2263) 评论(0) 推荐(0) 编辑
摘要:代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--引入命名空间usingSystem.IO;usingSystem.Net;usingSystem.Text;usingSystem.Text.RegularExpressions;//以GET方式抓取... 阅读全文
posted @ 2010-11-06 21:15 韩天伟 阅读(2070) 评论(0) 推荐(1) 编辑
摘要:[代码] 阅读全文
posted @ 2010-11-04 12:35 韩天伟 阅读(750) 评论(0) 推荐(1) 编辑