📄 customer_source.aspx
字号:
<!-- #include virtual="/include/pagedirective.inc" -->
<!-- #include virtual="/include/imports.inc" -->
<!-- #include virtual="/include/common_function.inc" -->
<html>
<head>
<link REL="StyleSheet" HREF="/css/standard.css" >
<script language="C#" runat="server">
/*************************************************
* 模块: customer_source.aspx
* 作者: vivid
* 修改: 1/30/2001
* 目的: customer_source table maintain
* 参数: none
* 数据: sel: customer_source
* ins: customer_source
* del: customer_source
* upt: customer_source
***************************************************/
SqlConnection myConnection;
private void Page_Load(Object Src, EventArgs E) {
try {
myConnection = new SqlConnection
(ConfigurationSettings.AppSettings["edu"]);
if (!IsPostBack)
BindGrid();
}
catch (System.Exception e){
ErrorHandler(e.ToString());
}
}
private void Add_Click(Object sender, EventArgs E) {
try{
String insertCmd = "insert into customer_source "
+ "values (@customer_source_id,@customer_source_name)";
SqlCommand myCommand = new SqlCommand(insertCmd, myConnection);
myCommand.Parameters.Add(new SqlParameter("@customer_source_id", SqlDbType.VarChar, 50));
myCommand.Parameters["@customer_source_id"].Value = customer_source_id.Value;
myCommand.Parameters.Add(new SqlParameter("@customer_source_name", SqlDbType.VarChar, 50));
myCommand.Parameters["@customer_source_name"].Value = customer_source_name.Value;
myConnection.Open();
try {
myCommand.ExecuteNonQuery();
MessageSQLInsDone();
}
catch (System.Data.SqlClient.SqlException e) {
SQLErrorHandler(e);
}
myConnection.Close();
BindGrid();
}
catch (System.Exception e){
ErrorHandler(e.ToString());
}
}
public void MyDataGrid_Delete(Object sender, DataGridCommandEventArgs E) {
try{
String deleteCmd = "delete from customer_source where customer_source_id = @customer_source_id";
SqlCommand myCommand = new SqlCommand(deleteCmd, myConnection);
myCommand.Parameters.Add(new SqlParameter("@customer_source_id", SqlDbType.VarChar, 50));
myCommand.Parameters["@customer_source_id"].Value =MyDataGrid.DataKeys[(int)E.Item.ItemIndex];
myConnection.Open();
try {
myCommand.ExecuteNonQuery();
MessageSQLDelDone();
}
catch (System.Data.SqlClient.SqlException e) {
SQLErrorHandler(e);
}
myConnection.Close();
BindGrid();
}
catch (System.Exception e) {
ErrorHandler(e.ToString());
}
}
public void MyDataGrid_Edit(Object sender, DataGridCommandEventArgs E) {
try{
MyDataGrid.EditItemIndex = (int)E.Item.ItemIndex;
BindGrid();
}
catch (System.Exception e) {
ErrorHandler(e.ToString());
}
}
public void MyDataGrid_Cancel(Object sender, DataGridCommandEventArgs E) {
try{
MyDataGrid.EditItemIndex = -1;
BindGrid();
}
catch (System.Exception e) {
ErrorHandler(e.ToString());
}
}
public void MyDataGrid_Update(Object sender, DataGridCommandEventArgs E) {
try{
if (Page.IsValid) {
string updateCmd = "update customer_source set customer_source_name = @customer_source_name where customer_source_id = @customer_source_id";
SqlCommand myCommand = new SqlCommand(updateCmd, myConnection);
myCommand.Parameters.Add(new SqlParameter("@customer_source_id", SqlDbType.VarChar, 50));
myCommand.Parameters["@customer_source_id"].Value = MyDataGrid.DataKeys[(int)E.Item.ItemIndex];
myCommand.Parameters.Add(new SqlParameter("@customer_source_name", SqlDbType.VarChar, 50));
myCommand.Parameters["@customer_source_name"].Value = ((TextBox)E.Item.FindControl("edit_customer_source_name")).Text;
myConnection.Open();
try {
myCommand.ExecuteNonQuery();
MessageSQLUptDone();
MyDataGrid.EditItemIndex = -1;
}
catch (System.Data.SqlClient.SqlException e) {
SQLErrorHandler(e);
}
myConnection.Close();
BindGrid();
}
}
catch (System.Exception e) {
ErrorHandler(e.ToString());
}
}
private void BindGrid() {
try{
SqlDataAdapter myCommand = new SqlDataAdapter("select * from customer_source ", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "customer_source");
MyDataGrid.DataSource=ds.Tables["customer_source"].DefaultView;
MyDataGrid.DataBind();
}
catch (System.Exception e){
ErrorHandler(e.ToString());
}
}
</script>
</head>
<body style="font: 10pt verdana">
<!-- #include virtual="/include/header.inc" -->
<form runat="server">
<table width=100% cellspacing=0 cellpadding=0>
<tr>
<td align="center" class="CONTENTTITLE" width="100%" bgcolor="D3C9C7">
顾客来源数据维护
</td>
</tr>
<tr>
<td>
<span id="Message" EnableViewState="false" class="MESSAGE" runat="server"/>
</td>
</tr>
<td colspan="10" bgcolor="#aaaadd" style="font:10pt verdana">新增:</td>
</table>
<table style="font: 8pt verdana">
<tr>
<TD VALIGN="top" ALIGN="left"><span class="REQUIREDFIELD">顾客来源代码:</span><BR><input type="text" id="customer_source_id" value="000" runat="server"></FONT></TD>
<TD VALIGN="top" ALIGN="left"><span class="REQUIREDFIELD">顾客来源代码:</span><BR><input type="text" id="customer_source_name" value="000" runat="server"></FONT></TD>
<TD VALIGN="top" ALIGN="left">
<FONT FACE="Verdana,Helvetica,Arial" SIZE=1> <BR>
<input type="submit" OnServerClick="Add_Click" value="新增" runat="server">
</FONT>
</TD>
</tr>
<TR>
<TD ><asp:RequiredFieldValidator ControlToValidate="customer_source_id" Display="Static" ErrorMessage="*:不可空白" runat=server/></TD>
<TD ><asp:RequiredFieldValidator ControlToValidate="customer_source_name" Display="Static" ErrorMessage="*:不可空白" runat=server/></TD>
</TR>
</table>
<table style="font: 8pt verdana" width=100% >
<tr>
<td colspan="5" bgcolor="#aaaadd" style="font:10pt verdana">修改/删除:</td>
</tr>
</table>
<ASP:DataGrid id="MyDataGrid" runat="server"
BackColor="#F4FFF4"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="lightblue"
OnDeleteCommand="MyDataGrid_Delete"
DataKeyField="customer_source_id"
AutoGenerateColumns="false"
>
<Columns>
<asp:ButtonColumn Text="删除" CommandName="Delete" ButtonType="PushButton" />
<asp:TemplateColumn HeaderText="顾客来源代码" >
<ItemTemplate>
<a href="customer_source_upt.aspx?customer_source_id=<%# DataBinder.Eval(Container.DataItem, "customer_source_id") %>">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "customer_source_id") %>'/> </a>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="顾客来源名称" SortExpression="customer_source_name">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "customer_source_name") %>'/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</ASP:DataGrid>
</form>
<!-- #include virtual="/include/footer.inc" -->
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -