实训七产品小类管理
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实训七产品小类管理
实训目的:
实训内容:
实训过程:
1.界面制作(smallClass.aspx 页面)该页面全部静态代码如下:
v%@Page Language二"C#" AutoEventWireup 二"true"
Debug="true" In herits 二"bigClass" %> CodeFile 二"smallClass.aspx.cs"
<! DOCTYPBhtml PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "htt
p:///TR/xhtml1/DTD/xhtml1-tra nsitio nal.dtd">
<html xml ns ="htt p:///1999/xhtml">
<head runat 二"server"〉
<title >无标题页</ title >
<li nk href ="style.css" rel ="stylesheet" type ="text/css" />
</head〉
<body>
<form id ="form1" runat ="server">
<div >
<asp: ScriptManager ID ="ScriptManager1" runat ="server"> </ asp:
ScriptManager > <table align ="center" cellpadding ="0" cellspacing ="0"
width ="800">
<tr >
<td >
<asp: UpdatePanel ID="UpdatePanel1" runat ="server">
<ContentTemplate >
<table align ="center" cellpadding ="0" cellspacing ="0" width ="100%"
style ="border : 1px solid #C0C0C;0
margin-top : 5px; margin-bottom : 5px; ">
<tr bgcolor ="Silver">
<td align ="center" width ="200">
小类名称:</td >
<asp: TextBox ID="TextBox1"
="server" Width ="92px"></ asp: TextBox >
</td > <td align ="center" height ="35">
<asp: DropDownList
ID ="DropDownList1" runat ="server">
</ asp: DropDownList >
<td align ="center" height ="35"
width ="200">
所属大类: </ td
<td align ="center" height ="35"
width ="200">
小类编号: </ td
<td align ="center">
</ td >
</ tr >
<tr >
<td align ="center">
runat
</td > <td align ="center" height ="35">
<asp: TextBox ID="TextBox2"
runat ="server" Width ="82px"></ asp: TextBox >
</td > <td align ="center">
<asp: Button ID ="Button1"
runat ="server" onclick ="Button1_Click" Text ="添加"
Width ="77px" />
</td >
</ tr >
</ table > <asp: GridView ID ="GridView1" runat
="server"
AutoGenerateColumns ="False"
BackColor ="White" BorderColor ="#3366CC"
BorderStyle ="None" BorderWidth ="1px"
CellPadding ="4" CssClass ="gridview" DataKeyNames="id" onrowcancelingedit ="GridView1_RowCancelingEdit"
onrowdatabound ="GridView1_RowDataBound" onrowdeleting ="GridView1_RowDeleting1"
onrowediting ="GridView1_RowEditing"
onrowupdating ="GridView1_RowUpdating"
Width ="100%"> <FooterStyle BackColor
="#99CCCC"
ForeColor ="#003399" />
<RowStyle BackColor ="White"
ForeColor ="#003399" />
<Columns>
<asp: TemplateField HeaderText =" 大类名称">
<AlternatingItemTemplate >
<asp: Label ID ="Label1"
runat ="server" Text =' <%# Bind("bigID") %> '></ asp: Label >
<asp: HiddenField
ID="Hidde nField2" runat 二"server"
Value =' <%#
Eval("biglD") %> />
</ Alter nati ngItemTe mp late
>
vEditItemTe mp late >
<as p: Drop Dow nList
ID="Dro pDow nList2" runat 二"server"〉
</ as p: Drop Dow nList >
<asp: HiddenField
ID="Hidde nFieldl" runat 二"server"
Value =' <%#
Eval("bigID") %> />
</ EditItemTemplate >
<ItemTemplate >
runat 二"server" Text =' <%# Bind("bigID") %> '></ asp: Label >
<asp: Label ID="Label1"
<asp: HiddenField
ID ="HiddenField2" runat 二"server"
Value =' <%#
Eval("biglD") %> ' />
</ ItemTemplate > vltemStyle
Width ="150px" />
</ asp: TemplateField >
<asp: BoundField
DataField 二"smallName" HeaderText ="小类名称">
<ItemStyle Width ="150px" />
</ asp: BoundField >
<asp: BoundField DataField 二
"smalllD"
HeaderText ="小类编号">
vltemStyle Width ="150px" />
</ asp: BoundField >
<asp: CommandField
ShowEditButton ="True" />
<ItemStyle Width ="100px" />
</ asp: CommandField>
</ Columns>
<PagerStyle BackColor ="#99CCCC"
="#003399" HorizontalAlign ="Left" />
<SelectedRowStyle BackColor ="#009999"
<HeaderStyle BackColor ="#003399"
</ asp : GridView >
</ ContentTemplate >
</ asp: UpdatePanel >
</ td>
</ tr
ShowDeleteButton ="True"> <asp: CommandField
ForeColor Font-Bold ="True" ForeColor ="#CCFF99" />
Font-Bold ="True" ForeColor ="#CCCCFF"/>
</ table >
</div >
</ form > </ body> </ html> 2. 动态代码编写 (smallclass.aspx.cx)
System.Web.UI.HtmlControls;
System.Web.UI.WebControls;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using using
System.Web.UI.WebControls.WebParts;
partial class bigClass : System.Web.UI. Page
public DBfunction db = new DBfunction ();
protected void Page_Load( object sender, EventArgs e) db.isLogin();
if (!IsPostBack)
binddata();
db.initDropDownList(DropDownList1,
"bigName" , "bigID" , null );
void binddata()
using using System.Xml.Linq;
public
"select * from bigclass"
= db.getDataView( "select * from
smallClass" );
GridView1.DataBind();
protected void Button1_Click( object sender, EventArgs e)
if (Session[ "quanxian" ] != null &&
ScriptManager .RegisterStartupScript( this , GetType(),
对不起,您的权限不够 !')" , true );
return ;
else
if (TextBox1.Text.Trim().Length > 0 &&
TextBox2.Text.Trim().Length > 0)
Session[ "quanxian" ].ToString() != "0"
)
GridView1.DataSource Illi "alert('
if (!db.isExist( "select * from smallClass where smallID='"
+ TextBox2.Text.Trim() + "' and smallName='" + TextBox1.Text.Trim() + "' and bigid='" + DropDownList1.SelectedValue.ToString()+
DropDownList1.SelectedValue.ToString() + binddata();
else
ScriptManager .RegisterStartupScript( this , GetType(),
小类编号或小类名称不能相同! ')" , true );
ScriptManager .RegisterStartupScript( this , GetType(),
小类名称和小类编号不能为空 ')" , true );
"'" ))
db.sqlExecute( "insert into
smallClass(smallName,smallID,bigID) values('" + TextBox1.Text.Trim() +
Ill III + TextBox2.Text.Trim() + "','" +
);
"" , "alert(' Illi "alert('
else
protected void GridView1_RowUpdating( object sender, GridViewUpdateEventArgs e)
TextBox tbsmallName, tbsmallID;
DropDownList drpBigClass;
string sqlcheck= "" ,sqlupdate= ""
tbsmallID = ( TextBox )GridView1.Rows[e.RowIndex].Cells[2].Controls[0];
tbsmallName = ( TextBox )GridView1.Rows[e.RowIndex].Cells[1].Controls[0];
drpBigClass =
( DropDownList )GridView1.Rows[e.RowIndex].Cells[0].FindControl( "DropDownL
ist2" )
;
if (tbsmallName.Text.Trim().Length > 0 &&
tbsmallID.Text.Trim().Length >
0)
sqlcheck= "select * from (select * from smallclass where
id<>"
+ GridView1.DataKeys[e.RowIndex].Value + ") as t1 where
smallid='"
tbsmallID.Text.Trim()+ "' or smallname='" +tbsmallName.Text.Trim()+ Hill
if
(!db.isExist(sqlcheck))
db.sqlExecute( "update smallClass set smallName='" tbsmallName.Text.Trim() + "',smallID='" + tbsmallID.Text.Trim() +
"',bigID='" + drpBigClass.SelectedValue.ToString() + "' where
id="
GridView1.DataKeys[e.RowIndex].Value);
GridView1.EditIndex = -
1;
binddata()
;
}
else
ScriptManager .RegisterStartupScript( this , GetType(), Illi 小类编号或小类名称不能相同')" , true );
"alert
('
//GridView1.EditIndex = -
1;
//
binddata();
return ;
else
ScriptManager .RegisterStartupScript( this , GetType(), Illi 小类名称和小类编号不能为空')" , true );
"alert
('
protected void GridView1_RowEditing( object sender,
GridViewEditEventArgs e)
{
if (Session[ "quanxian" ] != null &&
ScriptManager .RegisterStartupScript( this , GetType(),
对不起,您的权限不够 !')" , true );
return ;
else
GridView1.EditIndex = e.NewEditIndex;
binddata();
protected void GridView1_RowDeleting1( object sender,
GridViewDeleteEventArgs e)
Session[ "quanxian" ].ToString() != "0" )
Illi "alert('
if (Session[ "quanxian" ] != null &&
Session[ "quanxian" ].ToString() != "0" )
ScriptManager .RegisterStartupScript( this , GetType(), Illi "alert(' 对不起,您的权限不够!')" , true );
return ;
else
db.sqlExecute( "delete from smallClass where id="
GridView1.DataKeys[e.RowIndex].Value);
binddata();
protected void GridView1_RowCancelingEdit( object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
binddata();
protected void GridView1_RowDataBound( object sender,
GridViewRowEventArgs e)
DataRowdr;
Label Lb;
DropDownList ddl;
HiddenField hf;
if (e.Row.RowType == DataControlRowType .DataRow)
"bg=this.style.backgroundColor; this.style.backgroundColor='#dddddd'"
"this.style.backgroundColor=bg" if (e.Row.RowState == DataControlRowState .Alternate ||
e.Row.Attributes.Add( "onmouseover"
e.Row.Attributes.Add( "onmouseout" ,
); );
e.Row.RowState == DataControlRowState .Normal)
Lb = ( Label )e.Row.Cells[0].FindControl( "Label1" );
hf =
( HiddenField )e.Row.Cells[0].FindControl( "HiddenField2" );
dr = db.getDataRow( "select * from bigClass where bigid='" + hf.Value.ToString() + "'" );
Lb.Text = dr[ "bigname" ].ToString();
if (e.Row.RowState == DataControlRowState .Edit ||
e.Row.RowState == ( DataControlRowState .Alternate |
DataControlRowState .Edit) )
ddl =
( DropDownList )e.Row.Cells[0].FindControl( "DropDownList2" );
hf =
( HiddenField )e.Row.Cells[0].FindControl( "HiddenField1" );
db.initDropDownList(ddl, "select * from bigclass" "bigname" , "bigID" , hf.Value.ToString());
}。