using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web.UI.WebControls; namespace FineUIPro.Web.HJGL.PointTrust { public partial class PointBatch : PageBase { #region 定义变量 /// /// 批次主键 /// public string PointBatchId { get { return (string)ViewState["PointBatchId"]; } set { ViewState["PointBatchId"] = value; } } #endregion #region 加载 /// /// 加载 /// /// /// protected void Page_Load(object sender, EventArgs e) { // ctlAuditFlow.Url = BLL.Project_SysSetService.GetAvevaNetUrl(this.CurrUser.LoginProjectId); if (!IsPostBack) { BLL.UnitService.InitUnitByProjectIdUnitTypeDropDownList(this.drpUnit, this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2, true); this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); this.txtStartTime.Text = string.Format("{0:yyyy-MM}", DateTime.Now); this.InitTreeMenu();//加载树 } } #region 加载树 /// /// 加载树 /// private void InitTreeMenu() { this.tvControlItem.Nodes.Clear(); TreeNode rootNode1 = new TreeNode(); rootNode1.NodeID = "1"; rootNode1.Text = "建筑工程"; rootNode1.CommandName = "建筑工程"; rootNode1.Selectable = false; this.tvControlItem.Nodes.Add(rootNode1); TreeNode rootNode2 = new TreeNode(); rootNode2.NodeID = "2"; rootNode2.Text = "安装工程"; rootNode2.CommandName = "安装工程"; rootNode2.Expanded = true; this.tvControlItem.Nodes.Add(rootNode2); var pUnits = (from x in Funs.DB.Project_ProjectUnit where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList(); // 获取当前用户所在单位 var currUnit = pUnits.FirstOrDefault(x => x.UnitId == this.CurrUser.UnitId); var unitWorkList = (from x in Funs.DB.WBS_UnitWork where x.ProjectId == this.CurrUser.LoginProjectId && x.SuperUnitWork == null && x.UnitId != null && x.ProjectType != null orderby x.UnitWorkCode select x).ToList(); List unitWork1 = null; List unitWork2 = null; //// 当前为施工单位,只能操作本单位的数据 //if (currUnit != null && currUnit.UnitType == Const.ProjectUnitType_2) //{ // unitWork1 = (from x in unitWorkList // where x.UnitId == this.CurrUser.UnitId && x.ProjectType == "1" // select x).ToList(); // unitWork2 = (from x in unitWorkList // where x.UnitId == this.CurrUser.UnitId && x.ProjectType == "2" // select x).ToList(); //} //else //{ unitWork1 = (from x in unitWorkList where x.ProjectType == "1" select x).ToList(); unitWork2 = (from x in unitWorkList where x.ProjectType == "2" select x).ToList(); //} if (unitWork1.Count() > 0) { foreach (var q in unitWork1) { int a = (from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == q.UnitWorkId select x).Count(); var unitNamesUnitIds = BLL.UnitService.getUnitNamesUnitIds(q.UnitId); TreeNode tn1 = new TreeNode(); tn1.NodeID = q.UnitWorkId; tn1.Text = q.UnitWorkName; tn1.ToolTip = "施工单位:" + unitNamesUnitIds; tn1.CommandName = "单位工程"; tn1.EnableExpandEvent = true; rootNode1.Nodes.Add(tn1); BindNodes(tn1); } } if (unitWork2.Count() > 0) { foreach (var q in unitWork2) { if (string.IsNullOrEmpty(this.txtWeldJointCode.Text.Trim())) { int a = (from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == q.UnitWorkId select x).Count(); var unitNamesUnitIds = BLL.UnitService.getUnitNamesUnitIds(q.UnitId); TreeNode tn2 = new TreeNode(); tn2.NodeID = q.UnitWorkId; tn2.Text = q.UnitWorkName; tn2.ToolTip = "施工单位:" + unitNamesUnitIds; tn2.EnableExpandEvent = true; tn2.CommandName = "单位工程"; rootNode2.Nodes.Add(tn2); BindNodes(tn2); } else { var pointManages = (from x in Funs.DB.View_HJGL_Batch_PointBatch join y in Funs.DB.View_HJGL_Batch_PointBatchItem on x.PointBatchId equals y.PointBatchId where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == q.UnitWorkId && y.WeldJointCode.Contains(this.txtWeldJointCode.Text.Trim()) select x).FirstOrDefault(); var unitNamesUnitIds = BLL.UnitService.getUnitNamesUnitIds(q.UnitId); TreeNode tn2 = new TreeNode(); tn2.NodeID = q.UnitWorkId; tn2.Text = q.UnitWorkName; tn2.ToolTip = "施工单位:" + unitNamesUnitIds; tn2.EnableExpandEvent = true; tn2.CommandName = "单位工程"; rootNode2.Nodes.Add(tn2); if (pointManages != null) { BindNodes(tn2); this.txtStartTime.Text = string.Format("{0:yyyy-MM}", pointManages.StartDate); } } } } } /// /// 绑定树节点 /// /// private void BindNodes(TreeNode node) { if (string.IsNullOrEmpty(this.txtWeldJointCode.Text.Trim())) { var p = from x in Funs.DB.HJGL_Batch_PointBatch where x.UnitWorkId == node.NodeID && x.StartDate < Convert.ToDateTime(this.txtStartTime.Text.Trim() + "-01").AddMonths(1) && x.StartDate >= Convert.ToDateTime(this.txtStartTime.Text.Trim() + "-01") select x; if (p.Count() > 0) { TreeNode newNode = new TreeNode(); newNode.Text = "探伤类型"; newNode.NodeID = "探伤类型"; node.Nodes.Add(newNode); } } else { var p = from x in Funs.DB.HJGL_Batch_PointBatch where x.UnitWorkId == node.NodeID //&& x.StartDate < Convert.ToDateTime(this.txtStartTime.Text.Trim() + "-01").AddMonths(1) //&& x.StartDate >= Convert.ToDateTime(this.txtStartTime.Text.Trim() + "-01") select x; if (p.Count() > 0) { TreeNode newNode = new TreeNode(); newNode.Text = "探伤类型"; newNode.NodeID = "探伤类型"; node.Nodes.Add(newNode); } } } #endregion #endregion #region 绑定树节点 protected void tvControlItem_TreeNodeExpanded(object sender, TreeNodeEventArgs e) { e.Node.Nodes.Clear(); if (e.Node.CommandName == "单位工程") { if (string.IsNullOrEmpty(this.txtWeldJointCode.Text.Trim())) { var detectionTypes = from x in Funs.DB.Base_DetectionType orderby x.DetectionTypeCode select new { x.DetectionTypeId, x.DetectionTypeCode, x.DetectionTypeName }; foreach (var item in detectionTypes) { var pointManages = from x in Funs.DB.View_HJGL_Batch_PointBatch where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == e.Node.NodeID && x.DetectionTypeId == item.DetectionTypeId select x; TreeNode newNode = new TreeNode(); if (pointManages.Count() > 0) { newNode.Text = item.DetectionTypeCode; newNode.NodeID = item.DetectionTypeId + "|" + e.Node.NodeID; newNode.EnableExpandEvent = true; newNode.ToolTip = item.DetectionTypeName; newNode.CommandName = "探伤类型"; e.Node.Nodes.Add(newNode); } TreeNode tn1 = new TreeNode { Text = "检测比例", NodeID = "检测比例", }; newNode.Nodes.Add(tn1); } } else { var detectionTypes = from x in Funs.DB.Base_DetectionType join y in Funs.DB.HJGL_Pipeline on x.DetectionTypeId equals y.DetectionType join z in Funs.DB.HJGL_WeldJoint on y.PipelineId equals z.PipelineId where z.WeldJointCode.Contains(this.txtWeldJointCode.Text.Trim()) orderby x.DetectionTypeCode select new { x.DetectionTypeId, x.DetectionTypeCode, x.DetectionTypeName }; foreach (var item in detectionTypes) { var pointManages = from x in Funs.DB.View_HJGL_Batch_PointBatch where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == e.Node.NodeID && x.DetectionTypeId == item.DetectionTypeId select x; TreeNode newNode = new TreeNode(); if (pointManages.Count() > 0) { newNode.Text = item.DetectionTypeCode; newNode.NodeID = item.DetectionTypeId + "|" + e.Node.NodeID; newNode.EnableExpandEvent = true; newNode.ToolTip = item.DetectionTypeName; newNode.CommandName = "探伤类型"; e.Node.Nodes.Add(newNode); } TreeNode tn1 = new TreeNode { Text = "检测比例", NodeID = "检测比例", }; newNode.Nodes.Add(tn1); } } } if (e.Node.CommandName == "探伤类型") { if (string.IsNullOrEmpty(this.txtWeldJointCode.Text.Trim())) { var detectionRates = from x in Funs.DB.Base_DetectionRate orderby x.DetectionRateCode select new { x.DetectionRateId, x.DetectionRateCode, x.DetectionRateValue }; foreach (var item in detectionRates) { var pointManages = from x in Funs.DB.View_HJGL_Batch_PointBatch where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == e.Node.ParentNode.NodeID && x.DetectionTypeId == e.Node.NodeID.Split('|')[0] && x.DetectionRateId == item.DetectionRateId && x.StartDate < Convert.ToDateTime(this.txtStartTime.Text.Trim() + "-01").AddMonths(1) && x.StartDate >= Convert.ToDateTime(this.txtStartTime.Text.Trim() + "-01") select x; if (item.DetectionRateValue > 0) //探伤比例为0的批不显示 { TreeNode newNode = new TreeNode(); if (pointManages.Count() > 0) { newNode.Text = item.DetectionRateValue.ToString() + "%"; newNode.NodeID = item.DetectionRateId + "|" + e.Node.NodeID; newNode.EnableExpandEvent = true; newNode.ToolTip = item.DetectionRateCode; newNode.CommandName = "检测比例"; e.Node.Nodes.Add(newNode); } TreeNode tn1 = new TreeNode { Text = "检测批", NodeID = "检测批", }; newNode.Nodes.Add(tn1); } } } else { var detectionRates = from x in Funs.DB.Base_DetectionRate join y in Funs.DB.HJGL_Pipeline on x.DetectionRateId equals y.DetectionRateId join z in Funs.DB.HJGL_WeldJoint on y.PipelineId equals z.PipelineId where z.WeldJointCode.Contains(this.txtWeldJointCode.Text.Trim()) orderby x.DetectionRateCode select new { x.DetectionRateId, x.DetectionRateCode, x.DetectionRateValue }; foreach (var item in detectionRates) { var pointManages = from x in Funs.DB.View_HJGL_Batch_PointBatch where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == e.Node.ParentNode.NodeID && x.DetectionTypeId == e.Node.NodeID.Split('|')[0] && x.DetectionRateId == item.DetectionRateId //&& x.StartDate < Convert.ToDateTime(this.txtStartTime.Text.Trim() + "-01").AddMonths(1) //&& x.StartDate >= Convert.ToDateTime(this.txtStartTime.Text.Trim() + "-01") select x; if (item.DetectionRateValue > 0) //探伤比例为0的批不显示 { TreeNode newNode = new TreeNode(); if (pointManages.Count() > 0) { newNode.Text = item.DetectionRateValue.ToString() + "%"; newNode.NodeID = item.DetectionRateId + "|" + e.Node.NodeID; newNode.EnableExpandEvent = true; newNode.ToolTip = item.DetectionRateCode; newNode.CommandName = "检测比例"; e.Node.Nodes.Add(newNode); } TreeNode tn1 = new TreeNode { Text = "检测批", NodeID = "检测批", }; newNode.Nodes.Add(tn1); } } } } if (e.Node.CommandName == "检测比例") { if (string.IsNullOrEmpty(this.txtWeldJointCode.Text.Trim())) { var pointManages = from x in Funs.DB.View_HJGL_Batch_PointBatch where x.ProjectId == this.CurrUser.LoginProjectId && x.DetectionRateId == e.NodeID.Split('|')[0] && x.DetectionTypeId == e.Node.ParentNode.NodeID.Split('|')[0] && x.UnitWorkId == e.Node.ParentNode.ParentNode.NodeID && x.StartDate < Convert.ToDateTime(this.txtStartTime.Text.Trim() + "-01").AddMonths(1) && x.StartDate >= Convert.ToDateTime(this.txtStartTime.Text.Trim() + "-01") select x; if (!string.IsNullOrEmpty(this.txtWelderCode.Text)) { pointManages = pointManages.Where(x => x.WelderCode.Contains(this.txtWelderCode.Text.Trim())); } if (this.drpUnit.SelectedValue != BLL.Const._Null) { pointManages = pointManages.Where(x => x.UnitId == this.drpUnit.SelectedValue); } pointManages = pointManages.OrderBy(x => x.StartDate); foreach (var item in pointManages) { TreeNode newNode = new TreeNode { NodeID = item.PointBatchId, ToolTip = "批", EnableClickEvent = true, }; var pipeline = PointBatchService.GetPointBatchById(item.PointBatchId); string startdate = string.Format("{0:yyyy-MM-dd}", pipeline.StartDate); string code = "DK-" + item.PointBatchCode.Substring(item.PointBatchCode.Length - 4) ; if (!item.EndDate.HasValue) ////批 没有关闭 粉色 { newNode.Text = "" + code + "【" + startdate + "】" + "【" + item.UnitName + "】" + ""; newNode.ToolTip = "批尚未关闭"; } // 当天批 else if (string.Format("{0:yyyy-MM-dd}", item.StartDate) == string.Format("{0:yyyy-MM-dd}", System.DateTime.Now) || string.Format("{0:yyyy-MM-dd}", item.EndDate) == string.Format("{0:yyyy-MM-dd}", System.DateTime.Now)) { newNode.Text = "" + code + "【" + startdate + "】" + "【" + item.UnitName + "】" + ""; newNode.ToolTip = "当天批"; } else { newNode.Text = code + "【" + startdate + "】" + "【" + item.UnitName + "】"; } e.Node.Nodes.Add(newNode); } } else { var pointManages = from x in Funs.DB.View_HJGL_Batch_PointBatch join y in Funs.DB.View_HJGL_Batch_PointBatchItem on x.PointBatchId equals y.PointBatchId where x.ProjectId == this.CurrUser.LoginProjectId && x.DetectionRateId == e.NodeID.Split('|')[0] && x.DetectionTypeId == e.Node.ParentNode.NodeID.Split('|')[0] && x.UnitWorkId == e.Node.ParentNode.ParentNode.NodeID //&& x.StartDate < Convert.ToDateTime(this.txtStartTime.Text.Trim() + "-01").AddMonths(1) //&& x.StartDate >= Convert.ToDateTime(this.txtStartTime.Text.Trim() + "-01") && y.WeldJointCode.Contains(this.txtWeldJointCode.Text.Trim()) select x; if (!string.IsNullOrEmpty(this.txtWelderCode.Text)) { pointManages = pointManages.Where(x => x.WelderCode.Contains(this.txtWelderCode.Text.Trim())); } if (this.drpUnit.SelectedValue != BLL.Const._Null) { pointManages = pointManages.Where(x => x.UnitId == this.drpUnit.SelectedValue); } foreach (var item in pointManages) { TreeNode newNode = new TreeNode { NodeID = item.PointBatchId, ToolTip = "批", EnableClickEvent = true, }; var pipeline = PointBatchService.GetPointBatchById(item.PointBatchId); string startdate = string.Format("{0:yyyy-MM-dd}", pipeline.StartDate); string PipeArea = ""; if (!string.IsNullOrEmpty(pipeline.PipelineId)) { switch (PipelineService.GetPipelineByPipelineId(pipeline.PipelineId).PipeArea) { case PipelineService.PipeArea_SHOP: PipeArea = "(工厂)"; break; case PipelineService.PipeArea_FIELD: PipeArea = "(现场)"; break; } } string code = "DK-" + item.PointBatchCode.Substring(item.PointBatchCode.Length - 4) + PipeArea; if (!item.EndDate.HasValue) ////批 没有关闭 粉色 { newNode.Text = "" + code + "【" + startdate + "】" + "【" + item.UnitName + "】" + ""; newNode.ToolTip = "批尚未关闭"; } // 当天批 else if (string.Format("{0:yyyy-MM-dd}", item.StartDate) == string.Format("{0:yyyy-MM-dd}", System.DateTime.Now) || string.Format("{0:yyyy-MM-dd}", item.EndDate) == string.Format("{0:yyyy-MM-dd}", System.DateTime.Now)) { newNode.Text = "" + code + "【" + startdate + "】" + "【" + item.UnitName + "】" + ""; newNode.ToolTip = "当天批"; } else { newNode.Text = code + "【" + startdate + "】" + "【" + item.UnitName + "】"; } e.Node.Nodes.Add(newNode); } } } } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { this.TbPipeline.Hidden = true; this.TbNotPipeline.Hidden = true; if (this.tvControlItem.SelectedNodeID != "0") { Model.SGGLDB db = Funs.DB; this.PointBatchId = tvControlItem.SelectedNodeID; this.BindGrid(); Model.Project_Sys_Set batch = BLL.Project_SysSetService.GetSysSetBySetId("5", this.CurrUser.LoginProjectId); if (batch != null) { if (batch.SetValue.Contains("6")) //按管线组批 { this.TbPipeline.Hidden = false; var pipeline = (from x in db.HJGL_Pipeline join y in db.HJGL_WeldJoint on x.PipelineId equals y.PipelineId join z in db.HJGL_Batch_PointBatchItem on y.WeldJointId equals z.WeldJointId where z.PointBatchId == this.PointBatchId select x).FirstOrDefault(); if (pipeline != null) { this.lbPipelineCode.Text = pipeline.PipelineCode; Model.Base_DetectionRate rate = BLL.Base_DetectionRateService.GetDetectionRateByDetectionRateId(pipeline.DetectionRateId); if (rate != null) { this.lbRate.Text = rate.DetectionRateValue + "%"; int totalJointCount = db.HJGL_WeldJoint.Count(x => x.PipelineId == pipeline.PipelineId); int needJointNum = Convert.ToInt32(Math.Ceiling((totalJointCount * rate.DetectionRateValue.Value) * 0.01)); this.lbNeedJointNum.Text = needJointNum.ToString(); var pointJointNum = (from x in db.HJGL_Batch_PointBatchItem join y in db.HJGL_WeldJoint on x.WeldJointId equals y.WeldJointId where y.PipelineId == pipeline.PipelineId && x.PointState == "1" select x).Count(); this.lbPointJointNum.Text = pointJointNum.ToString(); this.lbLastJointNum.Text = (needJointNum - pointJointNum).ToString(); } } } else //不按管线组批 { this.TbNotPipeline.Hidden = false; string unitWorkId = this.tvControlItem.SelectedNode.ParentNode.ParentNode.ParentNode.NodeID; string rateStr = this.tvControlItem.SelectedNode.ParentNode.Text; string rateId = this.tvControlItem.SelectedNode.ParentNode.NodeID.Split('|')[0]; string detectionType = this.tvControlItem.SelectedNode.ParentNode.ParentNode.NodeID.Split('|')[0]; this.lbTotalJointNum.Label = "本单位工程检测比例为" + rateStr + "的焊口总数"; var totalJoint = from x in db.HJGL_WeldJoint join y in db.HJGL_Pipeline on x.PipelineId equals y.PipelineId where y.DetectionRateId == rateId && y.UnitWorkId == unitWorkId && y.DetectionType == detectionType select x; int totalJointNum = totalJoint.Count(); int weldJointNum = totalJoint.Where(x => x.WeldingDailyId != null).Count(); int notWeldJointNum = totalJoint.Where(x => x.WeldingDailyId == null).Count(); this.lbTotalJointNum.Text = totalJointNum.ToString() + ", 已焊:" + weldJointNum.ToString() + ", 未焊:" + notWeldJointNum.ToString(); Model.Base_DetectionRate rate = BLL.Base_DetectionRateService.GetDetectionRateByDetectionRateId(rateId); if (rate != null) { int needJointNum = Convert.ToInt32(Math.Ceiling((totalJointNum * rate.DetectionRateValue.Value) * 0.01)); this.lbNeedJointNum2.Text = needJointNum.ToString(); var pointJointNum = (from x in db.HJGL_Batch_PointBatchItem join y in db.HJGL_Batch_PointBatch on x.PointBatchId equals y.PointBatchId where y.DetectionRateId == rateId && y.UnitWorkId == unitWorkId && y.DetectionTypeId == detectionType && x.PointState == "1" select x).Count(); this.lbPointJointNum2.Text = pointJointNum.ToString(); this.lbLastJointNum2.Text = (needJointNum - pointJointNum).ToString(); } } } } //Model.Parameter3D parameter3D = new Model.Parameter3D(); //Model.ColorModel colorModel = new Model.ColorModel(); //colorModel = BLL.Project_SysSetService.GetColorModel(this.CurrUser.LoginProjectId); //parameter3D.ColorModel = colorModel; //parameter3D.TagNum = "/E-9001,/E-9002"; //parameter3D.ButtonType = "0,4"; //ctlAuditFlow.Url_item = BLL.Project_SysSetService.GetAvevaNetUrl(this.CurrUser.LoginProjectId) + "item/IPE%7CVPD%7CArea-15A"; //ctlAuditFlow.data = parameter3D; //ctlAuditFlow.BindData(); } #endregion #region 数据绑定 #region 加载页面输入提交信息 /// /// 加载页面输入提交信息 /// private void PageInfoLoad() { this.txtStartDate.Text = string.Empty; this.txtEndDate.Text = string.Empty; this.txtState.Text = "未关闭"; Model.HJGL_Batch_PointBatch pointBatch = BLL.PointBatchService.GetPointBatchById(this.PointBatchId); if (pointBatch != null) { this.txtPointBatchCode.Text = pointBatch.PointBatchCode; if (pointBatch.StartDate.HasValue) { this.txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", pointBatch.StartDate); } if (pointBatch.EndDate.HasValue) { this.txtEndDate.Text = string.Format("{0:yyyy-MM-dd}", pointBatch.EndDate); this.txtState.Text = "已关闭"; } } var trustItem = (from x in Funs.DB.HJGL_Batch_BatchTrustItem join y in Funs.DB.HJGL_Batch_PointBatchItem on x.PointBatchItemId equals y.PointBatchItemId where y.PointBatchId == this.PointBatchId select x).FirstOrDefault(); if (trustItem != null) { this.txtPointState.Text = "不可调整"; } else { if (pointBatch != null) { if (pointBatch.IsClosed == true) { this.txtPointState.Text = "不可调整"; } else { this.txtPointState.Text = "可调整"; } } } } #endregion /// /// 数据绑定 /// private void BindGrid() { this.PageInfoLoad(); string strSql = @"SELECT PointBatchItemId,PointBatchId,WeldJointId,PointState,PointDate,RepairDate,CutDate,WeldJointCode,IsBuildTrust,WeldTypeCode, JointAttribute ,JointArea,IsWelderFirst,Size,WeldingDate,PipelineCode,PipingClassName,PointIsAudit,BackingWelderCode,CoverWelderCode FROM dbo.View_HJGL_Batch_PointBatchItem WHERE PointBatchId=@PointBatchId"; List listStr = new List(); if (!string.IsNullOrEmpty(PointBatchId)) { listStr.Add(new SqlParameter("@PointBatchId", this.PointBatchId)); } if (!string.IsNullOrEmpty(txtpipelinecode.Text.Trim())) { strSql += " and PipelineCode like @PipelineCode "; listStr.Add(new SqlParameter("@PipelineCode", "%" + txtpipelinecode.Text.Trim() + "%")); } 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(); for (int i = 0; i < this.Grid1.Rows.Count; i++) { this.Grid1.Rows[i].CellCssClasses[3] = null; this.Grid1.Rows[i].CellCssClasses[6] = null; var pointItem = BLL.PointBatchDetailService.GetBatchDetailById(this.Grid1.Rows[i].DataKeys[0].ToString()); if (pointItem != null) { if (pointItem.PointState != null) { this.Grid1.Rows[i].CellCssClasses[3] = "colorredBlue"; this.Grid1.Rows[i].CellCssClasses[6] = "colorredBlue"; } } } } /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } protected void btnQuery_Click(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 分页排序 #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 关闭弹出窗口及刷新页面 /// /// 批关闭 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { this.BindGrid(); } #region 查询 /// /// 查询 /// /// /// protected void Tree_TextChanged(object sender, EventArgs e) { this.InitTreeMenu(); } #endregion #endregion #region 手动关闭批 /// /// /// /// /// protected void btnClose_Click(object sender, EventArgs e) { var batch = BLL.PointBatchService.GetPointBatchById(this.PointBatchId); if (batch != null) { if (!batch.EndDate.HasValue) { PointBatchService.UpdateBatchIsClosed(this.PointBatchId, DateTime.Now); /*PointBatchService.UpdateBatchIsClosed2(this.PointBatchId, DateTime.Now); //生成委托单 Model.HJGL_Batch_BatchTrust newBatchTrust = new Model.HJGL_Batch_BatchTrust(); var project = BLL.ProjectService.GetProjectByProjectId(batch.ProjectId); var unit = BLL.UnitService.GetUnitByUnitId(batch.UnitId); var area = BLL.UnitWorkService.getUnitWorkByUnitWorkId(batch.UnitWorkId); var ndt = BLL.Base_DetectionTypeService.GetDetectionTypeByDetectionTypeId(batch.DetectionTypeId); var rate = BLL.Base_DetectionRateService.GetDetectionRateByDetectionRateId(batch.DetectionRateId); string perfix = string.Empty; newBatchTrust.TrustBatchCode = batch.PointBatchCode.Replace("-DK-", "-WT-"); string trustBatchId = SQLHelper.GetNewID(typeof(Model.HJGL_Batch_BatchTrust)); newBatchTrust.TrustBatchId = trustBatchId; newBatchTrust.TrustDate = DateTime.Now; newBatchTrust.ProjectId = batch.ProjectId; newBatchTrust.PointBatchId = batch.PointBatchId; newBatchTrust.UnitId = batch.UnitId; newBatchTrust.UnitWorkId = batch.UnitWorkId; newBatchTrust.DetectionTypeId = batch.DetectionTypeId; newBatchTrust.DetectionRateId = batch.DetectionRateId; newBatchTrust.PointBatchId = this.PointBatchId; BLL.Batch_BatchTrustService.AddBatchTrust(newBatchTrust); // 新增委托单*/ this.BindGrid(); Alert.ShowInTop("关批成功!", MessageBoxIcon.Success); } else { Alert.ShowInTop("批已关闭!", MessageBoxIcon.Success); } } else { Alert.ShowInTop("请选择检验批!", MessageBoxIcon.Success); } } #endregion #region 自动点口、打开重新点口、点口审核 /// /// /// /// /// protected void btnAutoPoint_Click(object sender, EventArgs e) { var batch = BLL.PointBatchService.GetPointBatchById(this.PointBatchId); if (!batch.EndDate.HasValue) { BLL.PointBatchDetailService.AutoPoint(this.PointBatchId); this.BindGrid(); Alert.ShowInTop("已成功点口!", MessageBoxIcon.Success); } else { Alert.ShowInTop("批已关闭,不能自动点口!", MessageBoxIcon.Success); } } protected void btnManual_Click(object sender, EventArgs e) { var batch = BLL.PointBatchService.GetPointBatchById(this.PointBatchId); if (!batch.EndDate.HasValue) { if (!string.IsNullOrEmpty(Grid1.SelectedRowID)) { Model.SGGLDB db = Funs.DB; var weldJoint = (from x in db.HJGL_WeldJoint join y in db.HJGL_Batch_PointBatchItem on x.WeldJointId equals y.WeldJointId where y.PointBatchItemId == Grid1.SelectedRowID select x).FirstOrDefault(); Model.Project_Sys_Set batchSet = BLL.Project_SysSetService.GetSysSetBySetId("5", this.CurrUser.LoginProjectId); if (batchSet != null && weldJoint != null) { int needJointNum = 0; int pointNumG = 0; int pointNumA = 0; if (batchSet.SetValue.Contains("6")) //按管线组批 { var pipeline = (from x in db.HJGL_Pipeline join y in db.HJGL_WeldJoint on x.PipelineId equals y.PipelineId join z in db.HJGL_Batch_PointBatchItem on y.WeldJointId equals z.WeldJointId where z.PointBatchId == this.PointBatchId select x).FirstOrDefault(); if (pipeline != null) { this.lbPipelineCode.Text = pipeline.PipelineCode; Model.Base_DetectionRate rate = BLL.Base_DetectionRateService.GetDetectionRateByDetectionRateId(pipeline.DetectionRateId); if (rate != null) { int totalJointCount = db.HJGL_WeldJoint.Count(x => x.PipelineId == pipeline.PipelineId); needJointNum = Convert.ToInt32(Math.Ceiling((totalJointCount * rate.DetectionRateValue.Value) * 0.01)); // 安装口检测数量 pointNumG = Convert.ToInt32(Math.Ceiling(needJointNum * 0.4)); // 预制口要检测的数量 pointNumA = needJointNum - pointNumG; var pointGNum = (from x in db.HJGL_Batch_PointBatchItem join y in db.HJGL_WeldJoint on x.WeldJointId equals y.WeldJointId where y.PipelineId == pipeline.PipelineId && x.PointState == "1" && y.JointAttribute == "安装口" select x).Count(); var pointNotGNum = (from x in db.HJGL_Batch_PointBatchItem join y in db.HJGL_WeldJoint on x.WeldJointId equals y.WeldJointId where y.PipelineId == pipeline.PipelineId && x.PointState == "1" && y.JointAttribute == "预制口" select x).Count(); if (weldJoint.JointAttribute == "安装口" && pointGNum >= pointNumG) { Alert.ShowInTop("安装口已达检测标准,无需再点此安装口!", MessageBoxIcon.Warning); return; } if (weldJoint.JointAttribute == "预制口" && pointNotGNum >= pointNumA) { Alert.ShowInTop("预制口已达检测标准,无需再点此预制口!", MessageBoxIcon.Warning); return; } } } } else //不按管线组批 { string unitWorkId = this.tvControlItem.SelectedNode.ParentNode.ParentNode.ParentNode.NodeID; string rateId = this.tvControlItem.SelectedNode.ParentNode.NodeID.Split('|')[0]; string detectionType = this.tvControlItem.SelectedNode.ParentNode.ParentNode.NodeID.Split('|')[0]; int totalJointNum = (from x in db.HJGL_WeldJoint join y in db.HJGL_Pipeline on x.PipelineId equals y.PipelineId where y.DetectionRateId == rateId && y.UnitWorkId == unitWorkId && y.DetectionType == detectionType select x).Count(); Model.Base_DetectionRate rate = BLL.Base_DetectionRateService.GetDetectionRateByDetectionRateId(rateId); if (rate != null) { needJointNum = Convert.ToInt32(Math.Ceiling((totalJointNum * rate.DetectionRateValue.Value) * 0.01)); // 安装口检测数量 pointNumG = Convert.ToInt32(Math.Ceiling(needJointNum * 0.4)); // 预制口要检测的数量 pointNumA = needJointNum - pointNumG; var pointGNum = (from x in db.HJGL_Batch_PointBatchItem join y in db.HJGL_Batch_PointBatch on x.PointBatchId equals y.PointBatchId join z in db.HJGL_WeldJoint on x.WeldJointId equals z.WeldJointId where y.DetectionRateId == rateId && y.UnitWorkId == unitWorkId && y.DetectionTypeId == detectionType && x.PointState == "1" && z.JointAttribute == "安装口" select x).Count(); var pointNotGNum = (from x in db.HJGL_Batch_PointBatchItem join y in db.HJGL_Batch_PointBatch on x.PointBatchId equals y.PointBatchId join z in db.HJGL_WeldJoint on x.WeldJointId equals z.WeldJointId where y.DetectionRateId == rateId && y.UnitWorkId == unitWorkId && y.DetectionTypeId == detectionType && x.PointState == "1" && z.JointAttribute == "预制口" select x).Count(); if (weldJoint.JointAttribute == "安装口" && pointGNum >= pointNumG) { Alert.ShowInTop("安装口已达检测标准,无需再点此安装口!", MessageBoxIcon.Warning); return; } if (weldJoint.JointAttribute == "预制口" && pointNotGNum >= pointNumA) { Alert.ShowInTop("预制口已达检测标准,无需再点此预制口!", MessageBoxIcon.Warning); return; } } } } PointBatchDetailService.UpdatePointBatchDetail(Grid1.SelectedRowID, "1", System.DateTime.Now); this.BindGrid(); tvControlItem_NodeCommand(null, null); Alert.ShowInTop("已成功点口!", MessageBoxIcon.Success); } else { Alert.ShowInTop("请选择点口!", MessageBoxIcon.Warning); } } else { Alert.ShowInTop("批已关闭,不能点口!", MessageBoxIcon.Success); } } /// /// 手动点口关闭 /// /// /// protected void btnPointAudit_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, Const.HJGL_PointBatchMenuId, Const.BtnPointAudit)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PointAudit.aspx", "点口审核 - "))); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } /// /// 打开重新点口 /// /// /// protected void btnbtnOpenResetPoint_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, Const.HJGL_PointBatchMenuId, Const.BtnOpenResetPoint)) { if (!string.IsNullOrEmpty(this.PointBatchId)) { var trustItem = (from x in Funs.DB.HJGL_Batch_BatchTrustItem join y in Funs.DB.HJGL_Batch_PointBatchItem on x.PointBatchItemId equals y.PointBatchItemId where y.PointBatchId == this.PointBatchId select x).FirstOrDefault(); if (trustItem != null) { Alert.ShowInTop("该批次不可调整!"); return; } Model.HJGL_Batch_PointBatch pointBatch = BLL.PointBatchService.GetPointBatchById(this.PointBatchId); if (pointBatch != null && pointBatch.IsClosed == true) { Alert.ShowInTop("该批次不可调整!"); return; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("OpenResetPoint.aspx?PointBatchId={0}", this.PointBatchId, "重新点口 - "))); } else { Alert.ShowInTop("请选择要重新点口的批!"); } } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } /// /// 重新选择扩口 /// /// /// protected void btnSelectExpandPoint_Click(object sender, EventArgs e) { } #endregion #region 生成委托单 /// /// 生成委托单 /// /// /// protected void btnGeneratingOrder_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, Const.HJGL_PointBatchMenuId, Const.BtnPointAudit)) { string batchId = this.tvControlItem.SelectedNodeID; if (!string.IsNullOrEmpty(batchId)) { var batch = BLL.PointBatchService.GetPointBatchById(batchId); var detail = BLL.PointBatchDetailService.GetBatchDetailByBatchId(batchId); foreach (var d in detail) { for (int i = 0; i < this.Grid1.Rows.Count; i++) { System.Web.UI.WebControls.CheckBoxList cblNDT = (System.Web.UI.WebControls.CheckBoxList)(this.Grid1.Rows[i].FindControl("cblNDT")); System.Web.UI.WebControls.HiddenField hdBatchDetailId = (System.Web.UI.WebControls.HiddenField)(this.Grid1.Rows[i].FindControl("hdBatchDetailId")); if (d.PointBatchItemId == hdBatchDetailId.Value) { string ndtId = string.Empty; foreach (System.Web.UI.WebControls.ListItem item in cblNDT.Items) { if (item.Selected) { ndtId += item.Value + ","; } } if (!string.IsNullOrEmpty(ndtId)) { ndtId = ndtId.Substring(0, ndtId.LastIndexOf(",")); d.NDT = ndtId; BLL.PointBatchDetailService.UpdatePointBatchDetail(d); } } } } if (batch.EndDate.HasValue && detail.Where(d => d.NDT != null).Count() > 0) { var detectionTypes = from x in Funs.DB.Base_DetectionType select x; var type1 = detectionTypes.FirstOrDefault(x => x.DetectionTypeId == batch.DetectionTypeId); string typeStr1 = string.Empty; if (type1 != null) { typeStr1 = type1.DetectionTypeCode; } var trust = from x in Funs.DB.HJGL_Batch_BatchTrust where x.PointBatchId == batchId select x; if (trust.Count() == 0) { detail = detail.Where(d => d.NDT != null).ToList(); foreach (var d in detail) { string[] ndts = d.NDT.Split(','); // 可能有多种探伤类型 foreach (string n in ndts) { var trustNdt = from x in Funs.DB.HJGL_Batch_BatchTrust where x.PointBatchId == batchId && x.DetectionTypeId == n select x; if (trustNdt.Count() == 0) { Model.HJGL_Batch_BatchTrust newBatchTrust = new Model.HJGL_Batch_BatchTrust(); var project = BLL.ProjectService.GetProjectByProjectId(batch.ProjectId); var unit = BLL.UnitService.GetUnitByUnitId(batch.UnitId); var area = BLL.UnitWorkService.getUnitWorkByUnitWorkId(batch.UnitWorkId); var ndt = BLL.Base_DetectionTypeService.GetDetectionTypeByDetectionTypeId(batch.DetectionTypeId); var rate = BLL.Base_DetectionRateService.GetDetectionRateByDetectionRateId(batch.DetectionRateId); string perfix = string.Empty; var type2 = detectionTypes.FirstOrDefault(x => x.DetectionTypeId == n); string typeStr2 = string.Empty; if (type2 != null) { typeStr2 = type2.DetectionTypeCode; } newBatchTrust.TrustBatchCode = BLL.Batch_BatchTrustService.BuildTrustBatchCode(batch.PointBatchCode, DateTime.Now, typeStr1, typeStr2); string trustBatchId = SQLHelper.GetNewID(typeof(Model.HJGL_Batch_BatchTrust)); newBatchTrust.TrustBatchId = trustBatchId; newBatchTrust.TrustDate = DateTime.Now; newBatchTrust.ProjectId = batch.ProjectId; newBatchTrust.PointBatchId = batch.PointBatchId; newBatchTrust.UnitId = batch.UnitId; newBatchTrust.UnitWorkId = batch.UnitWorkId; newBatchTrust.DetectionTypeId = n; newBatchTrust.DetectionRateId = batch.DetectionRateId; var NDEUnit = Funs.DB.Project_ProjectUnit.FirstOrDefault(x => x.ProjectId == this.CurrUser.LoginProjectId && x.UnitType == BLL.Const.ProjectUnitType_5); if (NDEUnit != null) { newBatchTrust.NDEUnit = NDEUnit.UnitId; } newBatchTrust.PointBatchId = this.PointBatchId; BLL.Batch_BatchTrustService.AddBatchTrust(newBatchTrust); // 新增委托单 // 增加明细 Model.HJGL_Batch_BatchTrustItem item = new Model.HJGL_Batch_BatchTrustItem(); item.TrustBatchItemId = SQLHelper.GetNewID(typeof(Model.HJGL_Batch_BatchTrustItem)); item.TrustBatchId = trustBatchId; item.PointBatchItemId = d.PointBatchItemId; item.WeldJointId = d.WeldJointId; item.CreateDate = DateTime.Now; BLL.Batch_BatchTrustItemService.AddBatchTrustItem(item); } else { Model.HJGL_Batch_BatchTrustItem item = new Model.HJGL_Batch_BatchTrustItem(); item.TrustBatchItemId = SQLHelper.GetNewID(typeof(Model.HJGL_Batch_BatchTrustItem)); item.TrustBatchId = trustNdt.First().TrustBatchId; item.PointBatchItemId = d.PointBatchItemId; item.WeldJointId = d.WeldJointId; item.CreateDate = DateTime.Now; BLL.Batch_BatchTrustItemService.AddBatchTrustItem(item); } } } BLL.LogService.AddSys_Log(this.CurrUser, this.PointBatchId, this.PointBatchId, BLL.Const.HJGL_PointBatchMenuId, "生成委托单"); ShowNotify("成功生成委托单!", MessageBoxIcon.Success); } else { ShowNotify("已生成委托单!", MessageBoxIcon.Warning); } } else { ShowNotify("批未关闭或批里没有点口!", MessageBoxIcon.Warning); } } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #endregion #region 切除焊口 #endregion #region 取消扩透 /// /// 取消扩透 /// /// /// protected void btnCancel_Click(object sender, EventArgs e) { } #endregion #region 打印 /// /// 打印 /// /// /// protected void btnPrint_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.PointBatchId)) { string parm = string.Empty; var pointBatch = Funs.DB.View_HJGL_Batch_PointBatch.FirstOrDefault(x => x.PointBatchId == this.PointBatchId); if (pointBatch != null) { if (!string.IsNullOrEmpty(pointBatch.UnitCode)) { parm = pointBatch.UnitCode; } else { parm = "NULL"; } if (!string.IsNullOrEmpty(pointBatch.ProjectCode)) { parm = parm + "|" + pointBatch.ProjectCode; } else { parm = parm + "|" + "NULL"; } if (!string.IsNullOrEmpty(pointBatch.DetectionTypeCode)) { parm = parm + "|" + "NDE Type:" + pointBatch.DetectionTypeCode; } else { parm = parm + "|" + "NDE Type:" + "NULL"; } // PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../../Report/ReportPrint.aspx?report=1&pointBatchId={0}&parm={1}", this.PointBatchId, parm, "编辑 - "))); } } } #endregion private string GetNewTrust(string code) { int r_num = 0; string newTrustCode = string.Empty; if (code.Contains("A") || code.Contains("B") || code.Contains("C")) { //int indexR = code.LastIndexOf("R"); //if (indexR > 0) //{ // try // { // r_num = Convert.ToInt32(code.Substring(indexR + 1, 1)) + 1; // newTrustCode = code.Substring(0, code.Length - 1) + r_num.ToString(); // } // catch { } //} string s = code.Substring(code.Length - 1, 1); string m = string.Empty; if (s == "A") { m = "B"; } else if (s == "B") { m = "C"; } newTrustCode = code.Substring(0, code.Length - 1) + m; } else { newTrustCode = code + "A"; } return newTrustCode; } /// /// 已检测口明细 /// /// /// protected void btnShow_Click(object sender, EventArgs e) { string unitWorkId = this.tvControlItem.SelectedNode.ParentNode.ParentNode.ParentNode.NodeID; string rateId = this.tvControlItem.SelectedNode.ParentNode.NodeID.Split('|')[0]; string detectionType = this.tvControlItem.SelectedNode.ParentNode.ParentNode.NodeID.Split('|')[0]; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PointWeldJointView.aspx?unitWorkId={0}&rateId={1}&detectionType={2}", unitWorkId, rateId, detectionType, "新增 - "))); } #region Grid绑定事件 /// /// Grid1绑定事件 /// /// /// protected void Grid1_RowDataBound(object sender, GridRowEventArgs e) { var batch = Funs.DB.View_HJGL_Batch_PointBatch.FirstOrDefault(x => x.PointBatchId == this.tvControlItem.SelectedNodeID); if (batch != null) { string[] strs = batch.DetectionTypeCode.Split('/'); System.Web.UI.WebControls.CheckBoxList cblNDT = (System.Web.UI.WebControls.CheckBoxList)(this.Grid1.Rows[e.RowIndex].FindControl("cblNDT")); cblNDT.DataTextField = "DetectionTypeCode"; cblNDT.DataValueField = "DetectionTypeId"; cblNDT.DataSource = BLL.Base_DetectionTypeService.GetDetectionTypeListByDetectionTypeType2(strs); cblNDT.DataBind(); var batchDetail = BLL.PointBatchDetailService.GetBatchDetailById(hdBatchDetailId.Value); if (batchDetail != null) { if (!string.IsNullOrEmpty(batchDetail.NDT)) { List ndtIds = batchDetail.NDT.Split(',').ToList(); foreach (var ndtId in ndtIds) { for (int i = 0; i < cblNDT.Items.Count; i++) { if (cblNDT.Items[i].Value == ndtId) { cblNDT.Items[i].Selected = true; } } } } } } } #endregion } }