到codeproject.com上随便找一下,一大把,有的你看了
解决方案 »
- 一个查询的问题
- 未将对象引用设置到对象的实例
- C#调用RAPI中的CeFindAllfiles函数时,如何设置其参数
- 求 C#里面控制 宽带连接图标在状态栏显示
- .NET WINFORM Datagrid显示如何换行
- wpf databinding to xml
- 关于MDI子窗体的实例化问题求助~~~请各位大仙关注一下~~~~~~~~···
- C# Socket长连接
- 窗体的问题
- C语言封装的DLL函数在C#中如何调用,void Fun(unsigned int(*fun)(unsigned char *,unsigned int))
- 出差在外,各位网友大救命!
- c#,PictureBox上如何实现双缓存
[email protected]
[email protected]
谢谢!!!
:)
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
index.aspx.cs
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.Configuration;namespace FttBBS1._0
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{ ///<summary>
///mysqlcmd是SQL语句。
///bid是论坛的第几个大板块。
///fid是论坛的大板块的第几个小版块。
///<summary>
string mysqlcmd,bid,fid; protected System.Data.SqlClient.SqlCommand sqlCommand1;
protected System.Data.SqlClient.SqlCommand sqlCommand2;
protected System.Data.SqlClient.SqlCommand sqlCommand3;
protected System.Data.SqlClient.SqlCommand sqlCommand4;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlConnection sqlConnection2;
protected System.Data.SqlClient.SqlConnection sqlConnection3;
protected System.Data.SqlClient.SqlConnection sqlConnection4;
protected System.Data.SqlClient.SqlDataReader mydatareader1;
protected System.Data.SqlClient.SqlDataReader mydatareader2;
protected System.Data.SqlClient.SqlDataReader mydatareader3;
protected System.Web.UI.WebControls.TextBox usernameTextBox;
protected System.Web.UI.WebControls.TextBox passwordTextBox;
protected System.Web.UI.WebControls.Label usernameLabel;
protected System.Web.UI.WebControls.Label passwordLabel;
protected System.Web.UI.WebControls.Label warLabel; protected System.Web.UI.WebControls.Button loginbtn;
protected System.Web.UI.WebControls.Table mytable;
protected System.Web.UI.WebControls.TableRow mytablerow;
protected System.Web.UI.WebControls.TableCell mytablecell; protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.HyperLink HyperLink2;
//ftttable是动态生成表格的主体方法.
public void ftttable()
{
//i是为了后面显示小版块编号以及显示表格相间的颜色
int i;
// str_passagenumber表示每一个小版块的帖子数。
string str_passagenumber;
//以下是生成表格的部分。
mytable.Rows.Clear();//the reason?
mytable.Width=Unit.Percentage(90);
//以下定义了表格的前景色和背景色.
mytable.ForeColor=Color.FromArgb(0x00,0x00,0xff);
mytable.BackColor=Color.FromArgb(0xcc,0xff,0xcc);
mytable.CellSpacing=1;
//get boardlsit
mysqlcmd="select boardID,name from board";
sqlCommand1.CommandText=mysqlcmd;
mydatareader1=sqlCommand1.ExecuteReader(); while (mydatareader1.Read())
{
bid=mydatareader1["boardID"].ToString(); mytablerow=new TableRow();
mytablerow.BackColor=Color.FromArgb(0x00,0x9A,0xFF);
mytablecell=new TableCell();
mytablecell.HorizontalAlign=HorizontalAlign.Left;
mytablecell.ColumnSpan=3;
mytablecell.Text="<img src='images/leng.gif' width='12' height='12'>";
mytablecell.Text="<table width='200' border='0' cellspacing='0' cellpadding='0'>"+mytablecell.Text;
mytablecell.Text+="<tr><td width='30'> </td>";
mytablecell.Text=mytablecell.Text+"<td width='150' ><font color='#000091'>";
mytablecell.Text=mytablecell.Text+mydatareader1["name"].ToString()+"</font></td>";
mytablecell.Text=mytablecell.Text+"</tr></table>";
mytablerow.Cells.Add(mytablecell);
mytable.Rows.Add(mytablerow);
//get forum list
mysqlcmd="select ID,Name from Forum where BoardID="+bid;
sqlCommand2.CommandText=mysqlcmd;
mydatareader2=sqlCommand2.ExecuteReader();
i=0;
while (mydatareader2.Read())
{
i++;
str_passagenumber=""; fid=mydatareader2["ID"].ToString(); mysqlcmd="select count(*) from Topic_"+bid+" where ForumID="+fid+"and iddd=0";
sqlCommand3.CommandText=mysqlcmd;
mydatareader3=sqlCommand3.ExecuteReader();
if (mydatareader3.Read())
{
str_passagenumber=mydatareader3[0].ToString();
}
mydatareader3.Close();
mytablerow=new TableRow();
if (i%2==0) mytablerow.BackColor=Color.FromArgb(0x9C,0xCF,0xFF);
else mytablerow.BackColor=Color.FromArgb(0xFF,0xFF,0xFF);
mytablecell=new TableCell();
mytablecell.HorizontalAlign=HorizontalAlign.Center;
mytablecell.Text=i.ToString("00");
mytablecell.Width=Unit.Percentage(10);
mytablerow.Cells.Add(mytablecell); //name
mytablecell=new TableCell();
mytablecell.HorizontalAlign=HorizontalAlign.Left;
mytablecell.Text="<a href='browse.aspx?bid="+bid+"&fid="+fid+"&pn=1&elite=0'>"+mydatareader2["Name"].ToString()+"</a>";
mytablecell.Width=Unit.Percentage(70);
mytablerow.Cells.Add(mytablecell);
//passagenumber
mytablecell=new TableCell();
mytablecell.HorizontalAlign=HorizontalAlign.Center;
mytablecell.Text=str_passagenumber;
mytablecell.Width=Unit.Percentage(20);
mytablerow.Cells.Add(mytablecell);
mytable.Rows.Add(mytablerow);
} mydatareader2.Close();
}
mydatareader1.Close();
Page.DataBind(); } private void Page_Load(object sender, System.EventArgs e)
{
HyperLink2.Enabled=false;
Session["login"]=0;
try
{
if (Session["name"].ToString()!=null) Session["login"]=1;
}
catch
{
}
if (Session["login"].ToString()=="1")
{
warLabel.Text="欢迎"+Session["name"]+"进入论坛";
HyperLink2.Enabled=true;
}
else
{
warLabel.Text="";
}
sqlConnection1.ConnectionString=("server=(local)\\NetSDK;database=pubs;user id=sa;password=7941978epe");
sqlConnection1.Open();
sqlCommand1.Connection=sqlConnection1;
sqlConnection2.ConnectionString=("server=(local)\\NetSDK;database=pubs;user id=sa;password=7941978epe");
sqlConnection2.Open();
sqlCommand2.Connection=sqlConnection2;
sqlConnection3.ConnectionString=("server=(local)\\NetSDK;database=pubs;user id=sa;password=7941978epe");
sqlConnection3.Open();
sqlCommand3.Connection=sqlConnection3;
sqlConnection4.ConnectionString=("server=(local)\\NetSDK;database=pubs;user id=sa;password=7941978epe");
sqlConnection4.Open();
sqlCommand4.Connection=sqlConnection4;
ftttable();
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlCommand2 = new System.Data.SqlClient.SqlCommand();
this.sqlCommand3 = new System.Data.SqlClient.SqlCommand();
this.sqlCommand4 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlConnection2 = new System.Data.SqlClient.SqlConnection();
this.sqlConnection3 = new System.Data.SqlClient.SqlConnection();
this.sqlConnection4 = new System.Data.SqlClient.SqlConnection();
this.loginbtn.Click += new System.EventHandler(this.loginbtn_Click);
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "data source=FTT-WATERASS\\NetSDK;initial catalog=pubs;integrated security=SSPI;per" +
"sist security info=False;workstation id=FTT-WATERASS;packet size=4096";
//
// sqlConnection2
//
this.sqlConnection2.ConnectionString = "data source=FTT-WATERASS\\NetSDK;initial catalog=pubs;integrated security=SSPI;per" +
"sist security info=False;workstation id=FTT-WATERASS;packet size=4096";
//
// sqlConnection3
//
this.sqlConnection3.ConnectionString = "data source=FTT-WATERASS\\NetSDK;initial catalog=pubs;integrated security=SSPI;per" +
"sist security info=False;workstation id=FTT-WATERASS;packet size=4096";
//
// sqlConnection4
//
this.sqlConnection4.ConnectionString = "data source=FTT-WATERASS\\NetSDK;initial catalog=pubs;integrated security=SSPI;per" +
"sist security info=False;workstation id=FTT-WATERASS;packet size=4096";
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void loginbtn_Click(object sender, System.EventArgs e)
{
mysqlcmd="select name,nickname,password,bbs_exp from users where name='"+usernameTextBox.Text+"'";
sqlCommand4.CommandText=mysqlcmd;
mydatareader3=sqlCommand4.ExecuteReader();
if (mydatareader3.Read()&&mydatareader3["password"].ToString()==passwordTextBox.Text)
{
Session["username"]=mydatareader3["nickname"].ToString();
Session["login"]="1";
Session["name"]=mydatareader3["name"].ToString();
Session["bbs_exp"]=mydatareader3["bbs_exp"].ToString();
warLabel.Text="欢迎"+usernameTextBox.Text+"进入论坛";
HyperLink2.Enabled=true; }
else
{
warLabel.Text="对不起,用户名或密码错误!";
}
mydatareader3.Close();
}
}
}
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.SqlClient;
namespace FttBBS1._0
{
/// <summary>
/// newuser 的摘要说明。
/// </summary>
public class newuser : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label nameLabel;
protected System.Web.UI.WebControls.Label nicknameLabel;
protected System.Web.UI.WebControls.Label passwprdLabel;
protected System.Web.UI.WebControls.Label repasswordLabel;
protected System.Web.UI.WebControls.Label qqLabel;
protected System.Web.UI.WebControls.Label emailLabel;
protected System.Web.UI.WebControls.Label schoolLabel;
protected System.Web.UI.WebControls.Label addressLabel;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.Label Label7; protected System.Web.UI.WebControls.TextBox nameTextBox;
protected System.Web.UI.WebControls.TextBox nicknameTextBox;
protected System.Web.UI.WebControls.TextBox passwordTextBox;
protected System.Web.UI.WebControls.TextBox repasswordTextBox;
protected System.Web.UI.WebControls.TextBox qqTextBox;
protected System.Web.UI.WebControls.TextBox emailTextBox;
protected System.Web.UI.WebControls.TextBox schoolTextBox;
protected System.Web.UI.WebControls.TextBox addressTextBox;
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Panel Panel3; protected System.Web.UI.WebControls.Button submitButton;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.HtmlControls.HtmlTable TABLE1;
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.submitButton.Click += new System.EventHandler(this.submitButton_Click); }
#endregion
private void submitButton_Click(object sender, System.EventArgs e1)
{
SqlConnection myconnection = new SqlConnection("server=(local)\\NetSDK;database=pubs;user id=sa;password=7941978epe");
SqlCommand mysqlcommand = new SqlCommand();
string mysqlcmdtext="insert into users (name,nickname,password,qq,email,school,address,visual) values(@name,@nickname,@password,@qq,@email,@school,@address,@visual)";
mysqlcommand.CommandText=mysqlcmdtext;
mysqlcommand.Connection=myconnection;
mysqlcommand.Parameters.Add(new SqlParameter("@name", SqlDbType.NVarChar, 40));
mysqlcommand.Parameters["@name"].Value = nameTextBox.Text;
mysqlcommand.Parameters.Add(new SqlParameter("@nickname", SqlDbType.NVarChar, 40));
mysqlcommand.Parameters["@nickname"].Value = nicknameTextBox.Text;
mysqlcommand.Parameters.Add(new SqlParameter("@password", SqlDbType.NVarChar, 400));
mysqlcommand.Parameters["@password"].Value = passwordTextBox.Text;
mysqlcommand.Parameters.Add(new SqlParameter("@qq", SqlDbType.NVarChar, 40));
mysqlcommand.Parameters["@qq"].Value = qqTextBox.Text;
mysqlcommand.Parameters.Add(new SqlParameter("@email", SqlDbType.NVarChar, 40));
mysqlcommand.Parameters["@email"].Value = emailTextBox.Text;
mysqlcommand.Parameters.Add(new SqlParameter("@school", SqlDbType.NVarChar, 400));
mysqlcommand.Parameters["@school"].Value = schoolTextBox.Text;
mysqlcommand.Parameters.Add(new SqlParameter("@address", SqlDbType.NVarChar, 400));
mysqlcommand.Parameters["@address"].Value = addressTextBox.Text;
if (Session["visual"]==null)
{
Session["visual"]="11.bmp";
}
mysqlcommand.Parameters.Add(new SqlParameter("@visual", SqlDbType.NVarChar, 40));
mysqlcommand.Parameters["@visual"].Value = Session["visual"].ToString(); myconnection.Open();
if (passwordTextBox.Text.Length<6)
{
Label7.Text="您的密码为空或少于6位,请重新输入。";
}
else if (passwordTextBox.Text!=repasswordTextBox.Text)
{ Label7.Text="您前后输入的密码不一致,请重新输入!";
passwordTextBox.Text="";
repasswordTextBox.Text="";
}
else if (nameTextBox.Text=="")
{
Label7.Text="用户名不能为空";
}
else if (nicknameTextBox.Text=="")
{
Label7.Text="用户昵称不能为空"; } else
{
try
{
mysqlcommand.ExecuteNonQuery();
Label7.Text=" 提交成功,您可以登录了。"; } catch (SqlException e)
{
if (e.Number == 2627)
Label7.Text = "错误:已存在具有相同主键的记录";
else
Label7.Text = "错误:未能添加记录,请确保正确填写了字段";
} }
myconnection.Close(); }
}
}
[email protected]
[email protected]