using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; namespace FineUIPro.Web.CQMS.Material { public partial class MaterialSearch : PageBase { /// /// 项目id /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } /// /// 定义集合 /// private static List list = new List(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ProjectId = this.CurrUser.LoginProjectId; list = new List(); BLL.UnitService.InitUnitDropDownList(this.drpUnit, this.ProjectId, true); BLL.MainItemService.InitMainItemDownList(drpMainItem, this.ProjectId, true); if (!string.IsNullOrEmpty(this.CurrUser.UnitId)) { this.drpUnit.SelectedValue = this.CurrUser.UnitId; } 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.*,M.MainItemName,U.UnitName from [dbo].[Material_Material] C left join [dbo].[ProjectData_MainItem] M on C.MainItemId=M.MainItemId left join [dbo].[Base_Unit] U on U.UnitId=C.UnitId where C.InspectionId is null"; List listStr = new List(); strSql += " AND C.ProjectId = @ProjectId"; listStr.Add(new SqlParameter("@ProjectId", this.ProjectId)); if (drpUnit.SelectedValue != BLL.Const._Null) { strSql += " AND C.UnitId=@UnitId"; listStr.Add(new SqlParameter("@UnitId", drpUnit.SelectedValue)); } if (drpMainItem.SelectedValue != BLL.Const._Null) { strSql += " AND C.MainItemId=@MainItem"; listStr.Add(new SqlParameter("@MainItem", drpMainItem.SelectedValue)); } if (!string.IsNullOrEmpty(this.txtMaterialCode.Text.Trim())) { strSql += " AND MaterialCode like @MaterialCode"; listStr.Add(new SqlParameter("@MaterialCode", "%" + this.txtMaterialCode.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtMaterialName.Text.Trim())) { strSql += " AND MaterialName like @MaterialName"; listStr.Add(new SqlParameter("@MaterialName", "%" + this.txtMaterialName.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtSpecificationAndModel.Text.Trim())) { strSql += " AND SpecificationAndModel like @SpecificationAndModel"; listStr.Add(new SqlParameter("@SpecificationAndModel", "%" + this.txtSpecificationAndModel.Text.Trim() + "%")); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); return tb; } /// /// 窗体关闭 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #region Grid行点击事件 /// /// Grid1行点击事件 /// /// /// protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { string rowID = Grid1.DataKeys[e.RowIndex][0].ToString(); if (e.CommandName == "IsSelected") { CheckBoxField checkField = (CheckBoxField)Grid1.FindColumn("ckbIsSelected"); if (checkField.GetCheckedState(e.RowIndex)) { if (!list.Contains(rowID)) { list.Add(rowID); } } else { if (list.Contains(rowID)) { list.Remove(rowID); } } } } #endregion /// /// 搜索 /// /// /// protected void btnSearch_Click(object sender, EventArgs e) { BindGrid(); } /// /// 重置 /// /// /// protected void btnRset_Click(object sender, EventArgs e) { drpUnit.SelectedIndex = 0; drpMainItem.SelectedIndex = 0; txtMaterialCode.Text = ""; txtMaterialName.Text = ""; BindGrid(); } #region 保存 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (this.drpUnit.SelectedValue == BLL.Const._Null) { ShowNotify("请先选择单位!", MessageBoxIcon.Warning); return; } if (list.Count == 0) { ShowNotify("请至少选择一项!", MessageBoxIcon.Warning); return; } Model.Material_Inspection ins = new Model.Material_Inspection(); ins.InspectionId = SQLHelper.GetNewID(); ins.ProjectId = this.CurrUser.LoginProjectId; ins.InspectionType = "M"; string prefix = ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId).ProjectCode + "-" + BLL.UnitService.GetUnitCodeByUnitId(this.CurrUser.UnitId) + "-CLBY-"; ins.InspectionCode = BLL.SQLHelper.RunProcNewId("SpGetNewCode4ByProjectId", "dbo.Material_Inspection", "InspectionCode", this.CurrUser.LoginProjectId, prefix); ins.UnitId = this.drpUnit.SelectedValue; ins.State = BLL.Const.Inspection_Compile; ins.CompileMan = this.CurrUser.PersonId; ins.CompileDate = DateTime.Now; BLL.CQMS_InspectionService.AddInspection(ins); Model.Material_InspectionApprove approve = new Model.Material_InspectionApprove(); approve.InspectionId = ins.InspectionId; approve.ApproveMan = CurrUser.PersonId; approve.ApproveType = Const.Inspection_Compile; BLL.CQMS_InspectionApproveService.AddInspectionApprove(approve); foreach (var item in list) { Model.Material_Material material = BLL.CQMS_MaterialService.GetMaterialByMaterialId(item); if (material != null) { material.InspectionId = ins.InspectionId; BLL.CQMS_MaterialService.UpdateMaterial(material); } } PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(ins.InspectionId) + ActiveWindow.GetHidePostBackReference()); } #endregion } }