175 lines
6.2 KiB
C#
175 lines
6.2 KiB
C#
|
namespace FineUIPro.Web.HJGL.Match
|
|||
|
{
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using System.Data.SqlClient;
|
|||
|
using System.Text;
|
|||
|
using BLL;
|
|||
|
using AspNet = System.Web.UI.WebControls;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 库存
|
|||
|
/// </summary>
|
|||
|
public partial class Storage : PageBase
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 加载页面
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Page_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (!IsPostBack)
|
|||
|
{
|
|||
|
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
|||
|
// 绑定表格
|
|||
|
this.BindGrid();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#region 绑定GV数据
|
|||
|
/// <summary>
|
|||
|
/// 绑定数据
|
|||
|
/// </summary>
|
|||
|
private void BindGrid()
|
|||
|
{
|
|||
|
string strSql = @"SELECT Storage.StorageId,Storage.ProjectId,Storage.MaterialId,ISNULL(Storage.InCount,0) AS InCount,ISNULL(Storage.OutCount,0) AS OutCount"
|
|||
|
+ @" ,(ISNULL(Storage.InCount,0) -ISNULL(Storage.OutCount,0)) AS StorageCount,Material.Code,Material.Name,Material.Standard,Material.UNIT,Material.SteelName"
|
|||
|
+ @" FROM dbo.HJGL_Match_Storage AS Storage"
|
|||
|
+ @" LEFT JOIN dbo.HJGL_Match_Material AS Material ON Storage.MaterialId =Material.MaterialId"
|
|||
|
+ @" WHERE Storage.ProjectId='" + this.CurrUser.LoginProjectId + "'";
|
|||
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|||
|
if (!string.IsNullOrEmpty(this.txtCode.Text.Trim()))
|
|||
|
{
|
|||
|
strSql += " AND Code LIKE @Code";
|
|||
|
listStr.Add(new SqlParameter("@Code", "%" + this.txtCode.Text.Trim() + "%"));
|
|||
|
}
|
|||
|
if (!string.IsNullOrEmpty(this.txtName.Text.Trim()))
|
|||
|
{
|
|||
|
strSql += " AND Name LIKE @Name";
|
|||
|
listStr.Add(new SqlParameter("@Name", "%" + this.txtName.Text.Trim() + "%"));
|
|||
|
}
|
|||
|
if (!string.IsNullOrEmpty(this.txtStandard.Text.Trim()))
|
|||
|
{
|
|||
|
strSql += " AND Standard LIKE @Standard";
|
|||
|
listStr.Add(new SqlParameter("@Standard", "%" + this.txtStandard.Text.Trim() + "%"));
|
|||
|
}
|
|||
|
|
|||
|
SqlParameter[] parameter = listStr.ToArray();
|
|||
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|||
|
|
|||
|
// 2.获取当前分页数据
|
|||
|
//var table = this.GetPagedDataTable(Grid1, tb1);
|
|||
|
Grid1.RecordCount = tb.Rows.Count;
|
|||
|
tb = GetFilteredTable(Grid1.FilteredData, tb);
|
|||
|
var table = this.GetPagedDataTable(Grid1, tb);
|
|||
|
|
|||
|
Grid1.DataSource = table;
|
|||
|
Grid1.DataBind();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 文本框查询事件
|
|||
|
/// <summary>
|
|||
|
/// 查询
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void TextBox_TextChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
this.BindGrid();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region GV分页排序
|
|||
|
/// <summary>
|
|||
|
/// 分页
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|||
|
{
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 排序
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Grid1_Sort(object sender, GridSortEventArgs e)
|
|||
|
{
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 分页显示条数下拉框
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 导出按钮
|
|||
|
/// 导出按钮
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void btnOut_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Response.ClearContent();
|
|||
|
string filename = Funs.GetNewFileName();
|
|||
|
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("库存" + filename, System.Text.Encoding.UTF8) + ".xls");
|
|||
|
Response.ContentType = "application/excel";
|
|||
|
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
|||
|
this.Grid1.PageSize = 100000;
|
|||
|
this.BindGrid();
|
|||
|
Response.Write(GetGridTableHtml(Grid1));
|
|||
|
Response.End();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 导出方法
|
|||
|
/// </summary>
|
|||
|
/// <param name="grid"></param>
|
|||
|
/// <returns></returns>
|
|||
|
private string GetGridTableHtml(Grid grid)
|
|||
|
{
|
|||
|
StringBuilder sb = new StringBuilder();
|
|||
|
sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
|
|||
|
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
|
|||
|
sb.Append("<tr>");
|
|||
|
foreach (GridColumn column in grid.Columns)
|
|||
|
{
|
|||
|
sb.AppendFormat("<td>{0}</td>", column.HeaderText);
|
|||
|
}
|
|||
|
sb.Append("</tr>");
|
|||
|
foreach (GridRow row in grid.Rows)
|
|||
|
{
|
|||
|
sb.Append("<tr>");
|
|||
|
foreach (GridColumn column in grid.Columns)
|
|||
|
{
|
|||
|
string html = row.Values[column.ColumnIndex].ToString();
|
|||
|
if (column.ColumnID == "tfNumber")
|
|||
|
{
|
|||
|
html = (row.FindControl("lblNumber") as AspNet.Label).Text;
|
|||
|
}
|
|||
|
sb.AppendFormat("<td>{0}</td>", html);
|
|||
|
}
|
|||
|
|
|||
|
sb.Append("</tr>");
|
|||
|
}
|
|||
|
|
|||
|
sb.Append("</table>");
|
|||
|
|
|||
|
return sb.ToString();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|