using BLL; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.UI.WebControls; namespace FineUIPro.Web.HJGL.RepairManage { public partial class RepairManageAudit : PageBase { #region 定义变量 /// /// 委托主键 /// public string CH_TrustID { get { return (string)ViewState["CH_TrustID"]; } set { ViewState["CH_TrustID"] = value; } } /// /// 查询视图集合 /// private static List trustItems = new List(); #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.txtReportDate.Text = string.Format("{0:yyyy-MM}", DateTime.Now); this.txtCH_AuditDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); BLL.UserService.InitUserDropDownList(this.drpCH_AuditMan, this.CurrUser.LoginProjectId, true);//审核人 this.drpCH_AuditMan.SelectedValue = this.CurrUser.UserId; this.InitTreeMenu(); } } #endregion #region 加载树装置-单位-工作区 /// /// 加载树 /// private void InitTreeMenu() { if (!string.IsNullOrEmpty(this.txtReportDate.Text.Trim())) { DateTime? startTime = Funs.GetNewDateTime(this.txtReportDate.Text.Trim()); DateTime? endTime = startTime.HasValue ? startTime.Value.AddMonths(1) : System.DateTime.Now; this.tvControlItem.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = "单位-装置-月份"; rootNode.NodeID = "0"; rootNode.Expanded = true; this.tvControlItem.Nodes.Add(rootNode); List units = null; var unit = BLL.ProjectUnitService.GetProjectUnitByUnitIdProjectId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId); if (unit == null || unit.UnitType == BLL.Const.ProjectUnitType_1 || unit.UnitType == BLL.Const.ProjectUnitType_3) { if (BLL.WorkAreaService.IsSupervisor(this.CurrUser.UnitId, this.CurrUser.LoginProjectId)) { units = (from x in Funs.DB.Base_Unit join y in Funs.DB.ProjectData_WorkArea on x.UnitId equals y.UnitId where (x.UnitId == this.CurrUser.UnitId || y.SupervisorUnitId == this.CurrUser.UnitId) && y.ProjectId == this.CurrUser.LoginProjectId select x).Distinct().ToList(); } else { units = BLL.UnitService.GetUnitByProjectIdUnitTypeList(this.CurrUser.LoginProjectId, "2"); } } else { units = (from x in Funs.DB.Base_Unit where x.UnitId == this.CurrUser.UnitId select x).ToList(); } List trustLists = new List(); ///委托单 if (!this.txtReportDate.Hidden) { trustLists = (from x in Funs.DB.CH_Trust where x.CH_TrustType == "2" && x.ProjectId == this.CurrUser.LoginProjectId && x.CH_TrustDate >= startTime && x.CH_TrustDate < endTime select x).ToList(); } else { trustLists = (from x in Funs.DB.CH_Trust where x.CH_TrustType == "2" && x.ProjectId == this.CurrUser.LoginProjectId && x.CH_TrustCode.Contains(this.txtSearchCode.Text.Trim()) select x).ToList(); } if (units != null) { foreach (var item in units) { TreeNode rootUnitNode = new TreeNode();//定义根节点 rootUnitNode.Text = item.UnitName; rootUnitNode.NodeID = item.UnitId; rootUnitNode.Expanded = true; rootUnitNode.ToolTip = "施工单位"; rootNode.Nodes.Add(rootUnitNode); var checkList = trustLists.Where(x => x.CH_TrustUnit == item.UnitId).ToList(); this.BindNodes(rootUnitNode, checkList); } } else { Alert.ShowInTop("请先增加施工单位!", MessageBoxIcon.Warning); return; } } else { Alert.ShowInTop("请选择委托月份!", MessageBoxIcon.Warning); return; } } #endregion #region 绑定树节点 /// /// 绑定树节点 /// /// private void BindNodes(TreeNode node, List trustLists) { if (node.ToolTip == "施工单位") { var installId = (from x in trustLists select x.InstallationId).Distinct(); if (installId.Count() > 0) { var install = from x in Funs.DB.Project_Installation where installId.Contains(x.InstallationId) orderby x.InstallationCode select x; foreach (var q in install) { TreeNode newNode = new TreeNode(); newNode.Text = q.InstallationName; newNode.NodeID = q.InstallationId + "|" + node.NodeID; ; newNode.ToolTip = "装置"; newNode.Expanded = true; node.Nodes.Add(newNode); this.BindNodes(newNode, trustLists); } } } else if (node.ToolTip == "装置") { string installationId = Funs.GetStrListByStr(node.NodeID, '|')[0]; var pointListMonth = (from x in trustLists where x.InstallationId == installationId && x.CH_TrustUnit == node.ParentNode.NodeID select string.Format("{0:yyyy-MM}", x.CH_TrustDate)).Distinct(); foreach (var item in pointListMonth) { TreeNode newNode = new TreeNode(); newNode.Text = item; newNode.NodeID = item + "|" + node.NodeID; ; newNode.ToolTip = "月份"; node.Nodes.Add(newNode); this.BindNodes(newNode, trustLists); } } else if (node.ToolTip == "月份") { string installationId = Funs.GetStrListByStr(node.ParentNode.NodeID, '|')[0]; var days = (from x in trustLists where x.InstallationId == installationId && x.CH_TrustUnit == node.ParentNode.ParentNode.NodeID orderby x.CH_TrustDate descending select x.CH_TrustDate).Distinct(); foreach (var item in days) { TreeNode newNode = new TreeNode(); newNode.Text = string.Format("{0:yyyy-MM-dd}", item); newNode.NodeID = item.ToString() + "|" + node.NodeID; ; newNode.ToolTip = "日期"; node.Nodes.Add(newNode); this.BindNodes(newNode, trustLists); } } else if (node.ToolTip == "日期") { string installationId = Funs.GetStrListByStr(node.ParentNode.ParentNode.NodeID, '|')[0]; var dReports = from x in trustLists where x.InstallationId == installationId && x.CH_TrustUnit == node.ParentNode.ParentNode.ParentNode.NodeID && x.CH_TrustDate == Funs.GetNewDateTime(node.Text) orderby x.CH_TrustCode descending select x; foreach (var item in dReports) { TreeNode newNode = new TreeNode(); if (!string.IsNullOrEmpty(item.CH_TrustCode)) { newNode.Text = item.CH_TrustCode; } else { newNode.Text = "未知"; } if (!item.CH_AuditDate.HasValue || string.IsNullOrEmpty(item.CH_AuditMan)) { newNode.Text = "" + newNode.Text + ""; node.Text = "" + node.Text + ""; node.ParentNode.Text = "" + node.ParentNode.Text + ""; } newNode.NodeID = item.CH_TrustID; newNode.EnableClickEvent = true; node.Nodes.Add(newNode); } } } #endregion #region 查询Tree /// /// 按日期、单号查询 /// /// /// protected void ckFind_SelectedIndexChanged(object sender, EventArgs e) { if (this.ckFind.SelectedValue == "0") { this.txtReportDate.Hidden = false; this.txtSearchCode.Hidden = true; if (string.IsNullOrEmpty(this.txtReportDate.Text)) { this.txtReportDate.Text = string.Format("{0:yyyy-MM}", DateTime.Now); } } else { this.txtReportDate.Hidden = true; this.txtSearchCode.Hidden = false; } this.InitTreeMenu(); } protected void Tree_TextChanged(object sender, EventArgs e) { this.InitTreeMenu(); } #endregion #region 点击树节点 /// /// 点击树节点 /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { trustItems = new List(); this.CH_TrustID = this.tvControlItem.SelectedNodeID; if (!string.IsNullOrEmpty(this.CH_TrustID)) { Model.CH_Trust trust = BLL.TrustManageEditService.GetCH_TrustByID(this.CH_TrustID); if (trust != null) { this.txtCH_TrustCode.Text = trust.CH_TrustCode; if (!string.IsNullOrEmpty(trust.CH_TrustUnit)) { this.txtCH_TrustUnitName.Text = BLL.UnitService.GetUnitNameByUnitId(trust.CH_TrustUnit); } if (!string.IsNullOrEmpty(trust.InstallationId)) { this.txtInstallationName.Text = BLL.Project_InstallationService.GetInstallationByInstallationId(trust.InstallationId).InstallationName; } this.txtCH_TrustDate.Text = trust.CH_TrustDate.HasValue ? string.Format("{0:yyyy-MM-dd}", trust.CH_TrustDate) : ""; this.txtCH_Press.Text = trust.CH_Press; if (!string.IsNullOrEmpty(trust.CH_NDTRate)) { var rate = BLL.Base_DetectionRateService.GetDetectionRateByDetectionRateId(trust.CH_NDTRate); if (rate != null) { this.txtCH_NDTRate.Text = rate.DetectionRateCode + "-" + rate.DetectionRate + "%"; } } this.txtCH_WorkNo.Text = trust.CH_WorkNo; if (!string.IsNullOrEmpty(trust.CH_NDTMethod)) { this.txtCH_NDTMethod.Text = Base_DetectionTypeService.GetDetectionTypeByDetectionTypeId(trust.CH_NDTMethod).DetectionTypeName; } if (!string.IsNullOrEmpty(trust.CH_TrustMan)) { this.txtCH_TrustMan.Text = BLL.UserService.GetUserNameByUserId(trust.CH_TrustMan); } this.txtCH_ItemName.Text = trust.CH_ItemName; if (!string.IsNullOrEmpty(trust.CH_AcceptGrade)) { if (trust.CH_AcceptGrade == "1") { this.txtCH_AcceptGrade.Text = "Ⅰ"; } else if (trust.CH_AcceptGrade == "2") { this.txtCH_AcceptGrade.Text = "Ⅱ"; } else if (trust.CH_AcceptGrade == "3") { this.txtCH_AcceptGrade.Text = "Ⅲ"; } else if (trust.CH_AcceptGrade == "4") { this.txtCH_AcceptGrade.Text = "Ⅳ"; } else if (trust.CH_AcceptGrade == "5") { this.txtCH_AcceptGrade.Text = "Ⅴ"; } } if (!string.IsNullOrEmpty(trust.CH_Tabler)) { this.txtCH_Tabler.Text =BLL.UserService.GetUserNameByUserId(trust.CH_Tabler); } if (!string.IsNullOrEmpty(trust.CH_SlopeType)) { this.txtCH_SlopeType.Text = BLL.Base_GrooveTypeService.GetGrooveTypeByGrooveTypeId(trust.CH_SlopeType).GrooveTypeName; } this.txtCH_NDTCriteria.Text = trust.CH_NDTCriteria; if (!string.IsNullOrEmpty(trust.CH_WeldMethod)) { this.txtCH_WeldMethod.Text = BLL.Base_WeldingMethodService.GetWeldingMethodByWeldingMethodId(trust.CH_WeldMethod).WeldingMethodName; } this.txtCH_ServiceTemp.Text = trust.CH_ServiceTemp; if (!string.IsNullOrEmpty(trust.CH_CheckUnit)) { this.txtCH_CheckUnit.Text = BLL.UnitService.GetUnitNameByUnitId(trust.CH_CheckUnit); } this.txtCH_RequestDate.Text = trust.CH_RequestDate.HasValue ? string.Format("{0:yyyy-MM-dd}", trust.CH_RequestDate) : ""; this.txtRemark.Text = trust.CH_Remark; if (!string.IsNullOrEmpty(trust.CH_AuditMan)) { this.drpCH_AuditMan.SelectedValue = trust.CH_AuditMan; } else { this.drpCH_AuditMan.SelectedValue = this.CurrUser.UserId; } this.txtCH_AuditDate.Text = trust.CH_AuditDate.HasValue ? string.Format("{0:yyyy-MM-dd}", trust.CH_AuditDate) : string.Format("{0:yyyy-MM-dd}", DateTime.Now); trustItems = BLL.TrustManageEditService.GetTrustItemViewByTrustId(this.CH_TrustID); if (trustItems.Count > 0) { this.Grid1.DataSource = trustItems; this.Grid1.DataBind(); } //隐藏和显示审核、取消审核按钮 if (!string.IsNullOrEmpty(trust.CH_AuditMan)&&trust.CH_AuditDate.HasValue) { this.btnAudit.Hidden = true; this.btnCancelAudit.Hidden = false; } else { this.btnAudit.Hidden = false; this.btnCancelAudit.Hidden = true; } } } else { this.CH_TrustID = string.Empty; } } #endregion #region Grid行绑定事件 /// /// Grid行绑定事件 /// /// /// protected void Grid1_RowDataBound(object sender, GridRowEventArgs e) { foreach (var item in trustItems) { if (item.JOT_JointStatus == "100" || item.JOT_JointStatus == "102") { if (item.JOT_ID == e.RowID) { CheckBoxField s = Grid1.FindColumn("JOT_JointStatus") as CheckBoxField; e.CellCssClasses[s.ColumnIndex] = "hidethis"; } } } } #endregion #region 审核 /// /// 审核 /// /// /// protected void btnAudit_Click(object sender, EventArgs e) { if (this.GetButtonPower(BLL.Const.BtnAuditing)) { var updatetrust = BLL.TrustManageEditService.GetCH_TrustByID(CH_TrustID); if (updatetrust != null && !String.IsNullOrEmpty(this.CH_TrustID)) { Model.CH_Trust trust = new Model.CH_Trust(); trust.CH_TrustID = this.CH_TrustID; if (!String.IsNullOrEmpty(this.txtCH_AuditDate.Text) && this.drpCH_AuditMan.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpCH_AuditMan.SelectedValue)) { trust.CH_AuditDate = Funs.GetNewDateTime(this.txtCH_AuditDate.Text); trust.CH_AuditMan = this.drpCH_AuditMan.SelectedValue; BLL.TrustManageEditService.AuditCH_Trust(trust); var trustItems = from x in Funs.DB.CH_TrustItem where x.CH_TrustID == this.CH_TrustID select x; foreach (var newitem in trustItems) { BLL.TrustManageEditService.UpdateJOT_TrustFlag(newitem.JOT_ID, "1"); ////更新焊口代号 var jotitem = BLL.PW_JointInfoService.GetJointInfoByJotID(newitem.JOT_ID); var chek = Funs.DB.CH_CheckItem.FirstOrDefault(x => x.JOT_ID == newitem.JOT_ID); if (chek == null) { BLL.RepairService.UpdateNewJointNo(newitem.JOT_ID, "K1"); } if (jotitem.JOT_JointStatus == "104") { BLL.RepairService.UpdateNewJointNo(jotitem.JOT_ID, "C"); } var ndttype = BLL.Base_DetectionTypeService.GetDetectionTypeByDetectionTypeId(trust.CH_NDTMethod); if (ndttype != null) { if (ndttype.DetectionTypeCode == "RT") { BLL.CheckManageService.UpdateCheckIsRepair(newitem.JOT_ID, this.CH_TrustID, true, "1"); } else { BLL.CheckManageService.UpdateCheckIsRepair(newitem.JOT_ID, this.CH_TrustID, true, "2"); } } } ShowNotify("审核完成!", MessageBoxIcon.Success); InitTreeMenu(); this.btnAudit.Hidden = true; this.btnCancelAudit.Hidden = false; } else { Alert.ShowInTop("请填写审核人和审核日期!", MessageBoxIcon.Warning); } } else { Alert.ShowInTop("请选择要审核的单据!", MessageBoxIcon.Warning); } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #endregion #region 取消审核 /// /// 取消审核 /// /// /// protected void btnCancelAudit_Click(object sender, EventArgs e) { if (this.GetButtonPower(BLL.Const.BtnCancelAuditing)) { var trustItem = BLL.TrustManageEditService.GetCH_TrustItemByCH_TrustID(this.CH_TrustID); if (trustItem != null) { foreach (var item in trustItem) { var nd = from x in Funs.DB.CH_CheckItem where x.CH_TrustItemID == item.CH_TrustItemID select x; if (nd.Count() > 0) { Alert.ShowInTop("'此委托单已在检测不允许取消审核!", MessageBoxIcon.Warning); return; } } } var updatetrust = BLL.TrustManageEditService.GetCH_TrustByID(CH_TrustID); if (updatetrust != null && !String.IsNullOrEmpty(this.CH_TrustID)) { Model.CH_Trust trust = new Model.CH_Trust(); trust.CH_TrustID = this.CH_TrustID; trust.CH_AuditDate = null; trust.CH_AuditMan = null; this.btnCancelAudit.Hidden = true; this.btnAudit.Hidden = false; BLL.TrustManageEditService.AuditCH_Trust(trust); var trustItems = from x in Funs.DB.CH_TrustItem where x.CH_TrustID == this.CH_TrustID select x; foreach (var newitem in trustItems) { BLL.TrustManageEditService.UpdateJOT_TrustFlag(newitem.JOT_ID, "2"); ////更新焊口代号 var jotitem = BLL.PW_JointInfoService.GetJointInfoByJotID(newitem.JOT_ID); if (jotitem.JOT_JointStatus == "102" || jotitem.JOT_JointStatus == "104") { BLL.RepairService.UpdateCancelAuditJointNo(jotitem.JOT_ID); } } ShowNotify("取消审核完成!", MessageBoxIcon.Success); InitTreeMenu(); } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private bool GetButtonPower(string button) { return BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_RepairManageAuditMenuId, button); } #endregion #region 打印 /// /// 打印按钮 /// /// /// protected void btnPrint_Click(object sender, EventArgs e) { string reportId = this.tvControlItem.SelectedNode.NodeID; var q = BLL.TrustManageEditService.GetCH_TrustByID(reportId); if (q != null) { string varValue = string.Empty; //var projectName = BLL.ProjectService.GetProjectNameByProjectId(this.CurrUser.LoginProjectId); //var installationName = BLL.Project_InstallationService.GetInstallationByInstallationId(q.InstallationId).InstallationName; //var unitName = BLL.UnitService.GetUnitNameByUnitId(q.UnitId); //varValue = installationName + "|" + unitName + "|" + projectName + "|" + q.PW_PointDate.Value.ToString("yyyy-MM-dd") + "|" + q.PW_PointNo; if (!string.IsNullOrEmpty(varValue)) { varValue = Microsoft.JScript.GlobalObject.escape(varValue.Replace("/", ",")); } if (BLL.Project_SysSetService.IsAuto("3", this.CurrUser.LoginProjectId) == true) //3表示无损委托 { PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId={3}", BLL.Const.TrustReportId, reportId, varValue, this.CurrUser.LoginProjectId))); } else if (BLL.Project_SysSetService.IsAuto("3", this.CurrUser.LoginProjectId) == false) { PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId={3}", BLL.Const.TrustReport2Id, reportId, varValue, this.CurrUser.LoginProjectId))); } else if (BLL.Project_SysSetService.IsAuto("3", this.CurrUser.LoginProjectId) == null) { var p = BLL.Project_SysSetService.GetSysSetBySetId("3", this.CurrUser.LoginProjectId); if (p.SetValue == "3") { PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId={3}", BLL.Const.TrustReport3Id, reportId, varValue, this.CurrUser.LoginProjectId))); } else // 4表示为神化委托单 { PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId={3}", BLL.Const.TrustReport4Id, reportId, varValue, this.CurrUser.LoginProjectId))); } } } else { Alert.ShowInTop("请选择要打印的委托单!", MessageBoxIcon.Warning); return; } } #endregion } }