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 { /// /// 项目id /// 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(); } } /// /// 绑定数据 /// 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 listStr = new List(); 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; } /// /// 分页显示条数下拉框 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } //分页 protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } /// /// 搜索 /// /// /// protected void btnSearch_Click(object sender, EventArgs e) { BindGrid(); } /// /// 重置 /// /// /// protected void btnRset_Click(object sender, EventArgs e) { drpMainItem.SelectedIndex = 0; txtMaterialName.Text = ""; BindGrid(); } } }