Exemple #1
0
        /// <summary>
        /// 插入信息-单位信息 1
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="arr"></param>
        public static bool AddUnit(string projectId, JArray arr, Model.Sys_User user)
        {
            Model.SUBHSSEDB db   = Funs.DB;
            bool            isOk = true;

            try
            {
                foreach (var item in arr)
                {
                    string fromUnitId = item["ID"].ToString();
                    string departName = item["DepartName"].ToString(); ///单位名称
                    string departSir  = item["DepartSir"].ToString();  ///单位级别 0:非项目部 1:项目部级 2:项目部下级单位
                    ////单位类型
                    string unitTypeId  = null;
                    var    getUnitType = db.Base_UnitType.FirstOrDefault(x => x.UnitTypeName == item["DepartType"].ToString());
                    if (getUnitType != null)
                    {
                        unitTypeId = getUnitType.UnitTypeId;
                    }

                    if (!string.IsNullOrEmpty(fromUnitId) && !string.IsNullOrEmpty(departName) && departSir != "1")
                    {
                        if (!string.IsNullOrEmpty(projectId))
                        {
                            Model.Base_Unit newUnit = new Model.Base_Unit
                            {
                                FromUnitId  = fromUnitId,
                                UnitCode    = item["DepartCode"].ToString(),
                                UnitName    = departName,
                                UnitTypeId  = unitTypeId,
                                Corporate   = item["Charge"].ToString(),
                                Telephone   = item["Phone"].ToString(),
                                IsHide      = false,
                                DataSources = projectId,
                            };

                            var getUnit = db.Base_Unit.FirstOrDefault(x => x.FromUnitId == fromUnitId);
                            if (getUnit == null)
                            {
                                var getUnitByName = db.Base_Unit.FirstOrDefault(x => x.UnitName == departName);
                                if (getUnitByName != null)
                                {
                                    newUnit.UnitId           = getUnitByName.UnitId;
                                    getUnitByName.FromUnitId = fromUnitId;
                                    db.SubmitChanges();
                                }
                                else
                                {
                                    newUnit.UnitId = SQLHelper.GetNewID(typeof(Model.Base_Unit));
                                    UnitService.AddUnit(newUnit);
                                }
                            }
                            else
                            {
                                newUnit.UnitId = getUnit.UnitId;
                            }

                            var pUnit = db.Project_ProjectUnit.FirstOrDefault(x => x.ProjectId == projectId && x.UnitId == newUnit.UnitId);
                            if (pUnit == null)
                            {
                                Model.Project_ProjectUnit newProjectUnit = new Model.Project_ProjectUnit
                                {
                                    ProjectId = projectId,
                                    UnitId    = newUnit.UnitId,
                                    UnitType  = Const.ProjectUnitType_2,
                                };

                                ProjectUnitService.AddProjectUnit(newProjectUnit);
                                BLL.LogService.AddSys_Log(user, null, newProjectUnit.ProjectUnitId, BLL.Const.ProjectUnitMenuId, BLL.Const.BtnModify);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                isOk = false;
                ErrLogInfo.WriteLog(string.Empty, ex);
            }
            return(isOk);
        }
        /// <summary>
        /// 根据projectId、unitid获取特岗人员资质信息
        /// </summary>
        /// <param name="projectId">项目ID</param>
        /// <param name="unitId">单位ID</param>
        /// <param name="qualityType">资质类型</param>
        /// <param name="states">0-待提交;1-待审核;2-已审核;-1打回</param>
        /// <param name="unitIdQ">查询单位ID</param>
        /// <returns></returns>
        public static List <Model.PersonQualityItem> getPersonQualityList(string projectId, string unitId, string qualityType, string states, string unitIdQ)
        {
            List <Model.PersonQualityItem> getLists = new List <Model.PersonQualityItem>();

            if (qualityType == "1")
            {
                getLists = (from x in Funs.DB.SitePerson_Person
                            join z in Funs.DB.Base_WorkPost on x.WorkPostId equals z.WorkPostId
                            join y in Funs.DB.QualityAudit_PersonQuality on x.PersonId equals y.PersonId into jonPerson
                            from y in jonPerson.DefaultIfEmpty()
                            where x.ProjectId == projectId && z.PostType == Const.PostType_2 && x.IsUsed == true && (!x.OutTime.HasValue || x.OutTime > DateTime.Now)
                            orderby x.CardNo
                            select new Model.PersonQualityItem
                {
                    PersonQualityId = y.PersonQualityId,
                    QualityType = qualityType,
                    PersonId = x.PersonId,
                    PersonName = x.PersonName,
                    CardNo = x.CardNo,
                    IdentityCard = x.IdentityCard,
                    ProjectId = x.ProjectId,
                    UnitId = x.UnitId,
                    UnitName = Funs.DB.Base_Unit.First(z => z.UnitId == x.UnitId).UnitName,
                    CertificateId = y.CertificateId,
                    CertificateName = Funs.DB.Base_Certificate.First(z => z.CertificateId == y.CertificateId).CertificateName,
                    WorkPostId = x.WorkPostId,
                    WorkPostName = z.WorkPostName,
                    CertificateNo = y.CertificateNo,
                    Grade = y.Grade,
                    SendUnit = y.SendUnit,
                    SendDate = string.Format("{0:yyyy-MM-dd}", y.SendDate),
                    LimitDate = string.Format("{0:yyyy-MM-dd}", y.LimitDate),
                    LimitDateD = y.LimitDate,
                    LateCheckDate = string.Format("{0:yyyy-MM-dd}", y.LateCheckDate),
                    ApprovalPerson = y.ApprovalPerson,
                    Remark = y.Remark,
                    CompileMan = y.CompileMan,
                    CompileManName = Funs.DB.Sys_User.First(z => z.UserId == y.CompileMan).UserName,
                    CompileDate = string.Format("{0:yyyy-MM-dd}", y.CompileDate),
                    AuditDate = string.Format("{0:yyyy-MM-dd}", y.AuditDate),
                    AuditorName = Funs.DB.Sys_User.First(z => z.UserId == y.AuditorId).UserName,
                    AuditOpinion = y.AuditOpinion,
                    States = y.States,
                    AttachUrl = APIUpLoadFileService.getFileUrl(y.PersonQualityId, null),
                }).ToList();
            }
            else if (qualityType == "2")
            {
                getLists = (from x in Funs.DB.SitePerson_Person
                            join z in Funs.DB.Base_WorkPost on x.WorkPostId equals z.WorkPostId
                            join y in Funs.DB.QualityAudit_SafePersonQuality on x.PersonId equals y.PersonId into jonPerson
                            from y in jonPerson.DefaultIfEmpty()
                            where x.ProjectId == projectId && z.IsHsse == true && x.IsUsed == true && (!x.OutTime.HasValue || x.OutTime > DateTime.Now)
                            orderby y.LimitDate
                            select new Model.PersonQualityItem
                {
                    PersonQualityId = y.SafePersonQualityId,
                    QualityType = qualityType,
                    PersonId = x.PersonId,
                    PersonName = x.PersonName,
                    CardNo = x.CardNo,
                    IdentityCard = x.IdentityCard,
                    ProjectId = x.ProjectId,
                    UnitId = x.UnitId,
                    UnitName = Funs.DB.Base_Unit.First(z => z.UnitId == x.UnitId).UnitName,
                    //CertificateId = y.CertificateId,
                    CertificateName = y.CertificateName,
                    WorkPostId = x.WorkPostId,
                    WorkPostName = z.WorkPostName,
                    CertificateNo = y.CertificateNo,
                    Grade = y.Grade,
                    SendUnit = y.SendUnit,
                    SendDate = string.Format("{0:yyyy-MM-dd}", y.SendDate),
                    LimitDate = string.Format("{0:yyyy-MM-dd}", y.LimitDate),
                    LimitDateD = y.LimitDate,
                    LateCheckDate = string.Format("{0:yyyy-MM-dd}", y.LateCheckDate),
                    ApprovalPerson = y.ApprovalPerson,
                    Remark = y.Remark,
                    CompileMan = y.CompileMan,
                    CompileManName = Funs.DB.Sys_User.First(z => z.UserId == y.CompileMan).UserName,
                    CompileDate = string.Format("{0:yyyy-MM-dd}", y.CompileDate),
                    AuditDate = string.Format("{0:yyyy-MM-dd}", y.AuditDate),
                    AuditorName = Funs.DB.Sys_User.First(z => z.UserId == y.AuditorId).UserName,
                    AuditOpinion = y.AuditOpinion,
                    States = y.States,
                    AttachUrl = APIUpLoadFileService.getFileUrl(y.SafePersonQualityId, null),
                }).ToList();
            }
            else if (qualityType == "3")
            {
                getLists = (from x in Funs.DB.SitePerson_Person
                            join z in Funs.DB.Base_WorkPost on x.WorkPostId equals z.WorkPostId
                            join y in Funs.DB.QualityAudit_EquipmentPersonQuality on x.PersonId equals y.PersonId into jonPerson
                            from y in jonPerson.DefaultIfEmpty()
                            where x.ProjectId == projectId && z.PostType == Const.PostType_5 && x.IsUsed == true && (!x.OutTime.HasValue || x.OutTime > DateTime.Now)
                            orderby y.LimitDate
                            select new Model.PersonQualityItem
                {
                    PersonQualityId = y.EquipmentPersonQualityId,
                    QualityType = qualityType,
                    PersonId = x.PersonId,
                    PersonName = x.PersonName,
                    CardNo = x.CardNo,
                    IdentityCard = x.IdentityCard,
                    ProjectId = x.ProjectId,
                    UnitId = x.UnitId,
                    UnitName = Funs.DB.Base_Unit.First(z => z.UnitId == x.UnitId).UnitName,
                    CertificateId = y.CertificateId,
                    CertificateName = Funs.DB.Base_Certificate.First(z => z.CertificateId == y.CertificateId).CertificateName,
                    WorkPostId = x.WorkPostId,
                    WorkPostName = z.WorkPostName,
                    CertificateNo = y.CertificateNo,
                    Grade = y.Grade,
                    SendUnit = y.SendUnit,
                    SendDate = string.Format("{0:yyyy-MM-dd}", y.SendDate),
                    LimitDate = string.Format("{0:yyyy-MM-dd}", y.LimitDate),
                    LimitDateD = y.LimitDate,
                    LateCheckDate = string.Format("{0:yyyy-MM-dd}", y.LateCheckDate),
                    ApprovalPerson = y.ApprovalPerson,
                    Remark = y.Remark,
                    CompileMan = y.CompileMan,
                    CompileManName = Funs.DB.Sys_User.First(z => z.UserId == y.CompileMan).UserName,
                    CompileDate = string.Format("{0:yyyy-MM-dd}", y.CompileDate),
                    AuditDate = string.Format("{0:yyyy-MM-dd}", y.AuditDate),
                    AuditorName = Funs.DB.Sys_User.First(z => z.UserId == y.AuditorId).UserName,
                    AuditOpinion = y.AuditOpinion,
                    States = y.States,
                    AttachUrl = APIUpLoadFileService.getFileUrl(y.EquipmentPersonQualityId, null),
                }).ToList();
            }

            if (ProjectUnitService.GetProjectUnitTypeByProjectIdUnitId(projectId, unitId))
            {
                getLists = getLists.Where(x => x.UnitId == unitId).ToList();
            }
            if (!string.IsNullOrEmpty(unitIdQ))
            {
                getLists = getLists.Where(x => x.UnitId == unitIdQ).ToList();
            }
            if (states == Const.State_0)
            {
                getLists = getLists.Where(x => x.States == null || x.States == states || x.PersonQualityId == null || x.LimitDateD < DateTime.Now.AddMonths(1)).ToList();
            }
            else if (states == Const.State_1)
            {
                getLists = getLists.Where(x => x.States == states).ToList();
            }
            else if (states == Const.State_2)
            {
                getLists = getLists.Where(x => x.States == states && x.LimitDateD >= DateTime.Now.AddMonths(1)).ToList();
            }
            else if (states == Const.State_R)
            {
                getLists = getLists.Where(x => x.States == states).ToList();
            }
            return(getLists);
        }