📄 editsclass.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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;
using System.Configuration;
namespace doughty_cn
{
/// <summary>
/// EditSClass 的摘要说明。
/// </summary>
public partial class EditSClass : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (!IsPostBack)
BindGrid();
}
public bool checkv(string ch)
{
if (System.Convert.ToInt16(ch)==1)
{
return true;
}
else
{
return false;
}
}
public void BindGrid()
{
string BID;
try
{
if (Request.QueryString["BID"]==null)
{
BID="10";
}
else
{
BID=Request.QueryString["BID"];
}
}
catch (Exception)
{
BID="10";
}
this.DGSClass.DataSource=DBOperate.SelectFormForum("SELECT SmallClass_ID, BigClass_ID, SmallClass_Name, Enable, Memo FROM Small_Class WHERE (BigClass_ID ="+BID+")");
this.Page.DataBind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.DGSClass.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DGSClass_CancelCommand);
this.DGSClass.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DGSClass_EditCommand);
this.DGSClass.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DGSClass_UpdateCommand);
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=KEKC;packet size=4096;user id=sa;data source=KEKC;persist security" +
" info=True;initial catalog=doughty_forum;password=123";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Small_Class", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("SmallClass_ID", "SmallClass_ID"),
new System.Data.Common.DataColumnMapping("BigClass_ID", "BigClass_ID"),
new System.Data.Common.DataColumnMapping("SmallClass_Name", "SmallClass_Name"),
new System.Data.Common.DataColumnMapping("Enable", "Enable")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = "UPDATE Small_Class SET SmallClass_ID = @SmallClass_ID, SmallClass_Name = @SmallCl" +
"ass_Name, Enable = @Enable, Memo = @Memo WHERE (SmallClass_ID = @SmallClass_ID)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@SmallClass_ID", System.Data.SqlDbType.Int, 4, "SmallClass_ID"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@SmallClass_Name", System.Data.SqlDbType.VarChar, 50, "SmallClass_Name"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Enable", System.Data.SqlDbType.Bit, 1, "Enable"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Memo", System.Data.SqlDbType.VarChar, 300, "Memo"));
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM Small_Class WHERE (SmallClass_ID = @Original_SmallClass_ID) AND (BigClass_ID = @Original_BigClass_ID OR @Original_BigClass_ID IS NULL AND BigClass_ID IS NULL) AND (Enable = @Original_Enable OR @Original_Enable IS NULL AND Enable IS NULL) AND (SmallClass_Name = @Original_SmallClass_Name OR @Original_SmallClass_Name IS NULL AND SmallClass_Name IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_SmallClass_ID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "SmallClass_ID", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_BigClass_ID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "BigClass_ID", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Enable", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Enable", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_SmallClass_Name", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "SmallClass_Name", System.Data.DataRowVersion.Original, null));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT SmallClass_ID, BigClass_ID, SmallClass_Name, Enable, Memo FROM Small_Class" +
" WHERE (BigClass_ID = @BigClass_ID)";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@BigClass_ID", System.Data.SqlDbType.Int, 4, "BigClass_ID"));
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = @"INSERT INTO Small_Class(SmallClass_ID, BigClass_ID, SmallClass_Name, Enable) VALUES (@SmallClass_ID, @BigClass_ID, @SmallClass_Name, @Enable); SELECT SmallClass_ID, BigClass_ID, SmallClass_Name, Enable FROM Small_Class WHERE (SmallClass_ID = @SmallClass_ID)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@SmallClass_ID", System.Data.SqlDbType.Int, 4, "SmallClass_ID"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@BigClass_ID", System.Data.SqlDbType.Int, 4, "BigClass_ID"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@SmallClass_Name", System.Data.SqlDbType.VarChar, 50, "SmallClass_Name"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Enable", System.Data.SqlDbType.Bit, 1, "Enable"));
}
#endregion
private void DGSClass_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DGSClass.EditItemIndex = -1;
BindGrid();
}
private void DGSClass_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DGSClass.EditItemIndex = (int)e.Item.ItemIndex;
BindGrid();
}
private void DGSClass_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string s1 = ((System.Web.UI.WebControls.TextBox)e.Item.FindControl("edit_SmallClass_Name")).Text;
string s2 = ((System.Web.UI.WebControls.TextBox)e.Item.FindControl("edit_Memo")).Text;
int b = 0;
if (((CheckBox)e.Item.FindControl("edit_Enable")).Checked == true)
b = 1;
string sid = DGSClass.DataKeys[(int)e.Item.ItemIndex].ToString();
string s = ("UPDATE Small_Class SET SmallClass_Name = @SmallClass_Name,Enable =" + b + ", [Memo] = @Memo WHERE (SmallClass_ID = " + sid + ")");
string DBtype = ConfigurationManager.AppSettings["DBtype"];
if (DBtype == "Accsee")
{
DBsql exsql = new DBsql();
try
{
exsql.Open();
OleDbCommand comcol = new OleDbCommand(s, exsql.con);
comcol.Parameters.Add("@SmallClass_Name", SqlDbType.VarChar);
comcol.Parameters.Add("@Memo", SqlDbType.VarChar);
comcol.Parameters["@SmallClass_Name"].Value = s1;
comcol.Parameters["@Memo"].Value = s2;
comcol.ExecuteNonQuery();
}
finally
{
exsql.Close();
}
}
else
{
SqlConnection sqlConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["DBConnection"]);
try
{
SqlCommand sqlCmd = new SqlCommand(s, sqlConnection);
sqlCmd.Parameters.Add("@SmallClass_Name", System.Data.SqlDbType.Text);
sqlCmd.Parameters.Add("@Memo", System.Data.SqlDbType.Text);
sqlCmd.Parameters["@SmallClass_Name"].Value = s1;
sqlCmd.Parameters["@Memo"].Value = s2;
sqlConnection.Open();
sqlCmd.ExecuteNonQuery();
}
finally
{
sqlConnection.Close();
}
}
DGSClass.EditItemIndex = -1;
BindGrid();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -