2022-09-05 16:36:31 +08:00
using BLL ;
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Data.SqlClient ;
namespace FineUIPro.Web.CQMS.Material
{
public partial class MaterialStatistics : PageBase
{
/// <summary>
/// 项目id
/// </summary>
public string ProjectId
{
get
{
return ( string ) ViewState [ "ProjectId" ] ;
}
set
{
ViewState [ "ProjectId" ] = value ;
}
}
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
this . ProjectId = this . CurrUser . LoginProjectId ;
BLL . MainItemService . InitMainItemDownList ( drpMainItem , this . ProjectId , true ) ;
BindGrid ( ) ;
}
}
/// <summary>
/// 绑定数据
/// </summary>
public void BindGrid ( )
{
DataTable tb = ChecklistData ( ) ;
Grid1 . RecordCount = tb . Rows . Count ;
tb = GetFilteredTable ( Grid1 . FilteredData , tb ) ;
var table = this . GetPagedDataTable ( Grid1 , tb ) ;
Grid1 . DataSource = table ;
Grid1 . DataBind ( ) ;
}
protected DataTable ChecklistData ( )
{
string strSql = @"select C.MaterialName,isnull(SUM(C.Num),0) as TotalNum,
isnull((select sum(m1.Num) from Material_Material m1 left join Material_Inspection i on i.InspectionId=m1.InspectionId where m1.MaterialName=C.MaterialName and i.State='C'),0) as InspectionNum,
(isnull(SUM(C.Num),0)-isnull((select sum(m1.Num) from Material_Material m1 left join Material_Inspection i on i.InspectionId=m1.InspectionId where m1.MaterialName=C.MaterialName and i.State='C'),0)) as NotInspectionNum from [dbo].[Material_Material] C where 1=1" ;
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
strSql + = " AND C.ProjectId = @ProjectId" ;
listStr . Add ( new SqlParameter ( "@ProjectId" , this . ProjectId ) ) ;
if ( drpMainItem . SelectedValue ! = BLL . Const . _Null )
{
strSql + = " AND C.MainItemId=@MainItem" ;
strSql = strSql . Replace ( "i.State='C'" , "i.State='C' and m1.MainItemId=@MainItem" ) ;
listStr . Add ( new SqlParameter ( "@MainItem" , drpMainItem . SelectedValue ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . txtMaterialName . Text . Trim ( ) ) )
{
strSql + = " AND MaterialName like @MaterialName" ;
listStr . Add ( new SqlParameter ( "@MaterialName" , "%" + this . txtMaterialName . Text . Trim ( ) + "%" ) ) ;
}
strSql + = " group by MaterialName" ;
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
return tb ;
}
/// <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 ( ) ;
}
//分页
protected void Grid1_PageIndexChange ( object sender , GridPageEventArgs e )
{
BindGrid ( ) ;
}
2025-10-10 14:33:21 +08:00
2022-09-05 16:36:31 +08:00
/// <summary>
/// 搜索
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSearch_Click ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
/// <summary>
/// 重置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnRset_Click ( object sender , EventArgs e )
{
drpMainItem . SelectedIndex = 0 ;
txtMaterialName . Text = "" ;
BindGrid ( ) ;
}
}
}