ERP仓库管理系统查询(十)

网友投稿 742 2022-08-31

ERP仓库管理系统查询(十)

ERP仓库管理系统查询(十)

需求:

1.根据仓库编号,获取仓库信息绑定至页面相关控件。

2.根据仓库编号,获取管理员信息绑定到页面相关控件

修改的界面:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StockEdit.aspx.cs" Inherits="BioErpWeb.StockSystem.StockEdit" %><%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

仓库信息管理系统
库房名称:
库房地址:
所属公司
仓库管理员
仓库状态 正常 停用

存储过程(使用通用的):

-- Description: 根据指定列,指定条件,指定表查询数据-- =============================================ALTER PROCEDURE [dbo].[GetDataByCondition] @tableName nvarchar(200), @columns nvarchar(500), @condition nvarchar(500)=' 1=1' ASBEGIN SET NOCOUNT ON; DECLARE @sqlStr nvarchar(2000) SET @sqlStr='select '+@columns+' from '+@tableName+' where '+@condition EXEC(@sqlStr) END

定义一个标量值函数:

-- Description: 根据员工编号返回员工姓名-- =============================================ALTER FUNCTION [dbo].[getUserNameByUserID]( @UserID int)RETURNS Nvarchar(20)ASBEGIN -- Declare the return variable here DECLARE @UserName nvarchar(20) -- Add the T-SQL statements to compute the return value here SELECT @UserName=UserName FROM UserManager WHERE UserManager.UserId=@UserID -- Return the result of the function RETURN @UserNameEND

根据条件返回一个数据阅读器对象

///

/// 根据条件返回一个数据阅读器对象 /// /// public static SqlDataReader GetDataReaderByCondition(string tableName, string columns, string condition) { SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@tableName",tableName), new SqlParameter("@columns",columns), new SqlParameter("@condition",condition) }; SqlDataReader reader = DataBaseHelper.SelectSQLReturnReader("GetDataByCondition", CommandType.StoredProcedure, pars); return reader; }

BLL层的代码:

///

/// 根据ID查询仓库表内容 /// /// 仓库ID /// StockTable public StockTable getStockTableByID(int id) { //调用的通用的存储过程 SqlDataReader reader= SqlComm.GetDataReaderByCondition("BioErpStockTable", "*", " id="+id.ToString()); StockTable stock = new StockTable(); stock.ID = id; while (reader.Read()) { stock.StockName = reader["StockName"].ToString(); stock.StockAddress = reader["StockAddress"].ToString(); stock.FarhterCompany = int.Parse(reader["FarhterCompany"].ToString()); stock.IsDel = bool.Parse(reader["IsDel"].ToString()); } reader.Close(); return stock; }

根据StockID绑定员工列表

///

/// 根据StockID绑定员工列表 /// /// StockID /// DataTable public DataTable getStockUsersListByStockID(int id) { DataTable dt = CommTool.SqlComm.GetDataByCondition("BioErpStockUsers", "ID,StockID,UserID,Username=dbo.getUserNameByUserID(UserID)", " StockID=" + id.ToString()).Tables[0]; return dt; }

后台的代码:

