ZHJA_HJGL/HJGL_ZH/BLL/Common/BaseInfo/Base_ProjectService.cs

581 lines
24 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace BLL
{
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Data.Linq;
using System.Web.Security;
using System.Web.UI.WebControls;
using Model;
using BLL;
using System.Collections;
public static class Base_ProjectService
{
public static Model.SGGLDB db = Funs.DB;
/// <summary>
///获取项目信息
/// </summary>
/// <returns></returns>
public static Model.Base_Project GetProjectByProjectId(string projectId)
{
return Funs.DB.Base_Project.FirstOrDefault(e => e.ProjectId == projectId);
}
/// <summary>
///获取项目信息
/// </summary>
/// <returns></returns>
public static List<Model.Base_Project> GetProjectByTestStandardId(string testStandardId)
{
return (from x in Funs.DB.Base_Project where x.TestStandardId == testStandardId select x).ToList();
}
/// <summary>
///获取项目编号
/// </summary>
/// <returns></returns>
public static string GetProjectCode(string projectId)
{
Model.Base_Project project = Funs.DB.Base_Project.FirstOrDefault(e => e.ProjectId == projectId);
if (project == null)
{
return "";
}
else
{
return project.ProjectCode;
}
}
/// <summary>
///获取项目简称
/// </summary>
/// <returns></returns>
public static string GetProjectName(string projectId)
{
Model.Base_Project project = Funs.DB.Base_Project.FirstOrDefault(e => e.ProjectId == projectId);
if (project == null)
{
return "";
}
else
{
return project.ShortName;
}
}
/// <summary>
/// 判断施工号是否存在
/// </summary>
/// <param name="projectId">项目ID</param>
/// <param name="projectCode">施工号</param>
/// <returns></returns>
public static bool IsExistProjectCode(string projectId, string projectCode, string projectSoft)
{
bool isExitCode = false;
var q = from x in Funs.DB.Base_Project where x.ProjectSoft==projectSoft && x.ProjectCode == projectCode && x.ProjectId != projectId select x;
if (q.Count() > 0)
{
isExitCode = true;
}
return isExitCode;
}
/// <summary>
/// 增加项目信息
/// </summary>
/// <returns></returns>
public static void AddProject(Model.Base_Project project)
{
Model.SGGLDB db = Funs.DB;
Model.Base_Project newProject = new Base_Project();
newProject.ProjectId = project.ProjectId;
newProject.ProjectCode = project.ProjectCode;
newProject.ProjectName = project.ProjectName;
newProject.ShortName = project.ShortName;
newProject.StartDate = project.StartDate;
newProject.EndDate = project.EndDate;
newProject.ProjectPrincipal = project.ProjectPrincipal;
newProject.TechnicalPrincipal = project.TechnicalPrincipal;
newProject.SecurePrincipal = project.SecurePrincipal;
newProject.ProjectManager = project.ProjectManager;
newProject.Remark = project.Remark;
newProject.IsClosed = project.IsClosed;
newProject.TestEngineeringCode = project.TestEngineeringCode;
newProject.CreateManId = project.CreateManId;
newProject.ProjectSoft = project.ProjectSoft;
newProject.CheckUnitId = project.CheckUnitId;
newProject.WatchUnit = project.WatchUnit;
newProject.TestStandardId = project.TestStandardId;
newProject.EquipmentName = project.EquipmentName;
newProject.TagNum = project.TagNum;
newProject.ProductNum = project.ProductNum;
newProject.BodyMaterial = project.BodyMaterial;
db.Base_Project.InsertOnSubmit(newProject);
db.SubmitChanges();
}
///修改项目信息
/// </summary>
/// <param name="project"></param>
public static void UpdateProject(Model.Base_Project project)
{
Model.SGGLDB db = Funs.DB;
Model.Base_Project newProject = db.Base_Project.First(e => e.ProjectId == project.ProjectId);
newProject.ProjectCode = project.ProjectCode;
newProject.ProjectName = project.ProjectName;
newProject.ShortName = project.ShortName;
newProject.StartDate = project.StartDate;
newProject.EndDate = project.EndDate;
newProject.ProjectPrincipal = project.ProjectPrincipal;
newProject.TechnicalPrincipal = project.TechnicalPrincipal;
newProject.SecurePrincipal = project.SecurePrincipal;
newProject.ProjectManager = project.ProjectManager;
newProject.Remark = project.Remark;
newProject.IsClosed = project.IsClosed;
newProject.TestEngineeringCode = project.TestEngineeringCode;
newProject.CreateManId = project.CreateManId;
newProject.ProjectSoft = project.ProjectSoft;
newProject.CheckUnitId = project.CheckUnitId;
newProject.WatchUnit = project.WatchUnit;
newProject.TestStandardId = project.TestStandardId;
newProject.EquipmentName = project.EquipmentName;
newProject.TagNum = project.TagNum;
newProject.ProductNum = project.ProductNum;
newProject.BodyMaterial = project.BodyMaterial;
db.SubmitChanges();
}
/// <summary>
/// 根据项目Id删除一个项目信息
/// </summary>
/// <param name="projectId"></param>
public static void DeleteProject(string projectId)
{
Model.SGGLDB db = Funs.DB;
Model.Base_Project project = db.Base_Project.FirstOrDefault(e => e.ProjectId == projectId);
if (project != null)
{
var bt = from x in db.Project_RoleButtonPower where x.ProjectId == projectId select x;
if (bt.Count() > 0)
{
db.Project_RoleButtonPower.DeleteAllOnSubmit(bt);
}
var rolePower = from x in db.Project_RolePower where x.ProjectId == projectId select x;
if (rolePower.Count() > 0)
{
db.Project_RolePower.DeleteAllOnSubmit(rolePower);
}
var report = from x in db.Common_ReportServer where x.ProjectId == projectId select x;
if (report.Count() > 0)
{
db.Common_ReportServer.DeleteAllOnSubmit(report);
}
var set = from x in db.Project_Sys_Set where x.ProjectId == projectId select x;
if (set.Count() > 0)
{
db.Project_Sys_Set.DeleteAllOnSubmit(set);
}
var punit = from x in db.Project_Unit where x.ProjectId == projectId select x;
if (punit.Count() > 0)
{
db.Project_Unit.DeleteAllOnSubmit(punit);
}
var puser = from x in db.Project_User where x.ProjectId == projectId select x;
if (puser.Count() > 0)
{
db.Project_User.DeleteAllOnSubmit(puser);
}
db.SubmitChanges();
}
db.Base_Project.DeleteOnSubmit(project);
db.SubmitChanges();
}
/// <summary>
/// 根据用户Id获取项目集合
/// </summary>
/// <param name="userId">用户ID</param>
/// <param name="projectSoft">1-管道安装2-压力容器</param>
/// <returns></returns>
public static List<Model.Base_Project> GetProjectListByUserId(string userId, string projectSoft)
{
if (userId == BLL.Const.GlyId) //管理员
{
var q = (from x in Funs.DB.Base_Project
where x.ProjectSoft == projectSoft
orderby x.ProjectCode descending
select x).ToList();
return q;
}
else
{
var q = (from x in Funs.DB.Base_Project
join y in Funs.DB.Project_User
on x.ProjectId equals y.ProjectId
where y.UserId == userId && x.ProjectSoft == projectSoft
select x).Distinct().ToList();
return q.OrderByDescending(x => x.ProjectCode).ToList();
}
}
/// <summary>
/// 根据用户Id获取项目集合
/// </summary>
/// <param name="userId">用户ID</param>
/// <param name="projectSoft">1-管道安装2-压力容器</param>
/// <returns></returns>
public static List<YlrqProject> GetYlrqProjectListByUserId(string userId, string projectSoft)
{
if (userId == BLL.Const.GlyId) //管理员
{
var q = (from x in Funs.DB.Base_Project
where x.ProjectSoft == projectSoft
orderby x.ProjectCode descending
select new YlrqProject
{
ProjectId = x.ProjectId,
ProjectName = x.ProjectName,
ShortName = x.ShortName,
StartDate = x.StartDate,
EndDate = x.EndDate,
ProjectCode = x.ProjectCode,
EquipmentName = x.EquipmentName,
ProductNum = x.ProductNum,
ProjectSoft = x.ProjectSoft,
ProjectTextField = $"施工号:({x.ProjectCode}),设备名称:({x.EquipmentName}),产品编号:({x.ProductNum})"
}).ToList();
return q.OrderByDescending(x => x.ProjectCode).ToList();
}
else
{
var q = (from x in Funs.DB.Base_Project
join y in Funs.DB.Project_User
on x.ProjectId equals y.ProjectId
where y.UserId == userId && x.ProjectSoft == projectSoft
select new YlrqProject
{
ProjectId = x.ProjectId,
ProjectName = x.ProjectName,
ShortName = x.ShortName,
StartDate = x.StartDate,
EndDate = x.EndDate,
ProjectCode = x.ProjectCode,
EquipmentName = x.EquipmentName,
ProductNum = x.ProductNum,
ProjectSoft = x.ProjectSoft,
ProjectTextField = $"施工号:({x.ProjectCode}),设备名称:({x.EquipmentName}),产品编号:({x.ProductNum})"
}).Distinct().ToList();
return q.OrderByDescending(x => x.ProjectCode).ToList();
}
}
public class YlrqProject : Base_Project
{
public string ProjectTextField { get; set; }
}
/// <summary>
/// 获取用户所有项目字符串
/// </summary>
/// <param name="userId"></param>
/// <param name="projectSoft"></param>
/// <returns></returns>
public static string GetStrProjectIds(string userId, string projectSoft)
{
List<Model.Base_Project> projects = BLL.Base_ProjectService.GetProjectListByUserId(userId, projectSoft);
string projectIds = string.Empty;
foreach (var project in projects)
{
projectIds += project.ProjectId + ",";
}
return projectIds;
}
/// <summary>
/// 获取用户所有在建项目字符串
/// </summary>
/// <param name="userId"></param>
/// <param name="projectSoft"></param>
/// <returns></returns>
public static string GetStrOnProjectIds(string userId, string projectSoft)
{
List<Model.Base_Project> projects = BLL.Base_ProjectService.GetOnProjectListByUserId(userId, projectSoft);
string projectIds = string.Empty;
foreach (var project in projects)
{
projectIds += project.ProjectId + ",";
}
return projectIds;
}
public static List<Model.Base_Project> GetOnProjectListByUserId(string userId)
{
if (userId == BLL.Const.GlyId) //管理员
{
var q = (from x in Funs.DB.Base_Project
where x.IsClosed == false
orderby x.ProjectCode descending
select x).ToList();
return q;
}
else
{
var q = (from x in Funs.DB.Base_Project
join y in Funs.DB.Project_User
on x.ProjectId equals y.ProjectId
where y.UserId == userId && x.IsClosed == false
select x).Distinct().ToList();
return q.OrderByDescending(x => x.ProjectCode).ToList();
}
}
/// <summary>
/// 根据用户Id获取参与在建项目的集合
/// </summary>
/// <param name="userId">用户ID</param>
/// <param name="projectSoft">1-管道安装2-压力容器</param>
/// <returns></returns>
public static List<Model.Base_Project> GetOnProjectListByUserId(string userId, string projectSoft)
{
if (userId == BLL.Const.GlyId) //管理员
{
var q = (from x in Funs.DB.Base_Project
where x.IsClosed == false && x.ProjectSoft == projectSoft
orderby x.ProjectCode descending
select x).ToList();
return q;
}
else
{
var q = (from x in Funs.DB.Base_Project
join y in Funs.DB.Project_User
on x.ProjectId equals y.ProjectId
where y.UserId == userId && x.IsClosed == false && x.ProjectSoft == projectSoft
select x).Distinct().ToList();
return q.OrderByDescending(x => x.ProjectCode).ToList();
}
}
public static List<BaseProject> GetOnProjectListByUser(string userId, string projectSoft)
{
if (userId == BLL.Const.GlyId) //管理员
{
var q = (from x in Funs.DB.Base_Project
where x.IsClosed == false && x.ProjectSoft == projectSoft
orderby x.ProjectCode descending
select new BaseProject { ProjectId = x.ProjectId, ProjectCode = x.ProjectCode, ProjectName = x.ProjectName }).ToList();
return q;
}
else
{
var q = (from x in Funs.DB.Base_Project
join y in Funs.DB.Project_User
on x.ProjectId equals y.ProjectId
where y.UserId == userId && x.IsClosed == false && x.ProjectSoft == projectSoft
select new BaseProject { ProjectId = x.ProjectId, ProjectCode = x.ProjectCode, ProjectName = x.ProjectName }).Distinct().ToList();
return q;
}
}
/// <summary>
/// 获取RT的检测记录项目
/// </summary>
/// <param name="userId"></param>
/// <param name="projectSoft"></param>
/// <returns></returns>
public static List<BaseProjectOutput> GetOnProjectListByRT(string userId, string projectSoft)
{
if (userId == BLL.Const.GlyId) //管理员
{
var q = (from x in Funs.DB.Base_Project
where x.IsClosed == false && x.ProjectSoft == projectSoft
orderby x.ProjectCode descending
select new BaseProjectOutput {
ProjectName = x.ProjectName,
ProjectCode = x.ProjectCode,
ProjectId = x.ProjectId,
isExists = (from a in Funs.DB.HJGL_CH_Trust join b in Funs.DB.HJGL_CH_TrustItem on a.CH_TrustID equals b.CH_TrustID
where a.ProjectId == x.ProjectId && b.Record_PrintDate==null
&& a.CH_NDTMethod == "20d2cbca-8b3d-434b-b1c1-181796986fa5"
select new {a.ProjectId}
).Count()
}
).ToList();
return q;
}
else
{
var q = (from x in Funs.DB.Base_Project
join y in Funs.DB.Project_User
on x.ProjectId equals y.ProjectId
where y.UserId == userId && x.IsClosed == false && x.ProjectSoft == projectSoft
select new BaseProjectOutput
{
ProjectName = x.ProjectName,
ProjectCode = x.ProjectCode,
ProjectId = x.ProjectId,
isExists = (from a in Funs.DB.HJGL_CH_Trust
join b in Funs.DB.HJGL_CH_TrustItem on a.CH_TrustID equals b.CH_TrustID
where a.ProjectId == x.ProjectId && b.Record_PrintDate == null
&& a.CH_NDTMethod == "20d2cbca-8b3d-434b-b1c1-181796986fa5"
select new { a.ProjectId }
).Count()
}
).Distinct().ToList();
return q.OrderByDescending(x => x.ProjectCode).ToList();
}
}
/// <summary>
/// 获取非RT的检测记录项目
/// </summary>
/// <param name="userId"></param>
/// <param name="projectSoft"></param>
/// <returns></returns>
public static List<BaseProjectOutput> GetOnProjectListByNoRT(string userId, string projectSoft)
{
if (userId == BLL.Const.GlyId) //管理员
{
var q = (from x in Funs.DB.Base_Project
where x.IsClosed == false && x.ProjectSoft == projectSoft
orderby x.ProjectCode descending
select new BaseProjectOutput
{
ProjectName = x.ProjectName,
ProjectCode = x.ProjectCode,
ProjectId = x.ProjectId,
isExists = (from a in Funs.DB.HJGL_CH_Trust
join b in Funs.DB.HJGL_CH_TrustItem on a.CH_TrustID equals b.CH_TrustID
where a.ProjectId == x.ProjectId && b.Record_PrintDate == null
&& a.CH_NDTMethod != "20d2cbca-8b3d-434b-b1c1-181796986fa5"
select new { a.ProjectId }
).Count()
}
).ToList();
return q;
}
else
{
var q = (from x in Funs.DB.Base_Project
join y in Funs.DB.Project_User
on x.ProjectId equals y.ProjectId
where y.UserId == userId && x.IsClosed == false && x.ProjectSoft == projectSoft
select new BaseProjectOutput
{
ProjectName = x.ProjectName,
ProjectCode = x.ProjectCode,
ProjectId = x.ProjectId,
isExists = (from a in Funs.DB.HJGL_CH_Trust
join b in Funs.DB.HJGL_CH_TrustItem on a.CH_TrustID equals b.CH_TrustID
where a.ProjectId == x.ProjectId && b.Record_PrintDate == null
&& a.CH_NDTMethod != "20d2cbca-8b3d-434b-b1c1-181796986fa5"
select new { a.ProjectId }
).Count()
}
).Distinct().ToList();
return q.OrderByDescending(x => x.ProjectCode).ToList();
}
}
/// <summary>
/// 根据用户Id、项目状态、类型获取参与项目集合
/// </summary>
/// <param name="userId">用户ID</param>
/// <param name="state">项目状态</param>
/// <param name="projectSoft">类型1-管道安装2-压力容器</param>
/// <returns></returns>
public static List<Model.Base_Project> GetProjectListByUserIdAndState(string userId, string state, string projectSoft)
{
if (state == BLL.Const._Null)
{
if (userId == BLL.Const.GlyId) //管理员
{
var q = (from x in Funs.DB.Base_Project
where x.ProjectSoft == projectSoft
orderby x.ProjectCode descending
select x).ToList();
return q;
}
else
{
var q = (from x in Funs.DB.Base_Project
join y in Funs.DB.Project_User
on x.ProjectId equals y.ProjectId
where y.UserId == userId && x.ProjectSoft == projectSoft
select x).Distinct().ToList();
return q.OrderByDescending(x => x.ProjectCode).ToList();
}
}
else if (state == BLL.Const._True)
{
if (userId == BLL.Const.GlyId) //管理员
{
var q = (from x in Funs.DB.Base_Project
where x.IsClosed == true && x.ProjectSoft == projectSoft
orderby x.ProjectCode descending
select x).ToList();
return q;
}
else
{
var q = (from x in Funs.DB.Base_Project
join y in Funs.DB.Project_User
on x.ProjectId equals y.ProjectId
where y.UserId == userId && x.IsClosed == true && x.ProjectSoft == projectSoft
select x).Distinct().ToList();
return q.OrderByDescending(x => x.ProjectCode).ToList();
}
}
else
{
if (userId == BLL.Const.GlyId) //管理员
{
var q = (from x in Funs.DB.Base_Project
where x.IsClosed == false && x.ProjectSoft == projectSoft
orderby x.ProjectCode descending
select x).ToList();
return q;
}
else
{
var q = (from x in Funs.DB.Base_Project
join y in Funs.DB.Project_User
on x.ProjectId equals y.ProjectId
where y.UserId == userId && x.IsClosed == false && x.ProjectSoft == projectSoft
select x).Distinct().ToList();
return q.OrderByDescending(x => x.ProjectCode).ToList();
}
}
}
}
public class BaseProjectOutput:Model.Base_Project
{
public int isExists { get; set; }
}
public class BaseProject
{
public string ProjectId { get; set; }
public string ProjectCode { get; set; }
public string ProjectName { get; set; }
}
}