| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3944 人关注过本帖, 1 人收藏
标题:c#由浅入深代码
只看楼主 加入收藏
王杰
Rank: 2
等 级:新手上路
威 望:4
帖 子:307
专家分:0
注 册:2005-5-13
收藏
得分:0 

《C#中使用加密方式范例(sha1加密与md5加密)》
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace asp.net中的字符加密
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string s1="My name is wangjie";
Response.Write("字符串My name is wangjie,经过sha1加密后为:<br>");
string s2=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(s1,"sha1");
Response.Write(s2);
Response.Write("<br>");
string s3="i love c#";
Response.Write("i love c#,经过md5加密后为:<br>");
string s4=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(s3,"md5");
Response.Write(s4);
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}


http://zdrjwlb.bulo. QQ群:1659819
2005-11-22 18:40
王杰
Rank: 2
等 级:新手上路
威 望:4
帖 子:307
专家分:0
注 册:2005-5-13
收藏
得分:0 
ip与域名互换

王杰友情提示:
需要首先导入system.net 命名空间



using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net;
namespace WebApplication6
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label2;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面

}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
try
{
IPHostEntry hostinfo=Dns.GetHostByName(TextBox1.Text);
Label1.Text="您输入的域名对应的ip是:"+hostinfo.AddressList[0].ToString();
}
catch(Exception ee)
{
Label1.Text="无法转换,请检查您的输入!";
}
}

private void Button2_Click(object sender, System.EventArgs e)
{
try
{
IPHostEntry hostinfo1=Dns.GetHostByAddress(TextBox2.Text);
Label1.Text="您输入的ip对应的域名是:"+hostinfo1.HostName;
}
catch(Exception ee)
{
Label1.Text="无法转换,请检查您的输入!";
}
}
}
}


http://zdrjwlb.bulo. QQ群:1659819
2005-11-22 21:13
goodgoodstudy
Rank: 2
等 级:新手上路
威 望:3
帖 子:111
专家分:0
注 册:2005-4-6
收藏
得分:0 
总结的很好啊,但是要尽量写点明白点,自动生成的代码就不要写了

[此贴子已经被作者于2005-11-23 9:04:52编辑过]



2005-11-23 09:03
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
收藏
得分:0 
是定义一个人不能登陆多次.

<iframe name="alimamaifrm" frameborder="0" marginheight="0" marginwidth="0" border="0" scrolling="no" width="300" height="170" src="/go/app/tbk_app/chongzhi_300_170.php?pid=mm_28854300_2441872_11377541&page=chongzhi_300_170.php&size_w=300&size_h=170&stru_phone=1&stru_game=1&stru_travel=1" ></iframe>
2005-11-23 10:03
王杰
Rank: 2
等 级:新手上路
威 望:4
帖 子:307
专家分:0
注 册:2005-5-13
收藏
得分:0 
定义一个人不能登陆多次的代码很好写,只要检测到它的session为true就用javascript弹出一个对话框就可以了然后在把他引导到我们提前设置好的一个出错页面就可以了!另外里面的自动生成的代码中有 好多命名空间,大家可以顺便了解了解,有些命名空间如果不提前导入则会出错的。
况且自动生成的代码也不多啊!相信有过vs.net设计经验的人都会轻易的看懂的!

http://zdrjwlb.bulo. QQ群:1659819
2005-11-23 14:18
王杰
Rank: 2
等 级:新手上路
威 望:4
帖 子:307
专家分:0
注 册:2005-5-13
收藏
得分:0 
检测服务器开放的端口信息

经过无数次的反复验证与修改终于诞生了这篇帖子(鼓掌)
王杰友情提示:
首先导入system.io与system.net.sockets命名空间

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net.Sockets;
using System.IO;

namespace 再次检测服务器开放端口的信息
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel Panel1;

private void Page_Load(object sender, System.EventArgs e)
{
int[] arrPort=new int[5]{21,23,25,110,1433};
string strServer="localhost";
string strService,strResponse,strShow;
int intPort;
for(int i=0;i<arrPort.Length;i++)
{
intPort=arrPort[i];
switch(intPort)
{
case 21:
strService="FTP服务"; break;
case 23:
strService="Telnet服务"; break;
case 25:
strService="SMTP服务"; break;
case 110:
strService="POP3服务"; break;
default:
strService="无法知道"; break;
}
if ((strResponse=TcpConnect(strServer,intPort))!="没有开放")
{
strShow="<b>"+intPort.ToString()+"</b>端口:"+"</font>";
}
else
{
strShow="<b>"+intPort.ToString()+"</b>端口没有开放"+"(<font color=red>)"+strService+"</font>";
}
Panel1.Controls.Add(new LiteralControl(strShow+"<p>"));
}


}
public string TcpConnect(string strServer,int intPort)
{
string strResult;
TcpClient tcpc=new TcpClient();
try
{
tcpc.Connect(strServer,intPort);
Stream s=tcpc.GetStream();
StreamReader sr=new StreamReader(s);
strResult=sr.ReadLine();
}
catch(Exception ee)
{
strResult="没有开放";
}
finally
{
tcpc.Close();
}
return strResult;
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}


http://zdrjwlb.bulo. QQ群:1659819
2005-11-23 15:05
王杰
Rank: 2
等 级:新手上路
威 望:4
帖 子:307
专家分:0
注 册:2005-5-13
收藏
得分:0 
浏览器中的文件列表