public partial class StockEdit : System.Web.UI.Page { CompanyTableBll companybll = new CompanyTableBll(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { CompanyListBind(); StockInfoBind(); StockUsersIist(); } } BioErpStockTableBLL stocktablebll = new BioErpStockTableBLL(); BioErpStockUsersBLL stockuserbll = new BioErpStockUsersBLL(); static BioErpStockUsers stockusers = new BioErpStockUsers(); static StockTable stocktable = new StockTable(); ///

/// 仓库基本信息绑定 /// private void StockInfoBind() { if (Request.QueryString["stockid"] != null) { string id= Request.QueryString["stockid"].ToString(); stocktable= stocktablebll.getStockTableByID(int.Parse(id)); this.txtStockName.Text= stocktable.StockName; this.txtAddress.Text = stocktable.StockAddress; this.ddlCompany.SelectedValue = stocktable.FarhterCompany.ToString(); this.ddlState.SelectedValue = Convert.ToBoolean(stocktable.IsDel) ? "0" : "1"; } else { Server.Transfer("StockTableList.aspx"); } } private void CompanyListBind() { this.ddlCompany.DataSource = companybll.GetCompanyList(); this.ddlCompany.DataTextField = "CompanyName"; this.ddlCompany.DataValueField = "ID"; this.ddlCompany.DataBind(); this.ddlCompany.Items.Add(new ListItem("--请选择--","0")); this.ddlCompany.SelectedValue = "0"; } /// /// 绑定仓库管理员列表 /// private void StockUsersIist() { if (Request.QueryString["stockid"] != null) { string id=Request.QueryString["stockid"].ToString(); //查询仓库的管理员列表 System.Data.DataTable dt= stockuserbll.getStockUsersListByStockID(int.Parse(id)); string userids = ""; for (int i = 0; i < dt.Rows.Count; i++) { userids = userids + dt.Rows[i]["UserID"].ToString()+","; } //计算仓库管理员个数 int count = dt.Rows.Count; //调用RegisterStartupScript方法去调用前端的addRow 脚本函数 实现动态添加表格 ClientScript.RegisterStartupScript(this.GetType(), "test", "addRow(" + count + ");", true); ClientScript.RegisterStartupScript(this.GetType(), "setValues", "setValues('" + userids + "');", true); } } protected void btnSubmit_Click(object sender, EventArgs e) { stocktable.StockName = txtStockName.Text; stocktable.StockAddress = txtAddress.Text; stocktable.IsDel = this.ddlState.SelectedValue == "1" ? false : true; stocktable.FarhterCompany =int.Parse(ddlCompany.SelectedValue.ToString()); stocktablebll.StockTableUpdate(stocktable); string userids= Request["UserId"].ToString(); string[] useridlist = userids.Split(','); SqlComm.DeleteTableByCondition("BioErpStockUsers", "where StockID="+stocktable.ID.ToString()); for (int i = 0; i < useridlist.Length; i++) { stockusers.StockID = stocktable.ID; stockusers.UserID =int.Parse(useridlist[i].ToString()); stockuserbll.StockUserAdd(stockusers); } Server.Transfer("StockTableList.aspx"); } }

分页:

前台页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StockTableList.aspx.cs" Inherits="BioErpWeb.StockSystem.StockTableList" %><%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>

仓库信息管理系统
仓库名: 仓库地址: 所属公司: 状态: 正常 停用

分页及查询的后台:

public partial class StockTableList : System.Web.UI.Page { static string Condition = ""; static int pageindex=0; static int pagesize = 8; CompanyTableBll companybll = new CompanyTableBll(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.AspNetPager1.RecordCount = SqlComm.getDataCountByCondition("View_StockList", Condition); this.AspNetPager1.PageSize = pagesize; getCompanyList(); getStockList(); } } private void getCompanyList() { this.ddlCompany.DataSource = companybll.GetCompanyList(); this.ddlCompany.DataTextField = "CompanyName"; this.ddlCompany.DataValueField = "ID"; this.ddlCompany.DataBind(); this.ddlCompany.Items.Add(new ListItem("--请选择--", "0")); this.ddlCompany.SelectedValue = "0"; } ///

/// 获取仓库信息列表 /// private void getStockList() { this.GridView1.DataSource= SqlComm.getDataByPageIndex("View_StockList", "ID,StockName,FarhterCompany,StockAddress,IsDel,UserNames", "ID",Condition, pageindex, pagesize); this.GridView1.DataBind(); } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "imgEdit") { string id = e.CommandArgument.ToString(); Server.Transfer("StockEdit.aspx?stockid=" + id); } } protected void btnSearch_Click(object sender, EventArgs e) { Condition = ""; if (this.txtStotckName.Text != "") { Condition = " and StockName like '" + this.txtStotckName.Text + "%' "; } if (this.txtAddress.Text != "") { Condition = " and StockAddress like '" + this.txtAddress.Text + "%' "; } if (this.ddlCompany.SelectedValue != "0") { Condition = " and FarhterCompany='" + this.ddlCompany.SelectedItem.Text + "' "; } if (this.ddlState.SelectedValue == "0") { Condition = " and IsDel='True' "; } else { Condition = " and IsDel='False' "; } getStockList(); } protected void AspNetPager1_PageChanged(object sender, EventArgs e) { pageindex = this.AspNetPager1.CurrentPageIndex - 1; getStockList(); } }

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:为什么Go语言把类型声明放在后面?(go后面用什么形式)
下一篇:应用抽象工厂+反射实现通用数据源的设计(三)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~