198 lines
7.0 KiB
C#
198 lines
7.0 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;
|
|
using System.Linq;
|
|
|
|
/// <summary>
|
|
/// 库存
|
|
/// </summary>
|
|
public partial class PipelineRrequiredMaterials : 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()
|
|
{
|
|
////取管线材料视图
|
|
List<Model.HJGL_View_MatchPipeMaterial> viewMatch = new List<Model.HJGL_View_MatchPipeMaterial>();
|
|
if (!string.IsNullOrEmpty(this.txtName.Text.Trim()))
|
|
{
|
|
viewMatch = (from x in Funs.DB.HJGL_View_MatchPipeMaterial
|
|
where x.ProjectId == this.CurrUser.LoginProjectId
|
|
&& (x.Code.Contains(this.txtName.Text.Trim()) || x.Name.Contains(this.txtName.Text.Trim()))
|
|
orderby x.InstallationCode, x.UnitCode, x.WorkAreaCode,x.ISO_IsoNo
|
|
select x).ToList();
|
|
}
|
|
else
|
|
{
|
|
viewMatch = (from x in Funs.DB.HJGL_View_MatchPipeMaterial
|
|
where x.ProjectId == this.CurrUser.LoginProjectId
|
|
orderby x.InstallationCode, x.UnitCode, x.WorkAreaCode, x.ISO_IsoNo
|
|
select x).ToList();
|
|
}
|
|
|
|
////取管线材料id
|
|
var materialListId = (from x in viewMatch select x.MaterialId).Distinct().ToList();
|
|
List<Model.HJGL_View_MatchPipeMaterial> returnViewMatch = new List<Model.HJGL_View_MatchPipeMaterial>();
|
|
if (materialListId.Count() > 0 && viewMatch.Count() > 0)
|
|
{
|
|
foreach (var item in materialListId)
|
|
{
|
|
var materiaItem = viewMatch.Where(x => x.MaterialId == item);
|
|
if (materiaItem.Count() > 0)
|
|
{
|
|
var viewItem = materiaItem.FirstOrDefault();
|
|
viewItem.NeedCount = 0;
|
|
viewItem.UsedCount = 0;
|
|
viewItem.NowNeedCount = 0;
|
|
foreach (var materiaItemItem in materiaItem)
|
|
{
|
|
viewItem.NeedCount += materiaItemItem.NeedCount;
|
|
viewItem.UsedCount += materiaItemItem.UsedCount;
|
|
viewItem.NowNeedCount += materiaItemItem.NowNeedCount;
|
|
}
|
|
returnViewMatch.Add(viewItem);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
DataTable tb = this.LINQToDataTable(returnViewMatch);
|
|
|
|
// 2.获取当前分页数据
|
|
//var table = this.GetPagedDataTable(GridNewDynamic, 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
|
|
}
|
|
} |