using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.IO; using System.Linq; namespace FineUIPro.Web.HJGL.CheckManage { public partial class CheckManageStatic : PageBase { #region 定义变量 /// /// 检测方法代号 /// public string DetectionTypeCode { get { return (string)ViewState["DetectionTypeCode"]; } set { ViewState["DetectionTypeCode"] = value; } } #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); this.txtMonth.Text = string.Format("{0:yyyy-MM}", DateTime.Now); this.InitTreeMenu();//加载树 } } #endregion #region 导入 /// /// 导入焊接日报 /// /// /// protected void btnImport_Click(object sender, EventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_CheckManageStaticMenuId, BLL.Const.BtnSave)) { if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckManageDataIn.aspx?detectionTypeId={0}", this.tvControlItem.SelectedNodeID, "导入 - "))); } else { Alert.ShowInTop("请选择探伤类型!", MessageBoxIcon.Warning); return; } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #endregion #region 加载树装置-单位-工作区 /// /// 加载树 /// private void InitTreeMenu() { string SelectedNodeID = this.tvControlItem.SelectedNodeID; this.tvControlItem.Nodes.Clear(); //检测方法 var detectionType = (from x in Funs.DB.Base_DetectionType orderby x.DetectionTypeCode select x).ToList(); string sql = @"SELECT distinct CONVERT(nvarchar(10), ReportDate, 23) as ReportDate,[ReportNo],[DetectionTypeCode] FROM [dbo].[CH_CheckStatic] where [ReportDate]>=@dateA and [ReportDate]<@dateZ and ProjectId = @projectId order by [DetectionTypeCode],[ReportDate] desc"; List listStr = new List { new SqlParameter("@projectId", this.CurrUser.LoginProjectId), new SqlParameter("@dateA", this.txtMonth.Text+"-01"), new SqlParameter("@dateZ", DateUtil.ToDateTime( this.txtMonth.Text+"-01").Value.AddMonths(1).ToString("yyyy-MM-dd")), }; SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(sql, parameter); foreach (var type in detectionType) { TreeNode newNode = new TreeNode(); newNode.Text = type.DetectionTypeCode; newNode.NodeID = type.DetectionTypeId; newNode.ToolTip = "检测方法"; this.tvControlItem.Nodes.Add(newNode); if (tb != null) { HashSet dates = new HashSet(); for (int i = 0; i < tb.Rows.Count; i++) { if (tb.Rows[i]["DetectionTypeCode"].ToString() == type.DetectionTypeCode) { string datetemp = tb.Rows[i]["ReportDate"].ToString(); if (!dates.Contains(datetemp)) { dates.Add(datetemp); TreeNode dateNode = new TreeNode(); dateNode.Text = datetemp; //datetemp.Substring(0, datetemp.IndexOf(' ')).Replace("/", "-"); dateNode.NodeID = type.DetectionTypeId + "|" + dateNode.Text; dateNode.ToolTip = "报告日期"; newNode.Nodes.Add(dateNode); for (int j = 0; j < tb.Rows.Count; j++) { if (tb.Rows[j]["DetectionTypeCode"].ToString() == type.DetectionTypeCode && tb.Rows[j]["ReportDate"].ToString() == datetemp) { TreeNode reportNoNode = new TreeNode(); reportNoNode.Text = tb.Rows[j]["ReportNo"].ToString(); reportNoNode.NodeID = tb.Rows[j]["ReportNo"].ToString() + "|" + dateNode.Text + "|" + type.DetectionTypeCode; reportNoNode.ToolTip = "报告编号"; reportNoNode.EnableClickEvent = true; dateNode.Nodes.Add(reportNoNode); } } } } } } } this.tvControlItem.SelectedNodeID = SelectedNodeID; } #endregion protected void tvControlItem_NodeExpand(object sender, TreeNodeEventArgs e) { } #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { this.BindGrid(); } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { string strSql = @"select CheckStaticId, Installation_ID, InstallationName, CH_TrustID, CH_TrustCode, Trust_Date, ISO_ID, ISO_IsoNo, JOT_ID, JOT_JointNo, WorkAmout1, WorkAmout2, FilmSpecifications, FilmLocNum, JOT_JointDesc, MaterialId, MaterialCode, DetectionRateId, DetectionRateCode, WED_ID, WED_Code, CheckLevel, DefectType, DefectNum, EvaluateLevel, CheckDate, CheckTemperature, ReportNo, ReportDate, ReportAmount, ProgressMoney, CheckPerson, RefilmReason, FilmSpec, CheckResult, CheckResultDate, CheckResultNum, WME_ID, WeldingMethodCode, CheckThingName, WorkAreaId, WorkAreaCode, UnidId, UnitName, ISOExecutive, TrustUnitId, TrustUnitName, ProjectId, ProjectName, CheckThingType, CheckOpportunity, RadialType, FilmBlack, Remark, CreateDate, Status, DetectionTypeCode, DefectCode, ItemName, BatchNum, QualificationLevel, JointCount, FilmingNature, FilmNum, FilmMan, SourceCategory, PassCount, NoPassCount, DetectionTime, GrooveTypeId, GrooveTypeCode, ProcessCardNum, WorkMeter, WorkloadTrack, DetectionSurface, Workloads from CH_CheckStatic where ProjectId = @projectId "; List listStr = new List { new SqlParameter("@projectId", this.CurrUser.LoginProjectId) }; if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID)) { string[] SelectedNodes = this.tvControlItem.SelectedNodeID.Split('|'); if (SelectedNodes.Length > 0) { strSql += " and ReportNo = @ReportNo "; listStr.Add(new SqlParameter("@ReportNo", SelectedNodes[0])); } if (SelectedNodes.Length > 1) { strSql += " and ReportDate >= @ReportDateA and ReportDate<=@ReportDateZ "; listStr.Add(new SqlParameter("@ReportDateA", SelectedNodes[1])); listStr.Add(new SqlParameter("@ReportDateZ", SelectedNodes[1] + " 23:59:59")); } if (SelectedNodes.Length > 2) { strSql += " and DetectionTypeCode = @DetectionTypeCode "; listStr.Add(new SqlParameter("@DetectionTypeCode", SelectedNodes[2])); this.DetectionTypeCode = SelectedNodes[2].ToString(); } } if (!string.IsNullOrEmpty(txtJOT_JointNo.Text)) { strSql += " and CH_TrustCode like @CH_TrustCode "; listStr.Add(new SqlParameter("@CH_TrustCode", "%"+this.txtJOT_JointNo.Text+"%")); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); //var detectionType = BLL.Base_DetectionTypeService.GetDetectionTypeByDetectionTypeId(this.tvControlItem.SelectedNodeID); //if (detectionType!=null) //{ if (this.DetectionTypeCode == "RT") { this.Grid1.Hidden = false; this.Grid2.Hidden = true; // 2.获取当前分页数据 //var table = this.GetPagedDataTable(Grid1, tb1); Grid1.RecordCount = tb.Rows.Count; //tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } else if (this.DetectionTypeCode == "PT") { this.Grid1.Hidden = true; this.Grid2.Hidden = false; // 2.获取当前分页数据 //var table = this.GetPagedDataTable(Grid1, tb1); Grid2.RecordCount = tb.Rows.Count; //tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid2, tb); Grid2.DataSource = table; Grid2.DataBind(); } //} } #endregion #region Grid1分页排序 #region 页索引改变事件 /// /// 页索引改变事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { BindGrid(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #endregion #region Grid2分页排序 #region 页索引改变事件 /// /// 页索引改变事件 /// /// /// protected void Grid2_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid2_Sort(object sender, GridSortEventArgs e) { BindGrid(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize2_SelectedIndexChanged(object sender, EventArgs e) { Grid2.PageSize = Convert.ToInt32(ddlPageSize2.SelectedValue); BindGrid(); } #endregion #endregion #region 焊口信息 维护事件 /// /// Grid双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { if (GetButtonPower(Const.BtnModify)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckManageStaticEdit.aspx?CheckStaticId={0}", Grid1.SelectedRowID, "编辑 - "))); } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } protected void Grid2_RowDoubleClick(object sender, GridRowClickEventArgs e) { if (GetButtonPower(Const.BtnModify)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckManageStaticEdit.aspx?CheckStaticId={0}", Grid2.SelectedRowID, "编辑 - "))); } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } /// /// 焊口信息编辑 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { if (GetButtonPower(Const.BtnModify)) { var detectionType = BLL.Base_DetectionTypeService.GetDetectionTypeByDetectionTypeId(this.tvControlItem.SelectedNodeID); if (detectionType != null) { if (detectionType.DetectionTypeCode == "RT") { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning); return; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckManageStaticEdit.aspx?CheckStaticId={0}", Grid1.SelectedRowID, "维护 - "))); } else if (detectionType.DetectionTypeCode == "PT") { if (Grid2.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning); return; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckManageStaticEdit.aspx?CheckStaticId={0}", Grid2.SelectedRowID, "维护 - "))); } } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } /// /// 删除按钮 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (GetButtonPower(Const.BtnDelete)) { var detectionType = BLL.Base_DetectionTypeService.GetDetectionTypeByDetectionTypeId(this.tvControlItem.SelectedNodeID); if (detectionType != null) { if (detectionType.DetectionTypeCode == "RT") { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning); return; } bool isShow = true; if (Grid1.SelectedRowIndexArray.Length > 1) { isShow = false; } foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); if (judgementDelete(rowID, isShow)) { var checkStatic = Funs.DB.CH_CheckStatic.FirstOrDefault(x => x.CheckStaticId == rowID); Funs.DB.CH_CheckStatic.DeleteOnSubmit(checkStatic); Funs.DB.SubmitChanges(); //BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除焊口信息"); } } } else if (detectionType.DetectionTypeCode == "PT") { if (Grid2.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning); return; } bool isShow = true; if (Grid2.SelectedRowIndexArray.Length > 1) { isShow = false; } foreach (int rowIndex in Grid2.SelectedRowIndexArray) { string rowID = Grid2.DataKeys[rowIndex][0].ToString(); if (judgementDelete(rowID, isShow)) { var checkStatic = Funs.DB.CH_CheckStatic.FirstOrDefault(x => x.CheckStaticId == rowID); Funs.DB.CH_CheckStatic.DeleteOnSubmit(checkStatic); Funs.DB.SubmitChanges(); //BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除焊口信息"); } } } ShowNotify("删除成功!", MessageBoxIcon.Success); this.BindGrid(); } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #endregion #region 报表打印 /// /// 报表打印 /// /// /// protected void btnPrint_Click(object sender, EventArgs e) { string detectionMethod = this.tvControlItem.SelectedNodeID; if (!string.IsNullOrEmpty(detectionMethod)) { string strSql = @"SELECT [CheckStaticId] ,[Installation_ID] ,[InstallationName] ,[CH_TrustID] ,[CH_TrustCode] ,[Trust_Date] ,[ISO_ID] ,[ISO_IsoNo] ,[JOT_ID] ,[JOT_JointNo] ,[WorkAmout1] ,[WorkAmout2] ,[FilmSpecifications] ,[FilmLocNum] ,[JOT_JointDesc] ,[MaterialId] ,[MaterialCode] ,[DetectionRateId] ,[DetectionRateCode] ,[WED_ID] ,[WED_Code] ,[CheckLevel] ,[DefectType] ,[DefectNum] ,[EvaluateLevel] ,[CheckDate] ,[CheckTemperature] ,[ReportNo] ,[ReportDate] ,[ReportAmount] ,[ProgressMoney] ,[CheckPerson] ,[RefilmReason] ,[FilmSpec] ,[CheckResult] ,[CheckResultDate] ,[CheckResultNum] ,[WME_ID] ,[WeldingMethodCode] ,[CheckThingName] ,[WorkAreaId] ,[WorkAreaCode] ,[UnidId] ,[UnitName] ,[ISOExecutive] ,[TrustUnitId] ,[TrustUnitName] ,[ProjectId] ,[ProjectName] ,[CheckThingType] ,[CheckOpportunity] ,[RadialType] ,[FilmBlack] ,[Remark] ,[CreateDate] ,[Status] ,[DetectionTypeCode] ,[DefectCode] FROM [dbo].[CH_CheckStatic] where ProjectId = @projectId "; List listStr = new List { new SqlParameter("@projectId", this.CurrUser.LoginProjectId) }; if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID)) { string[] SelectedNodes = this.tvControlItem.SelectedNodeID.Split('|'); if (SelectedNodes.Length > 0) { strSql += " and ReportNo = @ReportNo "; listStr.Add(new SqlParameter("@ReportNo", SelectedNodes[0])); } if (SelectedNodes.Length > 1) { strSql += " and ReportDate >= @ReportDateA and ReportDate<=@ReportDateZ "; listStr.Add(new SqlParameter("@ReportDateA", SelectedNodes[1])); listStr.Add(new SqlParameter("@ReportDateZ", SelectedNodes[1] + " 23:59:59")); } if (SelectedNodes.Length > 2) { strSql += " and DetectionTypeCode = @DetectionTypeCode "; listStr.Add(new SqlParameter("@DetectionTypeCode", SelectedNodes[2])); } } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); var projectName = BLL.ProjectService.GetProjectNameByProjectId(this.CurrUser.LoginProjectId); Dictionary keyValuePairs = new Dictionary(); keyValuePairs.Add("ProjectName", projectName); BLL.Common.FastReportService.ResetData(); if (tb != null) { tb.TableName = "Data"; if (tb.Rows.Count > 0) { keyValuePairs.Add("TrustUnit", tb.Rows[0]["TrustUnitName"].ToString()); keyValuePairs.Add("ConUnit", tb.Rows[0]["UnitName"].ToString()); keyValuePairs.Add("ReportNo", tb.Rows[0]["ReportNo"].ToString()); keyValuePairs.Add("WorkAreaCode", tb.Rows[0]["WorkAreaCode"].ToString()); keyValuePairs.Add("WeldingMethodCode", tb.Rows[0]["WeldingMethodCode"].ToString()); keyValuePairs.Add("DetectionRateCode", tb.Rows[0]["DetectionRateCode"].ToString()); keyValuePairs.Add("CheckOpportunity", tb.Rows[0]["CheckOpportunity"].ToString()); keyValuePairs.Add("CheckLevel", tb.Rows[0]["CheckLevel"].ToString()); keyValuePairs.Add("InstallationName", tb.Rows[0]["InstallationName"].ToString()); } } BLL.Common.FastReportService.AddFastreportParameter(keyValuePairs); BLL.Common.FastReportService.AddFastreportTable(tb); string initTemplatePath = ""; string rootPath = Server.MapPath("~/"); initTemplatePath = "File\\Fastreport\\管道MT报告模板.frx"; if (this.tvControlItem.SelectedNodeID.Split('|').Length > 2) { string type = this.tvControlItem.SelectedNodeID.Split('|')[2] ; switch (type) { case "RT\\UT": case "RT": initTemplatePath = "File\\Fastreport\\管道RT报告模板.frx"; break; case "PT": initTemplatePath = "File\\Fastreport\\管道PT报告模板.frx"; break; case "UT": initTemplatePath = "File\\Fastreport\\管道UT报告模板.frx"; break; case "MT": initTemplatePath = "File\\Fastreport\\管道MT报告模板.frx"; break; case "TOFD\\UT\\MT": case "TOFD\\MT": case "3D-TFM": case "TOFD": initTemplatePath = "File\\Fastreport\\管道TOFD报告模板.frx"; break; } } if (File.Exists(rootPath + initTemplatePath)) { //PageContext.RegisterStartupScript(Window5.GetShowReference(String.Format("../TrustManage/Fastreport.aspx?ReportPath={0}", rootPath + initTemplatePath))); } } else { Alert.ShowInTop("请选择检测方法!", MessageBoxIcon.Warning); return; } } #endregion #region 关闭弹出窗口及刷新页面 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { this.InitTreeMenu();//加载树 this.BindGrid(); } /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } /// /// 查询 /// /// /// protected void Tree_TextChanged(object sender, EventArgs e) { this.InitTreeMenu(); this.BindGrid(); } #endregion #region 判断是否可删除 /// /// 判断是否可以删除 /// /// private bool judgementDelete(string id, bool isShow) { string content = string.Empty; //if (BLL.HJGL_HotProessManageEditService.GetHotProessByJotId(id) > 0) //{ // content = "热处理已经使用了该焊口,不能删除!"; //} //if (BLL.Funs.DB.HJGL_CH_TrustItem.FirstOrDefault(x => x.JOT_ID == id) != null) //{ // content = "无损委托已经使用了该焊口,不能删除!"; //} //if (BLL.Funs.DB.HJGL_CH_CheckItem.FirstOrDefault(x => x.JOT_ID == id) != null) //{ // content = "检测单已经使用了该焊口,不能删除!"; //} if (string.IsNullOrEmpty(content)) { return true; } else { if (isShow) { Alert.ShowInTop(content, MessageBoxIcon.Error); } return false; } } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private bool GetButtonPower(string button) { return BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_JointInfoMenuId, button); } #endregion #region 查询 /// /// 查询 /// /// /// protected void txtJOT_JointNo_TextChanged(object sender, EventArgs e) { BindGrid(); } #endregion } }