文章分类 - 编程那些事
摘要:Version4.0:解决了事务的问题。public class DBHelper{SqlConnection cnn = new SqlConnection(@"server=.;uid=sa;pwd=;database=testDB;");public int ExecuteNonQuery(string procName, SqlParameter[] ps){SqlCommand cmd = cnn.CreateCommand();cmd.CommandType = CommandType.StoredProcedure;cmd.CommandText = proc
阅读全文
摘要:Version5.0:这次将连接放入每个方法中,现场产生,现场使用。public class DBHelper{stringcnnString=@"server=.;uid=sa;pwd=;database=testDB;";public int ExecuteNonQuery(string procName, SqlParameter[] ps){SqlConnection cnn = new SqlConnection(cnnString);SqlCommand cmd = cnn.CreateCommand();cmd.CommandType = CommandTyp
阅读全文
摘要:Version2.0:采用命名参数的形式。public class DBHelper{SqlConnection cnn = new SqlConnection(@"server=.;uid=sa;pwd=;database=testDB;");public int ExecuteNonQuery(string sql, SqlParameter[] ps){SqlCommand cmd = cnn.CreateCommand();cmd.CommandText = sql;cmd.Parameters.AddRange(ps);cnn.Open();int x = cmd
阅读全文
摘要:Version3.0:使用存储过程。public class DBHelper{SqlConnection cnn = new SqlConnection(@"server=.;uid=sa;pwd=;database=testDB;");public int ExecuteNonQuery(string procName, SqlParameter[] ps){SqlCommand cmd = cnn.CreateCommand();cmd.CommandType = CommandType.StoredProcedure;cmd.CommandText = procNa
阅读全文
摘要:DBHelper是数据库系统中常用的类,通常用它来处理针对数据库的操作,比如基本的CRUD。一个人在写了一段程序后,不管用的是什么语言,这个类肯定能自己写了,当然,写出来的玩意千差万别,各有千秋,五花八门,啥样的都有,是啊,林子大了。Version1.0:public class DBHelper{SqlConnection cnn = new SqlConnection(@"server=.;uid=sa;pwd=;database=testDB;");public int ExecuteNonQuery(string sql){SqlCommand cmd = cnn.
阅读全文
摘要:添加ftp支持,支持服务器登录。using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;using System.Threading;namespace prjDownLoad{class Program{static void Main(string[] args){Thread t = new Thread(new ThreadStart(Down));t.Start();}static void Down(){DownloadUtil du = new
阅读全文
摘要:让下载类纯粹一些,在下载类的内部,不再保存为文件,如果要保存,那是用户自己的事情,提供了两种形式返回下载的内容:方法的返回值和事件参数。using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;using System.Threading;namespace prjDownLoad{class Program{static void Main(string[] args){Thread t = new Thread(new ThreadStart(Down))
阅读全文
摘要:整合了单线程和多线程。using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;using System.Threading;namespace prjDownLoad{class Program{static void Main(string[] args){Thread t = new Thread(new ThreadStart(Down));t.Start();}static void Down(){DownloadUtil du = new Down
阅读全文
摘要:使用线程池,给事件添加上合适的参数。using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;using System.Threading;namespace prjDownLoad{class Program{//准备了一个用来保存的文件流。static FileStream fs;static void Main(string[] args){Thread t = new Thread(new ThreadStart(Down));t.Start();}s
阅读全文
摘要:多线程,分块下载。using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;using System.Threading;namespace prjDownLoad{class Program{//准备了一个用来保存的文件流。static FileStream fs;static void Main(string[] args){Thread t = new Thread(new ThreadStart(Down));t.Start();}static voi
阅读全文
摘要:为了解决那些个把下载过程中的byte数组,要拿去自行处理的变态们,俺特地做了下面的更改。using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;using System.Threading;namespace prjDownLoad{class Program{//准备了一个用来保存的文件流。static FileStream fs;static void Main(string[] args){fs = new FileStream("c:\\e
阅读全文
摘要:收拾那些只要byte数组,不要当场保存的变态用户。using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;using System.Threading;namespace prjDownLoad{class Program{static void Main(string[] args){//在构造时可以不填写url和fileName//在下载的时候再填写。DownloadUtil du = new DownloadUtil();//订阅事件du.ReadCo
阅读全文
摘要:可以自定义要下载的url和要保存的文件名。using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;using System.Threading;namespace prjDownLoad{class Program{static void Main(string[] args){//实例化下载工具//要求用户在使用的时候,填入url和fileNameDownloadUtil du = new DownloadUtil("http://blog.si
阅读全文
摘要:将要下载的url和fileName的传递从构造中转移到DownloadData方法中,给用户以更大的灵活性。using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;using System.Threading;namespace prjDownLoad{class Program{static void Main(string[] args){//在构造时可以不填写url和fileName//在下载的时候再填写。DownloadUtil du = new D
阅读全文
摘要:把信号机隐藏起来,让调用方干净一点。using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;using System.Threading;namespace prjDownLoad{class Program{static void Main(string[] args){//实例化下载工具DownloadUtil du = new DownloadUtil();//订阅事件du.ReadCompleted += new ReadCompletedHandl
阅读全文
摘要:简单封装:using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;using System.Threading;namespace prjDownLoad{class Program{static void Main(string[] args){//信号机AutoResetEvent are = new AutoResetEvent(false);//实例化下载工具DownloadUtil du = new DownloadUtil();du.are =
阅读全文
摘要:using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;using System.Threading;namespace prjDownLoad{//读取完成委托delegate void ReadCompletedHandler();class Program{//添加一个AutoResetEvent//这是一个信号机static AutoResetEvent are = new AutoResetEvent(false);//读取完成事件static e
阅读全文
摘要:using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;using System.Threading;namespace prjDownLoad{//读取完成委托delegate void ReadCompletedHandler();//读取过程委托delegate void ReadProgressHandler(int x);class Program{//添加一个AutoResetEvent//这是一个信号机static AutoResetEvent
阅读全文
摘要:using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;using System.Threading;namespace prjDownLoad{class Program{//添加一个AutoResetEvent//这是一个信号机static AutoResetEvent are = new AutoResetEvent(false);static void Main(string[] args){//Version8.0//将下载数据放入线程池中。Thr
阅读全文
摘要:using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;using System.Threading;namespace prjDownLoad{class Program{//添加一个AutoResetEvent//这是一个信号机static AutoResetEvent are = new AutoResetEvent(false);static void Main(string[] args){//Version7.0//将下载数据放入一个单独的线程中
阅读全文