《产品小类管理实训.docx》由会员分享,可在线阅读,更多相关《产品小类管理实训.docx(8页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、实训七 产品小类管理实训目的:实训内容:实训过程:1. 界面制作(smallClass.aspx页面)该页面全部静态代码如下: 无标题页 小类名称: 所属大类: 小类编号: asp:Label ID=Label1 runat=server Text= asp:HiddenField ID=HiddenField2 runat=server Value= / asp:HiddenField ID=HiddenField1 runat=server Value= / asp:Label ID=Label1 runat=server Text= asp:HiddenField ID=H
2、iddenField2 runat=server Value= / 2. 动态代码編写(smallclass.aspx.cx)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 System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using Sy
3、stem.Web.UI.WebControls.WebParts;using System.Xml.Linq;public 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, select * from bigclass
4、, bigName, bigID, null); void binddata() GridView1.DataSource = db.getDataView(select * from smallClass); GridView1.DataBind(); protected void Button1_Click(object sender, EventArgs e) if (Sessionquanxian != null & Sessionquanxian.ToString() != 0) ScriptManager.RegisterStartupScript(this, GetType(),
5、 , alert(对不起,您的权限不够!), true); return; else if (TextBox1.Text.Trim().Length 0 & TextBox2.Text.Trim().Length 0) if (!db.isExist(select * from smallClass where smallID= + TextBox2.Text.Trim() + and smallName= + TextBox1.Text.Trim() + and bigid= + DropDownList1.SelectedValue.ToString()+) db.sqlExecute(i
6、nsert into smallClass(smallName,smallID,bigID) values( + TextBox1.Text.Trim() + , + TextBox2.Text.Trim() + , + DropDownList1.SelectedValue.ToString() + ); binddata(); else ScriptManager.RegisterStartupScript(this, GetType(), , alert(小类编号或小类名称不能相同!), true); else ScriptManager.RegisterStartupScript(th
7、is, GetType(), , alert(小类名称和小类编号不能为空), true); protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) TextBox tbsmallName, tbsmallID; DropDownList drpBigClass; string sqlcheck=,sqlupdate=; tbsmallID = (TextBox)GridView1.Rowse.RowIndex.Cells2.Controls0; tbsmallName = (TextBox)G
8、ridView1.Rowse.RowIndex.Cells1.Controls0; drpBigClass = (DropDownList)GridView1.Rowse.RowIndex.Cells0.FindControl(DropDownList2); if (tbsmallName.Text.Trim().Length 0 & tbsmallID.Text.Trim().Length 0) sqlcheck=select * from (select * from smallclass where id + GridView1.DataKeyse.RowIndex.Value + )
9、as t1 where smallid=+ tbsmallID.Text.Trim()+ or smallname=+tbsmallName.Text.Trim()+; if (!db.isExist(sqlcheck) db.sqlExecute(update smallClass set smallName= + tbsmallName.Text.Trim() + ,smallID= + tbsmallID.Text.Trim() + ,bigID= + drpBigClass.SelectedValue.ToString() + where id= + GridView1.DataKey
10、se.RowIndex.Value); GridView1.EditIndex = -1; binddata(); else ScriptManager.RegisterStartupScript(this, GetType(), , alert(小类编号或小类名称不能相同), true); /GridView1.EditIndex = -1; / binddata(); return; else ScriptManager.RegisterStartupScript(this, GetType(), , alert(小类名称和小类编号不能为空), true); protected void
11、GridView1_RowEditing(object sender, GridViewEditEventArgs e) if (Sessionquanxian != null & Sessionquanxian.ToString() != 0) ScriptManager.RegisterStartupScript(this, GetType(), , alert(对不起,您的权限不够!), true); return; else GridView1.EditIndex = e.NewEditIndex; binddata(); protected void GridView1_RowDel
12、eting1(object sender, GridViewDeleteEventArgs e) if (Sessionquanxian != null & Sessionquanxian.ToString() != 0) ScriptManager.RegisterStartupScript(this, GetType(), , alert(对不起,您的权限不够!), true); return; else db.sqlExecute(delete from smallClass where id= + GridView1.DataKeyse.RowIndex.Value); binddat
13、a(); protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) GridView1.EditIndex = -1; binddata(); protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) DataRow dr; Label Lb; DropDownList ddl; HiddenField hf; if (e.Row.RowType = DataControlRowTy
14、pe.DataRow) e.Row.Attributes.Add(onmouseover, bg=this.style.backgroundColor; this.style.backgroundColor=#dddddd); e.Row.Attributes.Add(onmouseout, this.style.backgroundColor=bg); if (e.Row.RowState = DataControlRowState.Alternate | e.Row.RowState = DataControlRowState.Normal) Lb = (Label)e.Row.Cells
15、0.FindControl(Label1); hf = (HiddenField)e.Row.Cells0.FindControl(HiddenField2); dr = db.getDataRow(select * from bigClass where bigid= + hf.Value.ToString() + ); Lb.Text = drbigname.ToString(); if (e.Row.RowState = DataControlRowState.Edit | e.Row.RowState = (DataControlRowState.Alternate | DataControlRowState.Edit) ) ddl = (DropDownList)e.Row.Cells0.FindControl(DropDownList2); hf = (HiddenField)e.Row.Cells0.FindControl(HiddenField1); db.initDropDownList(ddl, select * from bigclass, bigname, bigID, hf.Value.ToString();