using BLL; using Model; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Reflection; using System.Web.UI.WebControls; namespace FineUIPro.Web.WeldingProcess.TrustManage { public partial class PointForAudit : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); BLL.Base_DetectionTypeService.InitDetectionTypeDropDownList(drpNde, "", false, ""); drpNde.SelectedValue = "32617d42-24cb-4390-b115-d53c9c9e2c81"; // 默认RT BindGrid(); } } private void BindGrid() { string strSql = @"SELECT PointBatchItemId,PointBatchId,PointBatchCode,WeldJointId,PointState,PointDate,WorkAreaCode, WeldJointCode,JointArea,Size,WelderCode,WeldingDate,PipelineCode,PipingClassName, (CASE WHEN IsWelderFirst=1 THEN '是' ELSE '否' END) AS IsWelderFirst, JLAudit,GLGSAudit,QTAudit,IsPointAudit FROM dbo.View_Batch_PointBatchItem WHERE PointState IS NOT NULL AND TrustBatchItemId IS NULL"; List listStr = new List(); if (!string.IsNullOrEmpty(this.txtPipeCode.Text)) { strSql += " AND PipelineCode LIKE @PipelineCode"; listStr.Add(new SqlParameter("@PipelineCode", "%" + this.txtPipeCode.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtPointStartDate.Text)) { strSql += " AND PointDate >= @PointStartDate"; listStr.Add(new SqlParameter("@PointStartDate", Convert.ToDateTime(this.txtPointStartDate.Text))); } if (!string.IsNullOrEmpty(this.txtPointEndDate.Text)) { strSql += " AND PointDate < @PointEndDate"; listStr.Add(new SqlParameter("@PointEndDate", Convert.ToDateTime(this.txtPointEndDate.Text).AddDays(1))); } if (drpNoAudit.SelectedValue != "0") { if (drpNoAudit.SelectedValue == "1") { strSql += " AND JLAudit='未审核'"; } if (drpNoAudit.SelectedValue == "2") { strSql += " AND GLGSAudit='未审核'"; } if (drpNoAudit.SelectedValue == "3") { strSql += " AND QTAudit='未审核'"; } } else { strSql += " AND (JLAudit='未审核' OR GLGSAudit='未审核' OR QTAudit='未审核')"; } if (drpNde.SelectedValue != null) { strSql += " AND DetectionTypeId=@DetectionTypeId"; listStr.Add(new SqlParameter("@DetectionTypeId", drpNde.SelectedValue)); } SqlParameter[] parameter = listStr.ToArray(); DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = dt.Rows.Count; var table = this.GetPagedDataTable(Grid1, dt); Grid1.DataSource = table; Grid1.DataBind(); } #region /// /// 改变索引事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } /// /// 分页下拉选择事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { this.BindGrid(); } #endregion protected void BtnAnalyse_Click(object sender, EventArgs e) { BindGrid(); } protected void Window2_Close(object sender, WindowCloseEventArgs e) { this.BindGrid(); } protected void btnJLAudit_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PointForAuditMenuId, Const.BtnJLAudit)) { if (Grid1.SelectedRowIndexArray.Length <= 0) { Alert.ShowInTop("最少选中一行!", MessageBoxIcon.Warning); return; } string userId = CurrUser.UserId; foreach (string pointBatchItemId in Grid1.SelectedRowIDArray) { var pointBatchItem = BLL.Batch_PointBatchItemService.GetPointBatchItemByPointBatchItemId(pointBatchItemId); pointBatchItem.JLAudit = userId; BLL.Funs.DB.SubmitChanges(); } Alert.ShowInTop("所选项审核完成!", MessageBoxIcon.Warning); BindGrid(); } else { ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); return; } } protected void btnGLGSAudit_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PointForAuditMenuId, Const.BtnGLGSAudit)) { if (Grid1.SelectedRowIndexArray.Length <= 0) { Alert.ShowInTop("最少选中一行!", MessageBoxIcon.Warning); return; } string userId = CurrUser.UserId; foreach (string pointBatchItemId in Grid1.SelectedRowIDArray) { var pointBatchItem = BLL.Batch_PointBatchItemService.GetPointBatchItemByPointBatchItemId(pointBatchItemId); pointBatchItem.GLGSAudit = userId; BLL.Funs.DB.SubmitChanges(); } Alert.ShowInTop("所选项审核完成!", MessageBoxIcon.Warning); BindGrid(); } else { ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); return; } } protected void btnOtherAudit_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PointForAuditMenuId, Const.BtnQTAudit)) { if (Grid1.SelectedRowIndexArray.Length <= 0) { Alert.ShowInTop("最少选中一行!", MessageBoxIcon.Warning); return; } string userId = CurrUser.UserId; foreach (string pointBatchItemId in Grid1.SelectedRowIDArray) { var pointBatchItem = BLL.Batch_PointBatchItemService.GetPointBatchItemByPointBatchItemId(pointBatchItemId); pointBatchItem.QTAudit = userId; BLL.Funs.DB.SubmitChanges(); } Alert.ShowInTop("所选项审核完成!", MessageBoxIcon.Warning); BindGrid(); } else { ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); return; } } /// /// 手动生成委托单 /// /// /// protected void btnHandGenerate_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PointManageMenuId, Const.BtnHandGenerate)) { bool isAudit = true; string[] selectedRowIDArray = Grid1.SelectedRowIDArray; foreach (string rowId in selectedRowIDArray) { var q =from x in Funs.DB.Batch_PointBatchItem where x.PointBatchItemId== rowId && (x.JLAudit==null || x.GLGSAudit==null) select x; if (q.Count() > 0) { isAudit=false; break; } } if (!isAudit) { Alert.ShowInTop("有未审核的焊口!", MessageBoxIcon.Warning); return; } string PointBatchItemList = string.Join(",", selectedRowIDArray); if (selectedRowIDArray.Length > 0) { string strSql = @"SELECT pItem.PointBatchId,jot.WeldingMethodId,jot.GrooveTypeId, (CASE WHEN pItem.IsWelderFirst=1 THEN 1 ELSE 0 END) AS IsWelderFirst FROM Batch_PointBatchItem AS pItem LEFT JOIN Pipeline_WeldJoint AS jot ON jot.WeldJointId=pItem.WeldJointId WHERE CHARINDEX(PointBatchItemId,@PointBatchItemList)>0 GROUP BY pItem.PointBatchId, jot.WeldingMethodId,jot.GrooveTypeId, (CASE WHEN pItem.IsWelderFirst=1 THEN 1 ELSE 0 END)"; List listStr = new List(); listStr.Add(new SqlParameter("@PointBatchItemList", PointBatchItemList)); SqlParameter[] parameter = listStr.ToArray(); DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter); if (dt.Rows.Count > 0) { foreach (DataRow r in dt.Rows) { var point = BLL.Batch_PointBatchService.GetPointBatchById(r["PointBatchId"].ToString()); var iso = BLL.Pipeline_PipelineService.GetPipelineByPipelineId(point.PipelineId); var project = BLL.Base_ProjectService.GetProjectByProjectId(point.ProjectId); var unit = BLL.Base_UnitService.GetUnit(point.UnitId); var ndt = BLL.Base_DetectionTypeService.GetDetectionTypeByDetectionTypeId(point.DetectionTypeId); var work = BLL.Project_WorkAreaService.GetProject_WorkAreaByWorkAreaId(iso.WorkAreaId); Model.Batch_BatchTrust newBatchTrust = new Model.Batch_BatchTrust(); string perfix = string.Empty; perfix = ndt.DetectionTypeCode + "-" + unit.UnitCode + "-" + work.WorkAreaCode + "-PI" + "-"; newBatchTrust.TrustBatchCode = BLL.SQLHelper.RunProcNewId("SpGetNewCode", "dbo.Batch_BatchTrust", "TrustBatchCode", project.ProjectId, perfix); string trustBatchId = SQLHelper.GetNewID(typeof(Model.Batch_BatchTrust)); newBatchTrust.TrustBatchId = trustBatchId; newBatchTrust.TrustDate = DateTime.Now; newBatchTrust.ProjectId = point.ProjectId; newBatchTrust.UnitId = point.UnitId; newBatchTrust.InstallationId = point.InstallationId; newBatchTrust.WorkAreaId = iso.WorkAreaId; newBatchTrust.WeldingMethodId = r["WeldingMethodId"].ToString(); newBatchTrust.GrooveTypeId = r["GrooveTypeId"].ToString(); newBatchTrust.IsWelderFirst = Convert.ToBoolean(r["IsWelderFirst"]); newBatchTrust.DetectionTypeId = point.DetectionTypeId; newBatchTrust.PipelineId = point.PipelineId; BLL.Batch_BatchTrustService.AddBatchTrust(newBatchTrust); // 新增委托单 // 生成委托明细,并回写点口明细信息 string itemSql = @"SELECT pItem.PointBatchItemId,pItem.PointBatchId,jot.WeldingMethodId, jot.GrooveTypeId,(CASE WHEN pItem.IsWelderFirst=1 THEN 1 ELSE 0 END) AS IsWelderFirst FROM Batch_PointBatchItem AS pItem LEFT JOIN Pipeline_WeldJoint AS jot ON jot.WeldJointId=pItem.WeldJointId WHERE CHARINDEX(PointBatchItemId,@PointBatchItemList)>0 AND PointBatchId=@PointBatchId AND jot.WeldingMethodId=@WeldingMethodId AND jot.GrooveTypeId=@GrooveTypeId AND (CASE WHEN pItem.IsWelderFirst=1 THEN '1' ELSE '0' END)=@IsWelderFirst"; List param = new List(); param.Add(new SqlParameter("@PointBatchItemList", PointBatchItemList)); param.Add(new SqlParameter("@PointBatchId", r["PointBatchId"].ToString())); param.Add(new SqlParameter("@WeldingMethodId", newBatchTrust.WeldingMethodId)); param.Add(new SqlParameter("@GrooveTypeId", newBatchTrust.GrooveTypeId)); param.Add(new SqlParameter("@IsWelderFirst", r["IsWelderFirst"].ToString())); SqlParameter[] paramList = param.ToArray(); DataTable dtItem = SQLHelper.GetDataTableRunText(itemSql, paramList); string toPointBatch = string.Empty; foreach (DataRow item in dtItem.Rows) { //str pointItemId = ""; var pointItem = BLL.Batch_PointBatchItemService.GetPointBatchItemByPointBatchItemId(item["PointBatchItemId"].ToString()); if (BLL.Batch_PointBatchService.GetIsGenerateTrust(pointItem.PointBatchItemId)) // 生成委托单的条件判断 { if (!toPointBatch.Contains(pointItem.PointBatchId)) { toPointBatch = toPointBatch + pointItem.PointBatchId + ","; } Model.Batch_BatchTrustItem trustItem = new Model.Batch_BatchTrustItem { TrustBatchItemId = SQLHelper.GetNewID(typeof(Model.Batch_BatchTrustItem)), TrustBatchId = trustBatchId, PointBatchItemId = pointItem.PointBatchItemId, WeldJointId = pointItem.WeldJointId, //FilmNum = fileNum, CreateDate = DateTime.Now }; Batch_BatchTrustItemService.AddBatchTrustItem(trustItem); } //Model.Batch_PointBatchItem pointBatchItem = Funs.DB.Batch_PointBatchItem.FirstOrDefault(e => e.PointBatchItemId == item.PointBatchItemId); pointItem.IsBuildTrust = true; Funs.DB.SubmitChanges(); } // 回写委托批对应点口信息 if (!string.IsNullOrEmpty(toPointBatch)) { toPointBatch = toPointBatch.Substring(0, toPointBatch.Length - 1); var updateTrut = BLL.Batch_BatchTrustService.GetBatchTrustById(trustBatchId); if (updateTrut != null) { updateTrut.TopointBatch = toPointBatch; BLL.Batch_BatchTrustService.UpdateBatchTrust(updateTrut); } } } BindGrid(); Alert.ShowInTop("委托单已生成!", MessageBoxIcon.Success); } } else { Alert.ShowInTop("请勾选要生成委托单的焊口!", MessageBoxIcon.Warning); } } else { ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); return; } #region 不用了改为自动分组 // List selectRow = new List(); // foreach (string pitem in Grid1.SelectedRowIDArray) // { // selectRow.Add(pitem); // } // if (selectRow.Count() > 0) // { // List weldMot = new List(); // List grooveType = new List(); // List IsFist = new List(); // List pointBatchIds = new List(); // string error = string.Empty; // foreach (string pointItemId in selectRow) // { // var pointItem = BLL.Batch_PointBatchItemService.GetPointBatchItemByPointBatchItemId(pointItemId); // var jot = BLL.Pipeline_WeldJointService.GetWeldJointByWeldJointId(pointItem.WeldJointId); // weldMot.Add(jot.WeldingMethodId); // grooveType.Add(jot.GrooveTypeId); // IsFist.Add(pointItem.IsWelderFirst == true ? true : false); // pointBatchIds.Add(pointItem.PointBatchId); // } // if (pointBatchIds.Distinct().Count() > 1) // { // error = "勾选的焊口不在一个批次中,"; // } // if (weldMot.Distinct().Count() > 1) // { // error = "勾选的焊口焊接方法不一至,"; // } // if (grooveType.Distinct().Count() > 1) // { // error = error + "勾选的焊口坡口类型不一至,"; // } // if (IsFist.Distinct().Count() > 1) // { // error = error + "勾选的焊口是否首三不一至,"; // } // if (error == string.Empty) // { // var point = BLL.Batch_PointBatchService.GetPointBatchById(pointBatchIds[0]); // var iso = BLL.Pipeline_PipelineService.GetPipelineByPipelineId(point.PipelineId); // var project = BLL.Base_ProjectService.GetProjectByProjectId(point.ProjectId); // var unit = BLL.Base_UnitService.GetUnit(point.UnitId); // var ndt = BLL.Base_DetectionTypeService.GetDetectionTypeByDetectionTypeId(point.DetectionTypeId); // var work = BLL.Project_WorkAreaService.GetProject_WorkAreaByWorkAreaId(iso.WorkAreaId); // Model.Batch_BatchTrust newBatchTrust = new Model.Batch_BatchTrust(); // string perfix = string.Empty; // //perfix = unit.UnitCode + "-" + ins.InstallationCode + "-GD-" + ndt.DetectionTypeCode + "-"; // perfix = ndt.DetectionTypeCode + "-" + unit.UnitCode + "-" + work.WorkAreaCode + "-PI" + "-"; // newBatchTrust.TrustBatchCode = BLL.SQLHelper.RunProcNewId("SpGetNewCode", "dbo.Batch_BatchTrust", "TrustBatchCode", project.ProjectId, perfix); // string trustBatchId = SQLHelper.GetNewID(typeof(Model.Batch_BatchTrust)); // newBatchTrust.TrustBatchId = trustBatchId; // newBatchTrust.TrustDate = DateTime.Now; // newBatchTrust.ProjectId = point.ProjectId; // newBatchTrust.UnitId = point.UnitId; // newBatchTrust.InstallationId = point.InstallationId; // newBatchTrust.WorkAreaId = iso.WorkAreaId; // newBatchTrust.WeldingMethodId = weldMot[0]; // newBatchTrust.GrooveTypeId = grooveType[0]; // newBatchTrust.IsWelderFirst = IsFist[0]; // newBatchTrust.DetectionTypeId = point.DetectionTypeId; // newBatchTrust.PipelineId = point.PipelineId; // BLL.Batch_BatchTrustService.AddBatchTrust(newBatchTrust); // 新增委托单 // // 生成委托明细,并回写点口明细信息 // string toPointBatch = string.Empty; // foreach (string pointItemId in selectRow) // { // var pointItem = BLL.Batch_PointBatchItemService.GetPointBatchItemByPointBatchItemId(pointItemId); // if (BLL.Batch_PointBatchService.GetIsGenerateTrust(pointItem.PointBatchItemId)) ////生成委托单的条件判断 // { // if (!toPointBatch.Contains(pointItem.PointBatchId)) // { // toPointBatch = toPointBatch + pointItem.PointBatchId + ","; // } // Model.Batch_BatchTrustItem trustItem = new Model.Batch_BatchTrustItem // { // TrustBatchItemId = SQLHelper.GetNewID(typeof(Model.Batch_BatchTrustItem)), // TrustBatchId = trustBatchId, // PointBatchItemId = pointItem.PointBatchItemId, // WeldJointId = pointItem.WeldJointId, // //FilmNum = fileNum, // CreateDate = DateTime.Now // }; // Batch_BatchTrustItemService.AddBatchTrustItem(trustItem); // } // //Model.Batch_PointBatchItem pointBatchItem = Funs.DB.Batch_PointBatchItem.FirstOrDefault(e => e.PointBatchItemId == item.PointBatchItemId); // pointItem.IsBuildTrust = true; // Funs.DB.SubmitChanges(); // } // // 回写委托批对应点口信息 // if (!string.IsNullOrEmpty(toPointBatch)) // { // toPointBatch = toPointBatch.Substring(0, toPointBatch.Length - 1); // var updateTrut = BLL.Batch_BatchTrustService.GetBatchTrustById(trustBatchId); // if (updateTrut != null) // { // updateTrut.TopointBatch = toPointBatch; // BLL.Batch_BatchTrustService.UpdateBatchTrust(updateTrut); // } // } // Alert.ShowInTop("委托单已生成!", MessageBoxIcon.Success); // } // else // { // Alert.ShowInTop(error + "不能组成一个委托单!", MessageBoxIcon.Warning); // } // } // else // { // Alert.ShowInTop("请勾选要生成委托单的焊口!", MessageBoxIcon.Warning); // } //} //else //{ // ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); // return; //} #endregion } } }