using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; namespace FineUIPro.Web.CQMS.Material { public partial class MaterialTestView : PageBase { /// /// 主键 /// public string MaterialTestId { get { return (string)ViewState["MaterialTestId"]; } set { ViewState["MaterialTestId"] = value; } } /// /// 办理类型 /// public string State { get { return (string)ViewState["State"]; } set { ViewState["State"] = value; } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BLL.UnitService.InitUnitDropDownList(this.drpUnit, this.CurrUser.LoginProjectId, true); BLL.UnitService.InitUnitDropDownList(this.drpCheckUnit, this.CurrUser.LoginProjectId, true); BLL.MaterialTypeService.InitMaterialType(this.drpMaterialType, true); BLL.Person_PersonsService.InitUserProjectIdUnitIdRoleIdDropDownList(this.drpWitness, this.CurrUser.LoginProjectId, string.Empty, string.Empty, true); MaterialTestId = Request.Params["MaterialTestId"]; if (!string.IsNullOrEmpty(MaterialTestId)) { Model.Material_MaterialTest materialTest = BLL.CQMS_MaterialTestService.GetMaterialTestByMaterialTestId(MaterialTestId); Model.Material_Inspection inspection = BLL.CQMS_InspectionService.GetInspectionByInspectionId(materialTest.InspectionId); txtInspectionCode.Text = inspection.InspectionCode; if (!string.IsNullOrEmpty(materialTest.UnitId)) { drpUnit.SelectedValue = materialTest.UnitId; } if (!string.IsNullOrEmpty(materialTest.MaterialTypeId)) { drpMaterialType.SelectedValue = materialTest.MaterialTypeId; } this.txtSpotCheckRate.Text = materialTest.SpotCheckRate; this.txtSpotCheckNum.Text = materialTest.SpotCheckNum; if (!string.IsNullOrEmpty(materialTest.Witness)) { string[] strs = materialTest.Witness.Split(','); this.drpWitness.SelectedValueArray = strs; } if (materialTest.CheckResult != null) { if (materialTest.CheckResult == true) { this.rblCheckResult.SelectedValue = "True"; } else { this.rblCheckResult.SelectedValue = "False"; } } if (!string.IsNullOrEmpty(materialTest.CheckUnit)) { drpCheckUnit.SelectedValue = materialTest.CheckUnit; } BindData(inspection.InspectionType, materialTest.InspectionId); } } } private void BindData(string type, string inspectionId) { if (type == "M") //材料报验 { string strSql = @"select C.*,C.MaterialId as Id,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 1=1"; List listStr = new List(); strSql += " AND C.InspectionId = @InspectionId"; listStr.Add(new SqlParameter("@InspectionId", inspectionId)); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } else { string strSql = @"select C.*,C.EquipmentId as Id,C.EquipmentName as MaterialName,C.EquipmentCode as MaterialCode,M.MainItemName,U.UnitName from [dbo].[Material_Equipment] C left join [dbo].[ProjectData_MainItem] M on C.MainItemId=M.MainItemId left join [dbo].[Base_Unit] U on U.UnitId=C.UnitId where 1=1"; List listStr = new List(); strSql += " AND C.InspectionId = @InspectionId"; listStr.Add(new SqlParameter("@InspectionId", inspectionId)); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); this.Grid1.Columns[4].HeaderText = "设备名称"; this.Grid1.Columns[6].HeaderText = "设备位号"; this.Grid1.Columns[7].Hidden = true; } } protected void Grid1_Sort(object sender, GridSortEventArgs e) { } protected void WindowAtt_Close(object sender, WindowCloseEventArgs e) { } /// /// 时间转换 /// /// /// public string ConvertDate(object date) { if (date != null) { return string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(date)); } else { return null; } } protected void imgBtnFile_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CQMS/MaterialTest&menuId={1}", this.MaterialTestId, BLL.Const.MaterialTestMenuId))); } private string GetStringByArray(string[] array) { string str = string.Empty; foreach (var item in array) { if (item != BLL.Const._Null) { str += item + ","; } } if (!string.IsNullOrEmpty(str)) { str = str.Substring(0, str.LastIndexOf(",")); } return str; } } }