.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.Data.SqlClient; using Microsoft.Web.UI.WebControls; using System.Web.Security; using System.Net; using System.Web.Services ; using System.IO;namespace cargo { /// <summary> /// Manager 的摘要说明。 /// </summary> public class Manager : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox TBid; protected System.Web.UI.WebControls.TextBox TBname; protected System.Web.UI.WebControls.TextBox TBpath; protected System.Web.UI.WebControls.TextBox TBnotice; protected System.Web.UI.HtmlControls.HtmlGenericControl Div2; protected System.Web.UI.HtmlControls.HtmlGenericControl Div3; protected System.Web.UI.HtmlControls.HtmlGenericControl Div4; protected System.Web.UI.HtmlControls.HtmlGenericControl Div5; protected System.Web.UI.WebControls.Button Bdelet; protected System.Web.UI.WebControls.Button Breset; protected System.Web.UI.WebControls.DataGrid DataGrid1; protected System.Web.UI.WebControls.Panel Panel1; protected System.Web.UI.HtmlControls.HtmlTable Table1;
private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if (!Page.IsPostBack ) { BindGridToSource(); } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); }
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;
using Microsoft.Web.UI.WebControls;
using System.Web.Security;
using System.Net;
using System.Web.Services ;
using System.IO;namespace cargo
{
/// <summary>
/// Manager 的摘要说明。
/// </summary>
public class Manager : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TBid;
protected System.Web.UI.WebControls.TextBox TBname;
protected System.Web.UI.WebControls.TextBox TBpath;
protected System.Web.UI.WebControls.TextBox TBnotice;
protected System.Web.UI.HtmlControls.HtmlGenericControl Div2;
protected System.Web.UI.HtmlControls.HtmlGenericControl Div3;
protected System.Web.UI.HtmlControls.HtmlGenericControl Div4;
protected System.Web.UI.HtmlControls.HtmlGenericControl Div5;
protected System.Web.UI.WebControls.Button Bdelet;
protected System.Web.UI.WebControls.Button Breset;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.HtmlControls.HtmlTable Table1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (!Page.IsPostBack )
{
BindGridToSource();
}
} #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.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
// this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
this.Breset.Click += new System.EventHandler(this.Breset_Click);
this.Bdelet.Click += new System.EventHandler(this.Bdelet_Click_1);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
public void BindGridToSource()
{
string sql="select * from SiteDirectory where SystemName='cargo' order by LinkId";
SqlDataAdapter sda=new SqlDataAdapter(sql,cargo.Service.cargoService.myConnCargo());
DataTable dt=new DataTable();
sda.Fill(dt);
sda.Dispose();
this.DataGrid1.DataSource=dt;
this.DataGrid1.DataBind();
} private void Breset_Click(object sender, System.EventArgs e)
{
string id=TBid.Text.ToString().Trim();
string name=TBname.Text.ToString().Trim();
string path=TBpath.Text.ToString().Trim();
string notice=TBnotice.Text.ToString().Trim(); string addsql="insert into SiteDirectory (LinkId,SystemName,cLinkName,cLinkRef,cLinkDescription) values ('"+id+"','cargo','"+name+"','"+path+"','"+notice+"')";
SqlCommand sc=new SqlCommand(addsql,cargo.Service.cargoService.myConnCargo());
sc.ExecuteNonQuery();
BindGridToSource();
} private void Bdelet_Click_1(object sender, System.EventArgs e)
{
string id=TBid.Text.ToString().Trim(); string deletsql="delete SiteDirectory where LinkId='"+id+"'";
SqlCommand sc=new SqlCommand(deletsql,cargo.Service.cargoService.myConnCargo());
sc.ExecuteNonQuery();
BindGridToSource();
} private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=e.Item.ItemIndex;
BindGridToSource();
} private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=-1;
BindGridToSource();
} private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string id=e.Item.Cells[1].Text.ToString().Trim();
string name=((TextBox)e.Item.Cells[2].Controls[0]).Text.ToString().Trim();
string path=((TextBox)e.Item.Cells[3].Controls[0]).Text.ToString().Trim();
string notice=((TextBox)e.Item.Cells[4].Controls[0]).Text.ToString().Trim(); string updatecmd="update SiteDirectory set cLinkName='"+name+"',cLinkRef='"+path+"',cLinkDescription='"+notice+"'where LinkId='"+id+"'";
SqlCommand sc=new SqlCommand(updatecmd,cargo.Service.cargoService.myConnCargo());
sc.ExecuteNonQuery();
DataGrid1.EditItemIndex=-1;
BindGridToSource();
}
}
}
<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>
<%@ Register TagPrefix="uc1" TagName="SysMenu" Src="modules/SysMenu.ascx" %>
<%@ Page language="c#" Codebehind="Manager.aspx.cs" AutoEventWireup="false" Inherits="cargo.Manager" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Manager</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="css/cargo.css" type="text/css" rel="stylesheet">
</HEAD>
<body>
<form id="Manager" method="post" runat="server">
<TABLE class="desk" id="Table1" style="Z-INDEX: 102; LEFT: 0px; POSITION: absolute; TOP: -1px" height="100%" cellSpacing="1" cellPadding="1" width="778" border="1" runat="server">
<TBODY>
<TR>
<TD style="HEIGHT: 22px"><uc1:sysmenu id="SysMenu1" runat="server"></uc1:sysmenu></TD>
</TR>
<TR>
<TD class="filltitle" style="HEIGHT: 25px" colSpan="2"><FONT face="宋体">系统资源</FONT>
</TD>
</TR>
<tr>
<td style="HEIGHT: 278px" colSpan="2"><asp:panel id="Panel1" runat="server" Width="725px" Height="214px">
<asp:DataGrid id="DataGrid1" runat="server" Height="174px" Width="724px" AutoGenerateColumns="False" ShowFooter="True" CssClass="datagrid">
<HeaderStyle CssClass="Gheader"></HeaderStyle>
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="更新" HeaderText="编辑" CancelText="取消" EditText="-》"></asp:EditCommandColumn>
<asp:BoundColumn DataField="LinkId" HeaderText="ID" ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn DataField="cLinkName" HeaderText="名称"></asp:BoundColumn>
<asp:BoundColumn DataField="cLinkRef" HeaderText="路径"></asp:BoundColumn>
<asp:BoundColumn DataField="cLinkDescription" HeaderText="备注"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
</asp:panel><FONT face="宋体"> </FONT><FONT face="宋体">
</FONT><FONT face="宋体">
<asp:button id="Breset" runat="server" Width="44px" CssClass="mybutton" Text="添加"></asp:button> </FONT><FONT face="宋体">
<asp:button id="Bdelet" runat="server" Width="44px" CssClass="mybutton" Text="删除"></asp:button>(删除只需要填写ID)</FONT></td>
</tr>
<TR>
<td style="HEIGHT: 25px">
<DIV id="Div2" style="DISPLAY: inline; WIDTH: 25px; HEIGHT: 20px" runat="server" ms_positioning="FlowLayout">ID:</DIV>
<asp:textbox id="TBid" runat="server" Width="45px" CssClass="mytextbox"></asp:textbox>
<DIV id="Div3" style="DISPLAY: inline; WIDTH: 52px; HEIGHT: 21px" runat="server" ms_positioning="FlowLayout">名称:</DIV>
<asp:textbox id="TBname" runat="server" Width="164px" CssClass="mytextbox"></asp:textbox>
<DIV id="Div4" style="DISPLAY: inline; WIDTH: 50px; HEIGHT: 22px" runat="server" ms_positioning="FlowLayout">路径:</DIV>
<asp:textbox id="TBpath" runat="server" Width="148px" CssClass="mytextbox"></asp:textbox>
<DIV id="Div5" style="DISPLAY: inline; WIDTH: 52px; HEIGHT: 21px" runat="server" ms_positioning="FlowLayout">备注:</DIV>
<asp:textbox id="TBnotice" runat="server" Width="166px" CssClass="mytextbox"></asp:textbox></td>
</TR>
</TBODY>
</TABLE>
</form>
</body>
</HTML>