374 lines
		
	
	
		
			20 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			374 lines
		
	
	
		
			20 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using System; | |||
|  | using System.Collections.Generic; | |||
|  | using System.Linq; | |||
|  | using System.Text; | |||
|  | using System.Collections; | |||
|  | using System.Data; | |||
|  | 
 | |||
|  | namespace BLL | |||
|  | { | |||
|  |     /// <summary> | |||
|  |     /// 检验批管理 | |||
|  |     /// </summary> | |||
|  |     public static class InspectionManagementService | |||
|  |     { | |||
|  |         public static Model.SUBQHSEDB db = Funs.DB; | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 记录数 | |||
|  |         /// </summary> | |||
|  |         private static int count | |||
|  |         { | |||
|  |             get; | |||
|  |             set; | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 获取分页列表 | |||
|  |         /// </summary> | |||
|  |         /// <param name="projectId"></param> | |||
|  |         /// <param name="UnitWorkId"></param> | |||
|  |         /// <param name="cNProfessionalId"></param> | |||
|  |         /// <param name="startDate"></param> | |||
|  |         /// <param name="endDate"></param> | |||
|  |         /// <param name="startRowIndex"></param> | |||
|  |         /// <param name="maximumRows"></param> | |||
|  |         /// <returns></returns> | |||
|  |         public static IEnumerable GetListData(string projectId, string UnitWorkId, string cNProfessionalId, string startDate, string endDate, int startRowIndex, int maximumRows) | |||
|  |         { | |||
|  |             IQueryable<Model.ProcessControl_InspectionManagement> q = from x in db.ProcessControl_InspectionManagement | |||
|  |                                                                       where x.ProjectId == projectId && x.FileType == null | |||
|  |                                                                       orderby x.InspectionDate descending | |||
|  |                                                                       select x; | |||
|  |             if (UnitWorkId != "0") | |||
|  |             { | |||
|  |                 q = q.Where(e => e.UnitWorkId == UnitWorkId); | |||
|  |             } | |||
|  |             if (cNProfessionalId != "0") | |||
|  |             { | |||
|  |                 q = q.Where(e => e.CNProfessionalId == cNProfessionalId); | |||
|  |             } | |||
|  |             if (!string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate)) | |||
|  |             { | |||
|  |                 q = q.Where(e => e.InspectionDate >= Funs.GetNewDateTime(startDate) && e.InspectionDate <= Funs.GetNewDateTime(endDate)); | |||
|  |             } | |||
|  |             count = q.Count(); | |||
|  |             if (count == 0) | |||
|  |             { | |||
|  |                 return new object[] { "" }; | |||
|  |             } | |||
|  |             return from x in q.Skip(startRowIndex).Take(maximumRows) | |||
|  |                    select new | |||
|  |                    { | |||
|  |                        x.InspectionId, | |||
|  |                        x.ProjectId, | |||
|  |                        x.NoticeCode, | |||
|  |                        x.AcceptanceCheckMan, | |||
|  |                        UnitName = (from y in db.Base_Unit where y.UnitId == x.UnitId select y.UnitName).FirstOrDefault(), | |||
|  |                        ProfessionalName = (from y in db.Base_CNProfessional where y.CNProfessionalId == x.CNProfessionalId select y.ProfessionalName).FirstOrDefault(), | |||
|  |                        x.InspectionCode, | |||
|  |                        InstallationName = (from y in db.WBS_UnitWork where y.UnitWorkId == x.UnitWorkId select y.UnitWorkName).FirstOrDefault(), | |||
|  |                        Branch = (from y in db.WBS_DivisionProject where y.DivisionProjectId == x.Branch select y.DivisionName).FirstOrDefault(),//分部 | |||
|  |                        ControlPointType = (from y in db.WBS_BreakdownProject where y.BreakdownProjectId == x.ControlPointType select y.BreakdownName).FirstOrDefault(),//质量控制点 | |||
|  |                        Class = (from y in db.WBS_BreakdownProject where y.BreakdownProjectId == x.ControlPointType select y.Class).FirstOrDefault(),//控制等级 | |||
|  |                        x.AcceptanceSite, | |||
|  |                        IsOnceQualified = (x.IsOnceQualified == true ? "是" : "否"), | |||
|  |                        x.InspectionDate, | |||
|  |                        x.AttachUrl, | |||
|  |                        x.AttachUrl2, | |||
|  |                    }; | |||
|  |         } | |||
|  |         public static IEnumerable GetListDataForDataType(string controlPointType, string projectId, string UnitWorkId, string cNProfessionalId, string startDate, string endDate, int startRowIndex, int maximumRows) | |||
|  |         { | |||
|  |             IQueryable<Model.ProcessControl_InspectionManagement> q = from x in db.ProcessControl_InspectionManagement | |||
|  |                                                                       where x.ProjectId == projectId && x.FileType == null | |||
|  |                                                                       orderby x.InspectionDate descending | |||
|  |                                                                       select x; | |||
|  |             if (!string.IsNullOrEmpty(controlPointType)) | |||
|  |             { | |||
|  |                 string[] types = controlPointType.Split(','); | |||
|  |                 q = q.Where(e=> types.Contains(e.ControlPointType)); | |||
|  |             } | |||
|  |             if (UnitWorkId != "0") | |||
|  |             { | |||
|  |                 q = q.Where(e => e.UnitWorkId == UnitWorkId); | |||
|  |             } | |||
|  |             if (cNProfessionalId != "0") | |||
|  |             { | |||
|  |                 q = q.Where(e => e.CNProfessionalId == cNProfessionalId); | |||
|  |             } | |||
|  |             if (!string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate)) | |||
|  |             { | |||
|  |                 q = q.Where(e => e.InspectionDate >= Funs.GetNewDateTime(startDate) && e.InspectionDate <= Funs.GetNewDateTime(endDate)); | |||
|  |             } | |||
|  |             count = q.Count(); | |||
|  |             if (count == 0) | |||
|  |             { | |||
|  |                 return new object[] { "" }; | |||
|  |             } | |||
|  |             return from x in q.Skip(startRowIndex).Take(maximumRows) | |||
|  |                    select new | |||
|  |                    { | |||
|  |                        x.InspectionId, | |||
|  |                        x.ProjectId, | |||
|  |                        x.NoticeCode, | |||
|  |                        x.AcceptanceCheckMan, | |||
|  |                        UnitName = (from y in db.Base_Unit where y.UnitId == x.UnitId select y.UnitName).FirstOrDefault(), | |||
|  |                        ProfessionalName = (from y in db.Base_CNProfessional where y.CNProfessionalId == x.CNProfessionalId select y.ProfessionalName).FirstOrDefault(), | |||
|  |                        x.InspectionCode, | |||
|  |                        InstallationName = (from y in db.WBS_UnitWork where y.UnitWorkId == x.UnitWorkId select y.UnitWorkName).FirstOrDefault(), | |||
|  |                        Branch = (from y in db.WBS_DivisionProject where y.DivisionProjectId == x.Branch select y.DivisionName).FirstOrDefault(),//分部 | |||
|  |                        ControlPointType = (from y in db.WBS_BreakdownProject where y.BreakdownProjectId == x.ControlPointType select y.BreakdownName).FirstOrDefault(),//质量控制点 | |||
|  |                        Class = (from y in db.WBS_BreakdownProject where y.BreakdownProjectId == x.ControlPointType select y.Class).FirstOrDefault(),//控制等级 | |||
|  |                        x.AcceptanceSite, | |||
|  |                        IsOnceQualified = (x.IsOnceQualified == true ? "是" : "否"), | |||
|  |                        x.InspectionDate, | |||
|  |                        x.AttachUrl, | |||
|  |                        x.AttachUrl2, | |||
|  |                    }; | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 获取分页列表数 | |||
|  |         /// </summary> | |||
|  |         /// <param name="projectId"></param> | |||
|  |         /// <param name="UnitWorkId"></param> | |||
|  |         /// <param name="cNProfessionalId"></param> | |||
|  |         /// <param name="startDate"></param> | |||
|  |         /// <param name="endDate"></param> | |||
|  |         /// <returns></returns> | |||
|  |         public static int GetListCount(string projectId, string UnitWorkId, string cNProfessionalId, string startDate, string endDate) | |||
|  |         { | |||
|  |             return count; | |||
|  |         } | |||
|  |         public static int GetListCountForDataType(string controlPointType, string projectId, string UnitWorkId, string cNProfessionalId, string startDate, string endDate) | |||
|  |         { | |||
|  |             return count; | |||
|  |         } | |||
|  |         /// <summary> | |||
|  |         /// 获取分页列表 | |||
|  |         /// </summary> | |||
|  |         /// <param name="projectId"></param> | |||
|  |         /// <param name="name"></param> | |||
|  |         /// <param name="startDate"></param> | |||
|  |         /// <param name="endDate"></param> | |||
|  |         /// <param name="startRowIndex"></param> | |||
|  |         /// <param name="maximumRows"></param> | |||
|  |         /// <returns></returns> | |||
|  |         public static int GetListCount(string projectId, string name,   string startDate, string endDate) | |||
|  |         {  | |||
|  |             return count; | |||
|  |         } | |||
|  |         public static DataSet GetListData(string projectId, string name, string startDate, string endDate, int startRowIndex, int maximumRows) | |||
|  |         { | |||
|  | 
 | |||
|  |             string sql = @"SELECT AcceptanceCheckMan,COUNT(*) SunNumber,COUNT(IsOnceQualified) OneStatisticsSunNumber,COUNT(IsOnceQualified)*100/COUNT(*) as OneStatistics
 | |||
|  |                           FROM[dbo].[ProcessControl_InspectionManagement] | |||
|  |                           where InspectionDate is not null | |||
|  |                           ";
 | |||
|  |             if (!string.IsNullOrEmpty(projectId)) | |||
|  |             { | |||
|  |                 sql += " and ProjectId = '" + projectId + "'"; | |||
|  |             } | |||
|  |             if (!string.IsNullOrEmpty(startDate)) | |||
|  |             { | |||
|  |                 sql += " and InspectionDate >= '" + startDate + "'"; | |||
|  |             } | |||
|  |             if (!string.IsNullOrEmpty(name)) | |||
|  |             { | |||
|  |                 sql += " and AcceptanceCheckMan  like  '%" + name + "%'"; | |||
|  |             } | |||
|  |             if (!string.IsNullOrEmpty(endDate)) | |||
|  |             { | |||
|  |                 sql += " and InspectionDate <= '" + endDate + "'"; | |||
|  |             } | |||
|  | 
 | |||
|  |             sql += " group by AcceptanceCheckMan"; | |||
|  |             DataSet dataSet = SQLHelper.RunSqlString(sql, "dt"); | |||
|  |             if (dataSet != null && dataSet.Tables.Count > 0) | |||
|  |             { | |||
|  |                 count = dataSet.Tables[0].Rows.Count; | |||
|  | 
 | |||
|  |                 DataSet data = new DataSet(); | |||
|  |                 DataTable dataTable = new DataTable(); | |||
|  |                 foreach (var row in dataSet.Tables[0].Columns) | |||
|  |                 { | |||
|  |                     dataTable.Columns.Add(row.ToString()); | |||
|  |                 } | |||
|  |                 data.Tables.Add(dataTable); | |||
|  |                 for (int i = startRowIndex; i <= (startRowIndex + maximumRows)&&i<dataSet.Tables[0].Rows.Count; i++) | |||
|  |                 { | |||
|  |                     var row = dataTable.NewRow(); | |||
|  |                     row["AcceptanceCheckMan"] = dataSet.Tables[0].Rows[i]["AcceptanceCheckMan"]; | |||
|  |                     row["SunNumber"] = dataSet.Tables[0].Rows[i]["SunNumber"]; | |||
|  |                     row["OneStatisticsSunNumber"] = dataSet.Tables[0].Rows[i]["OneStatisticsSunNumber"]; | |||
|  |                     row["OneStatistics"] = dataSet.Tables[0].Rows[i]["OneStatistics"].ToString() +"%"; | |||
|  |                     dataTable.Rows.Add(row); | |||
|  |                 } | |||
|  |                 return data; | |||
|  |             } | |||
|  |             return null; | |||
|  |         } | |||
|  |         /// <summary> | |||
|  |         /// 根据逐渐获取检验批管理 | |||
|  |         /// </summary> | |||
|  |         /// <param name="inspectionId"></param> | |||
|  |         /// <returns></returns> | |||
|  |         public static Model.ProcessControl_InspectionManagement GetInspectionManagementById(string inspectionId) | |||
|  |         { | |||
|  |             return Funs.DB.ProcessControl_InspectionManagement.FirstOrDefault(e => e.InspectionId == inspectionId); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 添加检验批管理 | |||
|  |         /// </summary> | |||
|  |         /// <param name="inspectionManagement"></param> | |||
|  |         public static void AddInspectionManagement(Model.ProcessControl_InspectionManagement inspectionManagement) | |||
|  |         { | |||
|  |             Model.SUBQHSEDB db = Funs.DB; | |||
|  |             Model.ProcessControl_InspectionManagement newInspectionManagement = new Model.ProcessControl_InspectionManagement(); | |||
|  |             newInspectionManagement.InspectionId = inspectionManagement.InspectionId; | |||
|  |             newInspectionManagement.ProjectId = inspectionManagement.ProjectId; | |||
|  |             newInspectionManagement.UnitId = inspectionManagement.UnitId; | |||
|  |             newInspectionManagement.CNProfessionalId = inspectionManagement.CNProfessionalId; | |||
|  |             newInspectionManagement.InspectionCode = inspectionManagement.InspectionCode; | |||
|  |             newInspectionManagement.UnitWorkId = inspectionManagement.UnitWorkId; | |||
|  |             newInspectionManagement.Branch = inspectionManagement.Branch; | |||
|  |             newInspectionManagement.ControlPointType = inspectionManagement.ControlPointType; | |||
|  |             newInspectionManagement.AcceptanceSite = inspectionManagement.AcceptanceSite; | |||
|  |             newInspectionManagement.IsOnceQualified = inspectionManagement.IsOnceQualified; | |||
|  |             newInspectionManagement.InspectionDate = inspectionManagement.InspectionDate; | |||
|  |             newInspectionManagement.AttachUrl = inspectionManagement.AttachUrl; | |||
|  |             newInspectionManagement.AttachUrl2 = inspectionManagement.AttachUrl2; | |||
|  |             newInspectionManagement.NoticeCode = inspectionManagement.NoticeCode; | |||
|  |             newInspectionManagement.ParentDivisionProjectId = inspectionManagement.ParentDivisionProjectId; | |||
|  |             newInspectionManagement.CheckDate = inspectionManagement.CheckDate; | |||
|  |             newInspectionManagement.CheckMan = inspectionManagement.CheckMan; | |||
|  |             newInspectionManagement.CompileMan = inspectionManagement.CompileMan; | |||
|  |             newInspectionManagement.CompileMan2 = inspectionManagement.CompileMan2; | |||
|  |             newInspectionManagement.CompileDate = inspectionManagement.CompileDate; | |||
|  |             newInspectionManagement.UnqualifiedReason = inspectionManagement.UnqualifiedReason; | |||
|  |             newInspectionManagement.AcceptanceCheckMan = inspectionManagement.AcceptanceCheckMan; | |||
|  |             newInspectionManagement.FileType = inspectionManagement.FileType; | |||
|  |             newInspectionManagement.CCUnitIds = inspectionManagement.CCUnitIds; | |||
|  |             newInspectionManagement.MainSendUnitId = inspectionManagement.MainSendUnitId; | |||
|  |             newInspectionManagement.AuditMan = inspectionManagement.AuditMan; | |||
|  |             newInspectionManagement.Status = inspectionManagement.Status; | |||
|  |             newInspectionManagement.PlanComplateDate = inspectionManagement.PlanComplateDate; | |||
|  |             newInspectionManagement.RePlanComplateDate = inspectionManagement.RePlanComplateDate; | |||
|  | 
 | |||
|  | 
 | |||
|  |             db.ProcessControl_InspectionManagement.InsertOnSubmit(newInspectionManagement); | |||
|  |             db.SubmitChanges(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 修改检验批管理 | |||
|  |         /// </summary> | |||
|  |         /// <param name="inspectionManagement"></param> | |||
|  |         public static void UpdateInspectionManagement(Model.ProcessControl_InspectionManagement inspectionManagement) | |||
|  |         { | |||
|  |             Model.SUBQHSEDB db = Funs.DB; | |||
|  |             Model.ProcessControl_InspectionManagement newInspectionManagement = db.ProcessControl_InspectionManagement.FirstOrDefault(e => e.InspectionId == inspectionManagement.InspectionId); | |||
|  |             if (newInspectionManagement != null) | |||
|  |             { | |||
|  |                 newInspectionManagement.ProjectId = inspectionManagement.ProjectId; | |||
|  |                 newInspectionManagement.UnitId = inspectionManagement.UnitId; | |||
|  |                 newInspectionManagement.CNProfessionalId = inspectionManagement.CNProfessionalId; | |||
|  |                 newInspectionManagement.InspectionCode = inspectionManagement.InspectionCode; | |||
|  |                 newInspectionManagement.UnitWorkId = inspectionManagement.UnitWorkId; | |||
|  |                 newInspectionManagement.Branch = inspectionManagement.Branch; | |||
|  |                 newInspectionManagement.ControlPointType = inspectionManagement.ControlPointType; | |||
|  |                 newInspectionManagement.AcceptanceSite = inspectionManagement.AcceptanceSite; | |||
|  |                 newInspectionManagement.IsOnceQualified = inspectionManagement.IsOnceQualified; | |||
|  |                 newInspectionManagement.InspectionDate = inspectionManagement.InspectionDate; | |||
|  |                 newInspectionManagement.AttachUrl = inspectionManagement.AttachUrl; | |||
|  |                 newInspectionManagement.AttachUrl2 = inspectionManagement.AttachUrl2; | |||
|  |                 newInspectionManagement.NoticeCode = inspectionManagement.NoticeCode; | |||
|  |                 newInspectionManagement.ParentDivisionProjectId = inspectionManagement.ParentDivisionProjectId; | |||
|  |                 newInspectionManagement.UnqualifiedReason = inspectionManagement.UnqualifiedReason; | |||
|  |                 newInspectionManagement.AcceptanceCheckMan = inspectionManagement.AcceptanceCheckMan; | |||
|  |                 newInspectionManagement.CompileMan2 = inspectionManagement.CompileMan2; | |||
|  | 
 | |||
|  |                 newInspectionManagement.CCUnitIds = inspectionManagement.CCUnitIds; | |||
|  |                 newInspectionManagement.MainSendUnitId = inspectionManagement.MainSendUnitId; | |||
|  |                 newInspectionManagement.AuditMan = inspectionManagement.AuditMan; | |||
|  |                 newInspectionManagement.Status = inspectionManagement.Status; | |||
|  |                 newInspectionManagement.PlanComplateDate = inspectionManagement.PlanComplateDate; | |||
|  |                 newInspectionManagement.RePlanComplateDate = inspectionManagement.RePlanComplateDate; | |||
|  | 
 | |||
|  |                 db.SubmitChanges(); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 根据主键删除检验批管理 | |||
|  |         /// </summary> | |||
|  |         /// <param name="inspectionId"></param> | |||
|  |         public static void DeleteInspectionManagement(string inspectionId) | |||
|  |         { | |||
|  |             Model.SUBQHSEDB db = Funs.DB; | |||
|  |             Model.ProcessControl_InspectionManagement inspectionManagement = db.ProcessControl_InspectionManagement.FirstOrDefault(e => e.InspectionId == inspectionId); | |||
|  |             if (inspectionManagement != null) | |||
|  |             { | |||
|  |                 if (!string.IsNullOrEmpty(inspectionManagement.AttachUrl)) | |||
|  |                 { | |||
|  |                     BLL.UploadAttachmentService.DeleteFile(Funs.RootPath, inspectionManagement.AttachUrl);//删除附件 | |||
|  |                 } | |||
|  |                 if (!string.IsNullOrEmpty(inspectionManagement.AttachUrl2)) | |||
|  |                 { | |||
|  |                     BLL.UploadAttachmentService.DeleteFile(Funs.RootPath, inspectionManagement.AttachUrl2);//删除附件 | |||
|  |                 } | |||
|  |                 db.ProcessControl_InspectionManagement.DeleteOnSubmit(inspectionManagement); | |||
|  |                 db.SubmitChanges(); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         public static List<Model.View_CQMS_InspectionManagementDetail> getInspectionManagementDetailListByCNProfessionalIdAndDate(string projectId, string cNProfessionalId, DateTime startDate, DateTime SoptDate, bool isOnceQualified) | |||
|  |         { | |||
|  |             List<Model.View_CQMS_InspectionManagementDetail> InspectionMangementList = (from x in Funs.DB.View_CQMS_InspectionManagementDetail where x.ProjectId == projectId select x).ToList(); | |||
|  |             if (!string.IsNullOrEmpty(cNProfessionalId) && cNProfessionalId != "0") | |||
|  |             { | |||
|  |                 InspectionMangementList = (from x in InspectionMangementList where x.CNProfessionalId == cNProfessionalId select x).ToList(); | |||
|  |             } | |||
|  |             if (isOnceQualified == true) | |||
|  |             { | |||
|  |                 InspectionMangementList = (from x in InspectionMangementList where x.IsOnceQualified == isOnceQualified select x).ToList(); | |||
|  |             } | |||
|  |             if (startDate != null && SoptDate != null) | |||
|  |             { | |||
|  |                 InspectionMangementList = (from x in InspectionMangementList where x.InspectionDate >= startDate && x.InspectionDate <= SoptDate select x).ToList(); | |||
|  |             } | |||
|  | 
 | |||
|  |             return InspectionMangementList; | |||
|  |         } | |||
|  |         public static List<Model.View_CQMS_InspectionManagementDetail> getInspectionManagementDetailListByUnitIdAndDate(string projectId, string unitId, DateTime startDate, DateTime SoptDate, bool isOnceQualified) | |||
|  |         { | |||
|  |             List<Model.View_CQMS_InspectionManagementDetail> InspectionMangementList = (from x in Funs.DB.View_CQMS_InspectionManagementDetail where x.ProjectId == projectId select x).ToList(); | |||
|  |             if (!string.IsNullOrEmpty(unitId) && unitId != "0") | |||
|  |             { | |||
|  |                 InspectionMangementList = (from x in InspectionMangementList where x.UnitId == unitId select x).ToList(); | |||
|  |             } | |||
|  |             if (isOnceQualified == true) | |||
|  |             { | |||
|  |                 InspectionMangementList = (from x in InspectionMangementList where x.IsOnceQualified == isOnceQualified select x).ToList(); | |||
|  |             } | |||
|  |             if (startDate != null && SoptDate != null) | |||
|  |             { | |||
|  |                 InspectionMangementList = (from x in InspectionMangementList where x.InspectionDate >= startDate && x.InspectionDate <= SoptDate select x).ToList(); | |||
|  |             } | |||
|  | 
 | |||
|  |             return InspectionMangementList; | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 根据主键获取视图信息 | |||
|  |         /// </summary> | |||
|  |         /// <param name="inspectionManagementId"></param> | |||
|  |         /// <returns></returns> | |||
|  |         public static Model.View_InspectionManagement GetViewInspectionManagementById(string inspectionManagementId) | |||
|  |         { | |||
|  |             return Funs.DB.View_InspectionManagement.FirstOrDefault(e => e.InspectionId == inspectionManagementId); | |||
|  |         } | |||
|  |     } | |||
|  | } |