代码生成器:ASP.NET写你自己的代码生成器



FRMMAIN.ASPX.CS

using ;
using .Collections;
using .ComponentModel;
using .Data;
using .Data.SqlClient;
using .Drawing;
using .Web;
using .Web.SessionState;
using .Web.UI;
using .Web.UI.WebControls;
using .Web.UI.HtmlControls;

Web_Test
{
/// <summary>
/// 作者:davi
/// 日期:3003-03-18
/// </summary>
public FrmMain : .Web.UI.Page
{
protected .Web.UI.WebControls.Label Label1;
protected .Web.UI.WebControls.Label Label2;
protected .Web.UI.WebControls.Label Label4;
protected .Web.UI.WebControls.DropDownList DropDownList1;
protected .Web.UI.WebControls.Label Label5;
protected .Web.UI.WebControls.TextBox txtServerName;
protected .Web.UI.WebControls.TextBox txtUserName;
protected .Web.UI.WebControls.TextBox txtPassword;
protected .Web.UI.WebControls.Button Button1;
protected .Web.UI.WebControls.DropDownList DropDownList2;
protected .Web.UI.WebControls.Label Label6;
protected .Web.UI.WebControls.Label Label7;
protected .Web.UI.WebControls.Button Button2;
protected .Web.UI.WebControls.DropDownList DropDownList3;
protected .Web.UI.WebControls.Button Button3;
protected .Web.UI.WebControls.TextBox txtLayOut;
protected .Web.UI.WebControls.Button Button4;
protected .Web.UI.WebControls.Button Button5;
protected .Web.UI.WebControls.Button Button6;
private SqlConnection m_Scon;
private DataSet m_DS;

private void Page_Load(object sender, .EventArgs e)
{
m_Scon = SqlConnection;
m_DS = DataSet;
}


#region Web Form Designer generated code
//[STAThreadAttribute]
override protected void _disibledevent=>this.DropDownList1.SelectedIndexChanged .EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Button2.Click .EventHandler(this.Button2_Click);
this.Button3.Click .EventHandler(this.Button3_Click);


this.Button4.Click .EventHandler(this.Button4_Click);
this.Button5.Click .EventHandler(this.Button5_Click);
this.Button6.Click .EventHandler(this.Button6_Click);
this.Load .EventHandler(this.Page_Load);

}
#endregion

#region 显示数据库表 Button1_Click
/// <summary>
/// 显示数据库
/// </summary>
/// <param name=\"sender\"></param>
/// <param name=\"e\"></param>
private void Button1_Click(object sender, .EventArgs e)
{
try
{
m_Scon.ConnectionString = \"user id=\"+this.txtUserName.Text+
\";password=\"+this.txtPassword.Text+
\";initial catalog=\"+this.DropDownList3.SelectedItem.Text+
\";data source=\"+this.txtServerName.Text;
SqlCommand m_Scmd = SqlCommand(\"sp_tables\",m_Scon);
m_Scmd.CommandType = CommandType.StoredProcedure;
SqlParameter myParm = m_Scmd.Parameters.Add(\"@table_type\",SqlDbType.VarChar,100);
myParm.Value = \"\'TABLE\'\";
m_Scon.Open;
SqlDataReader m_Sdr = m_Scmd.ExecuteReader;
this.DropDownList1.Items.Clear;
while(m_Sdr.Read)
{
(m_Sdr[\"TABLE_NAME\"].!=\"dtproperties\")
{
ListItem m_LI = ListItem;
m_LI.Text = m_Sdr[\"TABLE_NAME\"].;
m_LI.Value = m_Sdr[\"TABLE_NAME\"].;
this.DropDownList1.Items.Add(m_LI);
}
}
m_Sdr.Close;
m_Scon.Close;
}
catch
{


(m_Scon.State..ToUpper\"OPEN\")
{
m_Scon.Close;
}
}
}

#endregion

#region Show Columns in a table DropDownList1_SelectedIndexChanged
/// <summary>
/// 显示表所有列
/// </summary>
/// <param name=\"sender\"></param>
/// <param name=\"e\"></param>
private void DropDownList1_SelectedIndexChanged(object sender, .EventArgs e)
{
try
{
(this.DropDownList1.SelectedIndex!=-1)
{
m_Scon.ConnectionString = \"user id=\"+this.txtUserName.Text+
\";password=\"+this.txtPassword.Text+
\";initial catalog=\"+this.DropDownList3.SelectedItem.Text+
\";data source=\"+this.txtServerName.Text;
SqlCommand m_Scmd = SqlCommand(\"sp_columns\",m_Scon);
m_Scmd.CommandType = CommandType.StoredProcedure;
SqlParameter myParm = m_Scmd.Parameters.Add(\"@table_name\",SqlDbType.VarChar,100);
myParm.Value = this.DropDownList1.SelectedItem.Value;
m_Scon.Open;
SqlDataReader m_Sdr = m_Scmd.ExecuteReader;
this.DropDownList2.Items.Clear;
while(m_Sdr.Read)
{
ListItem m_LI = ListItem;
m_LI.Text = m_Sdr[\"COLUMN_NAME\"].;
m_LI.Value = m_Sdr[\"COLUMN_NAME\"].;
this.DropDownList2.Items.Add(m_LI);
}
m_Sdr.Close;
m_Scon.Close;


}
}
catch
{
(m_Scon.State..ToUpper\"OPEN\")
{
m_Scon.Close;
}
}
}

#endregion

#region Show All DataBase Button2_Click
/// <summary>
/// 显示所有数据库
/// </summary>
/// <param name=\"sender\"></param>
/// <param name=\"e\"></param>
private void Button2_Click(object sender, .EventArgs e)
{
try
{
m_Scon.ConnectionString = \"user id=\"+this.txtUserName.Text+
\";password=\"+this.txtPassword.Text+
\";data source=\"+this.txtServerName.Text;
SqlCommand m_Scmd = SqlCommand(\"sp_databases\",m_Scon);
m_Scmd.CommandType = CommandType.StoredProcedure;
m_Scon.Open;
SqlDataReader m_Sdr = m_Scmd.ExecuteReader;
this.DropDownList1.Items.Clear;
while(m_Sdr.Read)
{
ListItem m_LI = ListItem;
m_LI.Text = m_Sdr[\"DATABASE_NAME\"].;
m_LI.Value = m_Sdr[\"DATABASE_NAME\"].;
this.DropDownList3.Items.Add(m_LI);
}
m_Sdr.Close;
m_Scon.Close;
}
catch
{
(m_Scon.State..ToUpper\"OPEN\")
{
m_Scon.Close;
}
}
}



#endregion
Tags:  留言代码生成器 空间代码生成器 qq代码生成器 代码生成器

延伸阅读

最新评论

发表评论