版主手迹:
经过反复的修改测试,终于诞生了此帖子,于是心里无限感慨,中国的程序员怎么了???
错误无处不在!汗!
由于需要用到system.io所以需要提前导入,以后这点要时刻注意,程序到底都用到那些命名空间,我已经整理好相关的资料,将在有时间后一并发出来共享。呵呵
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;

namespace 浏览器中的文件列表2
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Table Table1;

private void Page_Load(object sender, System.EventArgs e)
{
string strCurrentDir=Server.MapPath(".");
Label1.Text=strCurrentDir;
FileInfo fi;
DirectoryInfo di;
TableCell tc;
TableRow tr;

string FileName; //文件名称
string FileExt; //文件扩展名
long FileSise; //文件大小
DateTime FileModify; //文件更新时间
DirectoryInfo dir=new DirectoryInfo(strCurrentDir);
foreach(FileSystemInfo fsi in dir.GetFileSystemInfos())
{
FileName ="";
FileExt="";
FileSise=0;
if (fsi is FileInfo)
//表示当前fsi是文件
{
fi=(FileInfo)fsi;
FileName=fi.Name; //文件名称
FileExt=fi.Extension; //文件扩展名称
FileSise=fi.Length; //获取当前文件的大小
FileModify=fi.LastWriteTime; //或许上次写入当前目录的时间
//通过扩展名来选择文件显示图标
}
else
{
//当前为目录
di=(DirectoryInfo)fsi;
FileName=di.Name;
FileModify=di.LastWriteTime;
}
//组建新的行
tr=new TableRow();
tc=new TableCell();
tc.Controls.Add(new LiteralControl(FileName.ToString()));
tr.Cells.Add(tc);
tc=new TableCell();
tc.Controls.Add(new LiteralControl(FileSise.ToString()));
tr.Cells.Add(tc);
tc=new TableCell();
tc.Controls.Add(new LiteralControl(FileModify.ToString()));
tr.Cells.Add(tc);
Table1.Rows.Add(tr);

}
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}

[此贴子已经被作者于2005-11-23 15:58:26编辑过]


http://zdrjwlb.bulo. QQ群:1659819
2005-11-23 15:57
王杰
Rank: 2
等 级:新手上路
威 望:4
帖 子:307
专家分:0
注 册:2005-5-13
收藏
得分:0 
connection对象介绍

王杰友情提示:
首先导入system.data跟system.data.oledb
如果是sqlserver的话应该导入using System.Data.SqlClient
具体问题具体分析吧以后不再提示!
首先我们从access的开始介绍,以后会陆续为大家介绍sqlserver的强大的功能,耐心等待吧!
下面是范例使用了2个label分别显示数据库的2中不同状态!
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

namespace WebApplication8
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label1;

private void Page_Load(object sender, System.EventArgs e)
{
OleDbConnection conn=new OleDbConnection();
conn.ConnectionString="provider=microsoft.jet.oledb.4.0;data source="+Server.MapPath("db1.mdb");
conn.Open();
Label1.Text=conn.State.ToString();
conn.Close();
Label2.Text=conn.State.ToString();
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}


http://zdrjwlb.bulo. QQ群:1659819
2005-11-23 17:23
王杰
Rank: 2
等 级:新手上路
威 望:4
帖 子:307
专家分:0
注 册:2005-5-13
收藏
得分:0 
ExecuteScalar方法

ExecuteScalar方法返回单个值,用来执行聚合函数。
下面是利用ExecuteScalar方法执行avg聚合函数的SQL语句

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
namespace ExecuteScalar方法
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;

private void Page_Load(object sender, System.EventArgs e)
{
OleDbConnection conn=new OleDbConnection();
conn.ConnectionString="provider=microsoft.jet.oledb.4.0;data source="+Server.MapPath("db1.mdb");
conn.Open();
String strSql="select avg(数学) from table1";
OleDbCommand comm=new OleDbCommand(strSql,conn);
Double d=(Double)comm.ExecuteScalar();
Label1.Text="所有人数学的平均成绩为"+d.ToString()+"分";
conn.Close();
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}


http://zdrjwlb.bulo. QQ群:1659819
2005-11-25 16:42
王杰
Rank: 2
等 级:新手上路
威 望:4
帖 子:307
专家分:0
注 册:2005-5-13
收藏
得分:0 
ExecuteScalar方法

ExecuteScalar方法返回单个值,用来执行聚合函数。
下面是利用ExecuteScalar方法执行avg聚合函数的SQL语句

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
namespace ExecuteScalar方法
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;

private void Page_Load(object sender, System.EventArgs e)
{
OleDbConnection conn=new OleDbConnection();
conn.ConnectionString="provider=microsoft.jet.oledb.4.0;data source="+Server.MapPath("db1.mdb");
conn.Open();
String strSql="select avg(数学) from table1";
OleDbCommand comm=new OleDbCommand(strSql,conn);
Double d=(Double)comm.ExecuteScalar();
Label1.Text="所有人数学的平均成绩为"+d.ToString()+"分";
conn.Close();
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}


http://zdrjwlb.bulo. QQ群:1659819
2005-11-25 16:43
快速回复:c#由浅入深代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013424 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved