addScope.aspx
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="addScope.aspx.cs" Inherits="addScope" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <style type="text/css">
- #div1
- {
- height: 52px;
- width: 1055px;
- }
- </style>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:Label ID="Label1" runat="server" Text="货物名称"></asp:Label><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
- <asp:Button ID="Button1" runat="server" Text="查询" οnclick="Button1_Click" />
- <br />
- <asp:GridView ID="GridView1" runat="server" AllowPaging="True" OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="false">
- <HeaderStyle BackColor="Azure" Font-Size="12px" HorizontalAlign="Center" />
- <RowStyle HorizontalAlign="Center" />
- <Columns>
- <asp:BoundField HeaderText="编号" />
- <asp:TemplateField HeaderText ="商品名称" >
- <ItemTemplate >
- <asp:LinkButton ID="LinkButton1" runat="server" Text='<%#Eval("商品名称") %>' ToolTip='<%#Eval("商品编号") %>' OnClick="Button3_Click" ></asp:LinkButton>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:BoundField HeaderText="数量" DataField ="数量" />
- <asp:BoundField HeaderText="最大数量" DataField ="最大数量" />
- <asp:BoundField HeaderText="规格型号" DataField ="规格型号" />
- <asp:BoundField HeaderText="单位" DataField ="单位" />
- <asp:BoundField HeaderText="大类" DataField ="大类" />
- <asp:BoundField HeaderText="中类" DataField ="中类" />
- <asp:BoundField HeaderText="ABC类" DataField ="ABC类" />
- </Columns>
- <PagerStyle HorizontalAlign="Center" BackColor="#FFFFCC" BorderStyle="None" BorderWidth="0px" ForeColor="#330099" />
- <PagerSettings Visible="False" />
- </asp:GridView>
- <div runat="server" id="ss" visible ="false">
- <asp:LinkButton ID="lnkbtnFrist" runat="server" OnClick="lnkbtnFrist_Click" >首页</asp:LinkButton>
- <asp:LinkButton ID="lnkbtnPre" runat="server" OnClick="lnkbtnPre_Click" >上一页</asp:LinkButton>
- <asp:Label ID="lblCurrentPage" runat="server" ></asp:Label>
- <asp:LinkButton ID="lnkbtnNext" runat="server" OnClick="lnkbtnNext_Click" >下一页</asp:LinkButton>
- <asp:LinkButton ID="lnkbtnLast" runat="server" OnClick="lnkbtnLast_Click" >尾页</asp:LinkButton>
- 跳转到第<asp:DropDownList ID="ddlCurrentPage" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
- </asp:DropDownList>页
- </div>
- <br />
- </div>
- </form>
- </body>
- </html>
addScope.aspx.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Configuration;
- using System.Data.SqlClient;
- using System.Data;
- public partial class addScope : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- /// <summary>
- /// 提交按钮,定义存储范围
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected void Button3_Click(object sender, EventArgs e)
- {
- if (TextBox1.Text == null || TextBox1.Text == string.Empty)
- {
- TextBox1.Focus();
- }
- else
- {
- LinkButton lb = sender as LinkButton;
- string id = lb.ToolTip;
- string connectionString = ConfigurationManager.ConnectionStrings["DefaultConnectionString"].ConnectionString;
- SqlConnection conn = new SqlConnection();
- conn.ConnectionString = connectionString;
- conn.Open();
- SqlCommand cmd = new SqlCommand("UpLoadImage", conn);
- SqlCommand cmd2 = new SqlCommand("addscope", conn);
- cmd.CommandType = CommandType.Text;
- cmd.Parameters.Add("@goodid", SqlDbType.Int);
- cmd.Parameters["@goodid"].Value = int.Parse(id);
- cmd.CommandText = string.Format("SELECT [GoodsId] as 商品编号 ,[GoodsName] as 商品名称,[GoodsNo] as 零配件号图号" +
- ",[ABCTypeName] as ABC类 ,[UnitName] as 单位 ,[MiddleTypeName] as 中类,[GoodsTypeName] as 大类,[ModelName] as 规格型号" +
- " ,[InventoryLevels] as 数量 ,[MaxLevels] as 最大数量 FROM [kuweichaxun].[dbo].[part_goodsview] where goodsid =@goodid");
- SqlDataReader resultOfgood = cmd.ExecuteReader();
- while (resultOfgood.Read())
- {
- cmd2.Parameters.Add("@goodname", SqlDbType.NVarChar);
- cmd2.Parameters["@goodname"].Value = resultOfgood["商品名称"];
- cmd2.Parameters.Add("@number", SqlDbType.Int);
- cmd2.Parameters["@number"].Value = resultOfgood["数量"];
- cmd2.Parameters.Add("@maxnumber", SqlDbType.Int);
- cmd2.Parameters["@maxnumber"].Value = resultOfgood["最大数量"];
- cmd2.Parameters.Add("@goodid", SqlDbType.Int);
- cmd2.Parameters["@goodid"].Value = resultOfgood["商品编号"];
- cmd2.Parameters.Add("@goodno", SqlDbType.NVarChar);
- cmd2.Parameters["@goodno"].Value = resultOfgood["零配件号图号"];
- cmd2.Parameters.Add("@modelname", SqlDbType.NVarChar);
- cmd2.Parameters["@modelname"].Value = resultOfgood["规格型号"];
- cmd2.Parameters.Add("@calname", SqlDbType.NVarChar);
- cmd2.Parameters["@calname"].Value = resultOfgood["单位"];
- cmd2.Parameters.Add("@goodtype", SqlDbType.NVarChar);
- cmd2.Parameters["@goodtype"].Value = resultOfgood["大类"];
- cmd2.Parameters.Add("@middletype", SqlDbType.NVarChar);
- cmd2.Parameters["@middletype"].Value = resultOfgood["中类"];
- cmd2.Parameters.Add("@abctype", SqlDbType.NVarChar);
- cmd2.Parameters["@abctype"].Value = resultOfgood["ABC类"];
- }
- resultOfgood.Dispose();
- int Row = int.Parse(Request.QueryString["row"].ToString());
- int Floor = int.Parse(Request.QueryString["floor"].ToString());
- int Line = int.Parse(Request.QueryString["line"].ToString());
- int Bit = int.Parse(Request.QueryString["bit"].ToString());
- cmd2.CommandText = string.Format("update storeinfo set goodname = @goodname,isdefine = 1,number=@number,maxnumber=@maxnumber, goodid=@goodid,goodno =@goodno,"+
- "modelname =@modelname ,calname =@calname ,goodtype =@goodtype,middletype =@middletype,abctype =@abctype where row = {0} and floor = {1} and line = {2} and bit ={3}",
- Row, Floor, Line, Bit);
- cmd.Dispose();
- cmd2.ExecuteNonQuery();
- cmd2.Dispose();
- conn.Close();
- Response.Write("<script>window.top.location= window.top.location;</script>");
- }
- }
- /// <summary>
- /// 查询按钮,适应于模糊匹配
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected void Button1_Click(object sender, EventArgs e)
- {
- string connectionString = ConfigurationManager.ConnectionStrings["DefaultConnectionString"].ConnectionString;
- SqlConnection conn = new SqlConnection();
- conn.ConnectionString = connectionString;
- conn.Open();
- DataTable table = new DataTable();
- SqlDataAdapter adapter = new SqlDataAdapter();
- SqlCommand cmd = new SqlCommand("UpLoadImage", conn);
- if (TextBox1.Text == null || TextBox1.Text == string.Empty)
- {
- cmd.CommandText = string.Format("SELECT [GoodsId] as 商品编号 ,[GoodsName] as 商品名称,[GoodsNo] as 零配件号图号" +
- ",[ABCTypeName] as ABC类 ,[UnitName] as 单位 ,[MiddleTypeName] as 中类,[GoodsTypeName] as 大类,[ModelName] as 规格型号" +
- " ,[InventoryLevels] as 数量 ,[MaxLevels] as 最大数量 FROM [kuweichaxun].[dbo].[part_goodsview]");
- }
- else
- {
- cmd.CommandText = string.Format("SELECT [GoodsId] as 商品编号 ,[GoodsName] as 商品名称,[GoodsNo] as 零配件号图号" +
- ",[ABCTypeName] as ABC类 ,[UnitName] as 单位 ,[MiddleTypeName] as 中类,[GoodsTypeName] as 大类,[ModelName] as 规格型号" +
- " ,[InventoryLevels] as 数量 ,[MaxLevels] as 最大数量 FROM [kuweichaxun].[dbo].[part_goodsview] where GoodsName like '%{0}%'", TextBox1.Text);
- }
- int i = cmd.ExecuteNonQuery();
- adapter.SelectCommand = cmd;
- adapter.Fill(table);
- GridView1.DataSource = table;
- GridView1.DataBind();
- cmd.Dispose();
- conn.Close();
- ss.Visible = true;
- }
- /// <summary>
- /// 在 GridView 控件中的某个行被绑定到一个数据记录时发生。此事件通常用于在某个行被绑定到数据时修改该行的内容。
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- this.lblCurrentPage.Text = string.Format("当前第{0}页/总共{1}页", this.GridView1.PageIndex + 1, this.GridView1.PageCount);
- //遍历所有行设置边框样式
- foreach (TableCell tc in e.Row.Cells)
- {
- tc.Attributes["style"] = "border-color:Black";
- }
- //用索引来取得编号
- if (e.Row.RowIndex != -1)
- {
- int id = GridView1.PageIndex * GridView1.PageSize + e.Row.RowIndex + 1;
- e.Row.Cells[0].Text = id.ToString();
- }
- }
- /// <summary>
- /// 重新绑定
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
- {
- this.GridView1.PageIndex = this.ddlCurrentPage.SelectedIndex;
- bind();
- }
- protected void lnkbtnFrist_Click(object sender, EventArgs e)
- {
- this.GridView1.PageIndex = 0;
- bind();
- }
- protected void lnkbtnPre_Click(object sender, EventArgs e)
- {
- if (this.GridView1.PageIndex > 0)
- {
- this.GridView1.PageIndex = this.GridView1.PageIndex - 1;
- bind();
- }
- }
- protected void lnkbtnNext_Click(object sender, EventArgs e)
- {
- if (this.GridView1.PageIndex < this.GridView1.PageCount)
- {
- this.GridView1.PageIndex = this.GridView1.PageIndex + 1;
- bind();
- }
- }
- protected void lnkbtnLast_Click(object sender, EventArgs e)
- {
- this.GridView1.PageIndex = this.GridView1.PageCount;
- bind();
- }
- /// <summary>
- /// 绑定数据
- /// </summary>
- public void bind()
- {
- string connectionString = ConfigurationManager.ConnectionStrings["DefaultConnectionString"].ConnectionString;
- SqlConnection conn = new SqlConnection();
- conn.ConnectionString = connectionString;
- conn.Open();
- DataTable table = new DataTable();
- SqlDataAdapter adapter = new SqlDataAdapter();
- SqlCommand cmd = new SqlCommand("UpLoadImage", conn);
- if (TextBox1.Text == null || TextBox1.Text == string.Empty)
- {
- cmd.CommandText = string.Format("SELECT [GoodsId] as 商品编号 ,[GoodsName] as 商品名称,[GoodsNo] as 零配件号图号" +
- ",[ABCTypeName] as ABC类 ,[UnitName] as 单位 ,[MiddleTypeName] as 中类,[GoodsTypeName] as 大类,[ModelName] as 规格型号" +
- " ,[InventoryLevels] as 数量 ,[MaxLevels] as 最大数量 FROM [kuweichaxun].[dbo].[part_goodsview] ");
- }
- else
- {
- cmd.CommandText = string.Format("SELECT [GoodsId] as 商品编号 ,[GoodsName] as 商品名称,[GoodsNo] as 零配件号图号" +
- ",[ABCTypeName] as ABC类 ,[UnitName] as 单位 ,[MiddleTypeName] as 中类,[GoodsTypeName] as 大类,[ModelName] as 规格型号" +
- " ,[InventoryLevels] as 数量 ,[MaxLevels] as 最大数量 FROM [kuweichaxun].[dbo].[part_goodsview]where GoodsName like '%{0}%'", TextBox1.Text);
- }
- cmd.ExecuteNonQuery();
- adapter.SelectCommand = cmd;
- adapter.Fill(table);
- GridView1.DataSource = table;
- GridView1.DataBind();
- this.ddlCurrentPage.Items.Clear();
- for (int i = 1; i <= this.GridView1.PageCount; i++)
- {
- this.ddlCurrentPage.Items.Add(i.ToString());
- }
- this.ddlCurrentPage.SelectedIndex = this.GridView1.PageIndex;
- }
- }