Exemple #1
0
        /// <summary>
        /// 插入信息-项目信息
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="arr"></param>
        public static string AddProject(JArray arr)
        {
            Model.SUBHSSEDB db        = Funs.DB;
            string          projectId = string.Empty;

            try
            {
                foreach (var item in arr)
                {
                    string fromUnitId = item["ID"].ToString();
                    string departName = item["DepartName"].ToString(); ///单位名称
                    string departSir  = item["DepartSir"].ToString();  ///单位级别 0:非项目部 1:项目部级 2:项目部下级单位
                    if (!string.IsNullOrEmpty(fromUnitId) && !string.IsNullOrEmpty(departName) && departSir == "1")
                    {
                        var getProjectByFromProjectId = db.Base_Project.FirstOrDefault(x => x.FromProjectId == fromUnitId);
                        if (getProjectByFromProjectId == null)
                        {
                            string projectCode = item["ProjectCode"].ToString();
                            var    getProjectByFromProjectName = db.Base_Project.FirstOrDefault(x => x.ProjectCode == projectCode);
                            if (getProjectByFromProjectName != null)
                            {
                                projectId = getProjectByFromProjectName.ProjectId;
                                getProjectByFromProjectName.FromProjectId = fromUnitId;
                                ProjectService.UpdateProject(getProjectByFromProjectName);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrLogInfo.WriteLog(string.Empty, ex);
            }
            return(projectId);
        }
Exemple #2
0
        /// <summary>
        /// 输入文本转换数字类型
        /// </summary>
        /// <returns></returns>
        public static int GetNewIntOrZero(string value)
        {
            int revalue = 0;

            if (!String.IsNullOrEmpty(value))
            {
                try
                {
                    revalue = Int32.Parse(value);
                }
                catch (Exception ex)
                {
                    ErrLogInfo.WriteLog(string.Empty, ex);
                }
            }

            return(revalue);
        }
Exemple #3
0
        /// <summary>
        /// 输入文本转换数字类型
        /// </summary>
        /// <returns></returns>
        public static decimal?GetNewDecimal(string value)
        {
            decimal?revalue = null;

            if (!String.IsNullOrEmpty(value))
            {
                try
                {
                    revalue = decimal.Parse(value);
                }
                catch (Exception ex)
                {
                    ErrLogInfo.WriteLog(string.Empty, ex);
                }
            }

            return(revalue);
        }
Exemple #4
0
        /// <summary>
        /// 判断一个字符串是否是整数
        /// </summary>
        /// <param name="integerStr">要检查的字符串</param>
        /// <returns>返回是或否</returns>
        public static bool IsInteger(string integerStr)
        {
            if (String.IsNullOrEmpty(integerStr))
            {
                return(false);
            }

            try
            {
                Convert.ToInt32(integerStr, NumberFormatInfo.InvariantInfo);
                return(true);
            }
            catch (Exception ex)
            {
                ErrLogInfo.WriteLog(string.Empty, ex);
                return(false);
            }
        }
Exemple #5
0
        /// <summary>
        /// 字符串是否为浮点数
        /// </summary>
        /// <param name="decimalStr">要检查的字符串</param>
        /// <returns>返回是或否</returns>
        public static bool IsDecimal(string decimalStr)
        {
            if (String.IsNullOrEmpty(decimalStr))
            {
                return(false);
            }

            try
            {
                Convert.ToDecimal(decimalStr, NumberFormatInfo.InvariantInfo);
                return(true);
            }
            catch (Exception ex)
            {
                ErrLogInfo.WriteLog(string.Empty, ex);
                return(false);
            }
        }
Exemple #6
0
 /// <summary>
 /// 输入文本转换时间类型(空时:默认当前时间)
 /// </summary>
 /// <returns></returns>
 public static DateTime GetNewDateTimeOrNow(string time)
 {
     try
     {
         if (!String.IsNullOrEmpty(time))
         {
             return(DateTime.Parse(time));
         }
         else
         {
             return(System.DateTime.Now);
         }
     }
     catch (Exception ex)
     {
         ErrLogInfo.WriteLog(string.Empty, ex);
         return(System.DateTime.Now);
     }
 }
Exemple #7
0
 /// <summary>
 /// 输入文本转换数字类型
 /// </summary>
 /// <returns></returns>
 public static int?GetNewInt(string value)
 {
     if (!String.IsNullOrEmpty(value))
     {
         try
         {
             return(Int32.Parse(value));
         }
         catch (Exception ex)
         {
             ErrLogInfo.WriteLog(string.Empty, ex);
             return(null);
         }
     }
     else
     {
         return(null);
     }
 }
Exemple #8
0
        /// <summary>
        ///  流程确认 定时执行 定时00:05 执行
        /// </summary>
        /// <param name="sender">Timer组件</param>
        /// <param name="e">事件参数</param>
        private static void ColligateFormConfirmProcessEve(object sender, ElapsedEventArgs e)
        {
            try
            {
                if (messageTimerEve != null)
                {
                    messageTimerEve.Stop();
                }

                DoSynchData();
            }
            catch (Exception ex)
            {
                ErrLogInfo.WriteLog("定时器启动异常。", ex);
            }
            finally
            {
                messageTimerEve.Interval = GetMessageTimerEveNextInterval();
                messageTimerEve.Start();
            }
        }
Exemple #9
0
 /// <summary>
 ///
 /// </summary>
 public static void SubmitChanges()
 {
     try
     {
         DB.SubmitChanges(ConflictMode.ContinueOnConflict);
     }
     catch (ChangeConflictException ex)
     {
         foreach (ObjectChangeConflict occ in DB.ChangeConflicts)
         {
             //以下是解决冲突的三种方法,选一种即可
             //// 使用当前数据库中的值,覆盖Linq缓存中实体对象的值
             //occ.Resolve(RefreshMode.OverwriteCurrentValues);
             //// 使用Linq缓存中实体对象的值,覆盖当前数据库中的值
             //occ.Resolve(RefreshMode.KeepCurrentValues);
             // 只更新实体对象中改变的字段的值,其他的保留不变
             occ.Resolve(RefreshMode.KeepChanges);
         }
         // 这个地方要注意,Catch方法中,我们前面只是指明了怎样来解决冲突,这个地方还需要再次提交更新,这样的话,值    //才会提交到数据库。
         DB.SubmitChanges();
         ErrLogInfo.WriteLog(string.Empty, ex);
     }
 }
Exemple #10
0
 /// <summary>
 /// 创建菜单信息XML方法
 /// </summary>
 /// <param name="fileName"></param>
 public static void CreateMenuDataXML(string menuType, List <Model.SpSysMenuItem> menusList, string superMenu, XmlTextWriter writer)
 {
     try
     {
         if (superMenu == "0")
         {
             ///xml文件路径名
             string     fileName   = Funs.RootPath + "common\\" + menuType + ".xml";
             FileStream fileStream = new FileStream(fileName, FileMode.Create);
             writer = new XmlTextWriter(fileStream, Encoding.UTF8)
             {
                 //使用自动缩进便于阅读
                 Formatting = Formatting.Indented
             };
             writer.WriteStartDocument();
             writer.WriteStartElement("Tree");                                                            //创建父节点
             var menuItemList = menusList.Where(x => x.SuperMenu == superMenu).OrderBy(x => x.SortIndex); //获取菜单列表
             if (menuItemList.Count() > 0)
             {
                 foreach (var item in menuItemList)
                 {
                     writer.WriteStartElement("TreeNode");                                         //创建子节点
                     writer.WriteAttributeString("id", item.MenuId);                               //添加属性
                     string name = item.MenuName;
                     if (CommonService.GetIsThisUnit(Const.UnitId_CWCEC) && name.Contains("HSSE")) //五环
                     {
                         name = name.Replace("HSSE", "HSE");
                     }
                     else
                     {
                         if (!name.Contains("月总结"))
                         {
                             name = name.Replace("HSSE", "安全");
                         }
                     }
                     writer.WriteAttributeString("Text", name);
                     writer.WriteAttributeString("NavigateUrl", item.Url);
                     if (!string.IsNullOrEmpty(item.Icon))
                     {
                         writer.WriteAttributeString("Icon", item.Icon);
                     }
                     else
                     {
                         writer.WriteAttributeString("Icon", "LayoutContent");
                     }
                     if (!item.IsEnd.HasValue || item.IsEnd == false)
                     {
                         CreateMenuDataXML(menuType, menusList, item.MenuId, writer);
                     }
                     writer.WriteFullEndElement();    //子节点结束
                     //在节点间添加一些空格
                     writer.WriteWhitespace("\n");
                 }
             }
             writer.WriteFullEndElement();    //父节点结束
             writer.Close();
             fileStream.Close();
         }
         else
         {
             var subMenuItemList = menusList.Where(x => x.SuperMenu == superMenu).OrderBy(x => x.SortIndex);    //获取菜单集合
             if (subMenuItemList.Count() > 0)
             {
                 foreach (var item in subMenuItemList)
                 {
                     //使用自动缩进便于阅读
                     writer.Formatting = Formatting.Indented;
                     writer.WriteStartElement("TreeNode");           //创建子节点
                     writer.WriteAttributeString("id", item.MenuId); //添加属性
                     string name = item.MenuName;
                     if (CommonService.GetIsThisUnit(Const.UnitId_CWCEC) && name.Contains("HSSE"))
                     {
                         name = name.Replace("HSSE", "HSE");
                     }
                     else
                     {
                         if (!name.Contains("月总结"))
                         {
                             name = name.Replace("HSSE", "安全");
                         }
                     }
                     //if (BLL.SafetyDataService.GetSafetyDataByMenuId(item.MenuId) != null)
                     //{
                     //    writer.WriteAttributeString("Text", name + "*");
                     //}
                     //else
                     //{
                     writer.WriteAttributeString("Text", name);
                     //}
                     writer.WriteAttributeString("NavigateUrl", item.Url);
                     if (!string.IsNullOrEmpty(item.Icon))
                     {
                         writer.WriteAttributeString("Icon", item.Icon);
                     }
                     else
                     {
                         writer.WriteAttributeString("Icon", "LayoutContent");
                     }
                     if (!item.IsEnd.HasValue || item.IsEnd == false)
                     {
                         CreateMenuDataXML(menuType, menusList, item.MenuId, writer);
                     }
                     writer.WriteFullEndElement();    //子节点结束
                     //在节点间添加一些空格
                     writer.WriteWhitespace("\n");
                 }
             }
         }
     }
     catch (Exception ex)
     {
         ErrLogInfo.WriteLog(string.Empty, ex);
     }
 }
Exemple #11
0
        /// <summary>
        /// 插入人员培训记录 5
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="arr"></param>
        public static bool AddPersonTrainRecord(string projectId, JArray arr, Model.Sys_User user)
        {
            Model.SUBHSSEDB db   = Funs.DB;
            bool            isOk = true;

            try
            {
                foreach (var item in arr)
                {
                    string id = item["ID"].ToString();
                    if (!string.IsNullOrEmpty(id))
                    {
                        bool isPass = false;
                        if (item["IsPass"].ToString() == "1")
                        {
                            isPass = true;
                        }

                        Model.EduTrain_TrainPersonRecord newTrainPersonRecord = new Model.EduTrain_TrainPersonRecord
                        {
                            ID             = id,
                            ProjectId      = projectId,
                            EmpName        = item["EmpName"].ToString(),
                            IdentifyId     = item["IdentifyId"].ToString(),
                            CategoryName   = item["CategoryName"].ToString(),
                            RecordId       = item["RecordId"].ToString(),
                            DepartId       = item["DepartId"].ToString(),
                            DepartName     = item["DepartName"].ToString(),
                            TrainPeriod    = item["TrainPeriod"].ToString(),
                            TotalScore     = item["TotalScore"].ToString(),
                            PassScore      = item["PassScore"].ToString(),
                            Score          = item["Score"].ToString(),
                            IsPass         = isPass,
                            GroupNo        = item["GroupNo"].ToString(),
                            ExamNo         = item["ExamNo"].ToString(),
                            ExamCount      = item["ExamCount"].ToString(),
                            DeviceNo       = item["DeviceNo"].ToString(),
                            OwnerDepartId  = item["OwnerDepartId"].ToString(),
                            Answers        = item["Answers"].ToString(),
                            RecordName     = item["RecordName"].ToString(),
                            TrainType      = item["TrainType"].ToString(),
                            PaperMode      = item["PaperMode"].ToString(),
                            TrainMode      = item["TrainMode"].ToString(),
                            TrainPrincipal = item["TrainPrincipal"].ToString(),
                            TrainStartDate = Funs.GetNewDateTime(item["TrainStartDate"].ToString()),
                            TrainEndDate   = Funs.GetNewDateTime(item["TrainEndDate"].ToString()),
                            TrainContent   = item["TrainContent"].ToString(),
                            TrainDescript  = item["TrainDescript"].ToString(),
                        };

                        var getnewTrainPersonRecord = db.EduTrain_TrainPersonRecord.FirstOrDefault(x => x.ID == id);
                        if (getnewTrainPersonRecord == null)
                        {
                            db.EduTrain_TrainPersonRecord.InsertOnSubmit(newTrainPersonRecord);
                            db.SubmitChanges();
                        }
                        else
                        {
                            db.SubmitChanges();
                        }
                    }
                    else
                    {
                        isOk = false;
                    }
                }
            }
            catch (Exception ex)
            {
                isOk = false;
                ErrLogInfo.WriteLog(string.Empty, ex);
            }
            return(isOk);
        }
Exemple #12
0
        /// <summary>
        /// 插入试卷 4
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="arr"></param>
        public static bool AddEduTrain_TrainTest(string projectId, JArray arr, Model.Sys_User user)
        {
            Model.SUBHSSEDB db   = Funs.DB;
            bool            isOk = true;

            try
            {
                foreach (var item in arr)
                {
                    string trainingId     = null; ////培训记录ID
                    var    getTrainRecord = db.EduTrain_TrainRecord.FirstOrDefault(x => x.FromRecordId == item["RecordId"].ToString());
                    if (getTrainRecord != null)
                    {
                        trainingId = getTrainRecord.TrainingId;
                    }

                    string trainTestId = item["ID"].ToString();
                    if (!string.IsNullOrEmpty(trainingId) && !string.IsNullOrEmpty(trainTestId))
                    {
                        Model.EduTrain_TrainTest newTrainTest = new Model.EduTrain_TrainTest
                        {
                            TrainTestId  = trainTestId,
                            TrainingId   = trainingId,
                            ExamNo       = item["ExamNo"].ToString(),
                            GroupNo      = item["GroupNo"].ToString(),
                            CourseID     = item["CourseID"].ToString(),
                            COrder       = Funs.GetNewInt(item["COrder"].ToString()),
                            QsnCode      = item["QsnCode"].ToString(),
                            QsnId        = item["QsnId"].ToString(),
                            QsnContent   = item["QsnContent"].ToString(),
                            QsnFileName  = item["QsnFileName"].ToString(),
                            QsnAnswer    = item["QsnAnswer"].ToString(),
                            QsnCategory  = item["QsnCategory"].ToString(),
                            QsnKind      = item["QsnKind"].ToString(),
                            Description  = item["Description"].ToString(),
                            QsnImportant = item["QsnImportant"].ToString(),
                            Analysis     = item["Analysis"].ToString(),
                            UploadTime   = Funs.GetNewDateTime(item["UploadTime"].ToString()),
                        };

                        var getTrainRecordDetail = db.EduTrain_TrainTest.FirstOrDefault(x => x.TrainTestId == trainTestId);
                        if (getTrainRecordDetail == null)
                        {
                            EduTrain_TrainTestService.AddTrainTest(newTrainTest);
                        }
                        else
                        {
                            newTrainTest.ExamNo       = newTrainTest.ExamNo;
                            newTrainTest.GroupNo      = newTrainTest.GroupNo;
                            newTrainTest.CourseID     = newTrainTest.CourseID;
                            newTrainTest.COrder       = newTrainTest.COrder;
                            newTrainTest.QsnCode      = newTrainTest.QsnCode;
                            newTrainTest.QsnId        = newTrainTest.QsnId;
                            newTrainTest.QsnContent   = newTrainTest.QsnContent;
                            newTrainTest.QsnFileName  = newTrainTest.QsnFileName;
                            newTrainTest.QsnAnswer    = newTrainTest.QsnAnswer;
                            newTrainTest.QsnCategory  = newTrainTest.QsnCategory;
                            newTrainTest.QsnKind      = newTrainTest.QsnKind;
                            newTrainTest.Description  = newTrainTest.Description;
                            newTrainTest.QsnImportant = newTrainTest.QsnImportant;
                            newTrainTest.Analysis     = newTrainTest.Analysis;
                            newTrainTest.UploadTime   = newTrainTest.UploadTime;
                            db.SubmitChanges();
                        }
                    }
                    else
                    {
                        isOk = false;
                    }
                }
            }
            catch (Exception ex)
            {
                isOk = false;
                ErrLogInfo.WriteLog(string.Empty, ex);
            }
            return(isOk);
        }
Exemple #13
0
        /// <summary>
        /// 插入培训人员 3
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="arr"></param>
        public static bool AddTrainRecordPerson(string projectId, JArray arr, Model.Sys_User user)
        {
            Model.SUBHSSEDB db   = Funs.DB;
            bool            isOk = true;

            try
            {
                foreach (var item in arr)
                {
                    string trainingId     = null; ////培训记录ID
                    var    getTrainRecord = db.EduTrain_TrainRecord.FirstOrDefault(x => x.FromRecordId == item["RecordId"].ToString());
                    if (getTrainRecord != null)
                    {
                        trainingId = getTrainRecord.TrainingId;
                    }

                    string personId  = null; ///人员信息ID
                    var    getPerson = db.SitePerson_Person.FirstOrDefault(x => x.IdentityCard == item["IdentifyId"].ToString());
                    if (getPerson != null)
                    {
                        personId = getPerson.PersonId;
                    }
                    bool checkResult = false;
                    if (item["IsPass"].ToString() == "1")
                    {
                        checkResult = true;
                    }
                    if (!string.IsNullOrEmpty(trainingId) && !string.IsNullOrEmpty(personId))
                    {
                        Model.EduTrain_TrainRecordDetail newTrainRecordDetail = new Model.EduTrain_TrainRecordDetail
                        {
                            TrainingId  = trainingId,
                            PersonId    = personId,
                            CheckScore  = Funs.GetNewDecimal(item["Score"].ToString()),
                            CheckResult = checkResult,
                        };

                        var getTrainRecordDetail = db.EduTrain_TrainRecordDetail.FirstOrDefault(x => x.TrainingId == trainingId && x.PersonId == personId);
                        if (getTrainRecordDetail == null)
                        {
                            EduTrain_TrainRecordDetailService.AddTrainDetail(newTrainRecordDetail);
                        }
                        else
                        {
                            getTrainRecordDetail.CheckScore  = newTrainRecordDetail.CheckScore;
                            getTrainRecordDetail.CheckResult = newTrainRecordDetail.CheckResult;
                            EduTrain_TrainRecordDetailService.UpdateTrainDetail(getTrainRecordDetail);
                        }
                    }
                    else
                    {
                        isOk = false;
                    }
                }
            }
            catch (Exception ex)
            {
                isOk = false;
                ErrLogInfo.WriteLog(string.Empty, ex);
            }
            return(isOk);
        }
Exemple #14
0
        /// <summary>
        /// 插入培训记录 2
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="arr"></param>
        public static bool AddTrainRecord(string projectId, JArray arr, Model.Sys_User user)
        {
            Model.SUBHSSEDB db   = Funs.DB;
            bool            isOk = true;

            try
            {
                foreach (var item in arr)
                {
                    string fromRecordId = item["ID"].ToString();
                    string trainTypeId  = null; ////培训类型
                    var    getTrainType = db.Base_TrainType.FirstOrDefault(x => x.TrainTypeName == item["TrainType"].ToString());
                    if (getTrainType != null)
                    {
                        trainTypeId = getTrainType.TrainTypeId;
                    }
                    string unitId = null;
                    if (!string.IsNullOrEmpty(item["TrainDepart"].ToString()))
                    {
                        var lists = Funs.GetStrListByStr(item["TrainDepart"].ToString(), ',');
                        if (lists.Count() > 0)
                        {
                            foreach (var itemList in lists)
                            {
                                var getUnit = db.Base_Unit.FirstOrDefault(x => x.UnitName == itemList);
                                if (getUnit != null)
                                {
                                    if (string.IsNullOrEmpty(unitId))
                                    {
                                        unitId = getUnit.UnitId;
                                    }
                                    else
                                    {
                                        unitId += ("," + getUnit.UnitId);
                                    }
                                }
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(unitId) && !string.IsNullOrEmpty(fromRecordId))
                    {
                        Model.EduTrain_TrainRecord newTrainRecord = new Model.EduTrain_TrainRecord
                        {
                            FromRecordId = fromRecordId,

                            ProjectId      = projectId,
                            TrainTitle     = item["RecordName"].ToString(),
                            TrainContent   = item["TrainContent"].ToString(),
                            TrainStartDate = Funs.GetNewDateTime(item["TrainStartDate"].ToString()),
                            TrainEndDate   = Funs.GetNewDateTime(item["TrainEndDate"].ToString()),
                            TeachHour      = Funs.GetNewDecimalOrZero(item["TrainPeriod"].ToString()),
                            TeachMan       = item["TrainPrincipal"].ToString(),
                            Remark         = item["TrainDescript"].ToString(),
                            TrainTypeId    = trainTypeId,
                            UnitIds        = unitId,
                            States         = Const.State_0,
                            CompileMan     = item["CreateUser"].ToString(),
                            TrainPersonNum = Funs.GetNewInt(item["PersonCount"].ToString()),
                        };

                        newTrainRecord.TrainingCode = Funs.GetNewFileName(newTrainRecord.TrainStartDate);
                        var getTrainRecord = Funs.DB.EduTrain_TrainRecord.FirstOrDefault(x => x.FromRecordId == fromRecordId);
                        if (getTrainRecord == null)
                        {
                            newTrainRecord.TrainingId = SQLHelper.GetNewID(typeof(Model.EduTrain_TrainRecord));
                            EduTrain_TrainRecordService.AddTraining(newTrainRecord);
                            BLL.LogService.AddSys_Log(user, newTrainRecord.TrainingCode, newTrainRecord.TrainingId, BLL.Const.ProjectTrainRecordMenuId, BLL.Const.BtnAdd);
                        }
                        else
                        {
                            getTrainRecord.TrainingCode   = newTrainRecord.TrainingCode;
                            getTrainRecord.TrainTitle     = newTrainRecord.TrainTitle;
                            getTrainRecord.TrainContent   = newTrainRecord.TrainContent;
                            getTrainRecord.UnitIds        = newTrainRecord.UnitIds;
                            getTrainRecord.TrainStartDate = newTrainRecord.TrainStartDate;
                            if (newTrainRecord.TrainEndDate.HasValue)
                            {
                                getTrainRecord.TrainEndDate = newTrainRecord.TrainEndDate;
                            }
                            else
                            {
                                getTrainRecord.TrainEndDate = newTrainRecord.TrainStartDate;
                            }
                            getTrainRecord.TeachHour    = newTrainRecord.TeachHour;
                            getTrainRecord.TeachMan     = newTrainRecord.TeachMan;
                            getTrainRecord.TeachAddress = newTrainRecord.TeachAddress;

                            getTrainRecord.Remark = newTrainRecord.Remark;
                            EduTrain_TrainRecordService.UpdateTraining(getTrainRecord);
                            BLL.LogService.AddSys_Log(user, getTrainRecord.TrainingCode, getTrainRecord.TrainingId, BLL.Const.ProjectTrainRecordMenuId, BLL.Const.BtnModify);
                        }
                    }
                    else
                    {
                        isOk = false;
                    }
                }
            }
            catch (Exception ex)
            {
                isOk = false;
                ErrLogInfo.WriteLog(string.Empty, ex);
            }
            return(isOk);
        }
Exemple #15
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);
        }
Exemple #16
0
        /// <summary>
        /// 插入人员信息 0
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="arr"></param>
        public static bool AddPerson(string projectId, JArray arr, Model.Sys_User user)
        {
            Model.SUBHSSEDB db   = Funs.DB;
            bool            isOk = true;

            try
            {
                foreach (var item in arr)
                {
                    ////单位
                    string unitId  = null;
                    var    getUnit = db.Base_Unit.FirstOrDefault(x => x.FromUnitId == item["DepartId"].ToString());
                    if (getUnit != null)
                    {
                        unitId = getUnit.UnitId;
                    }

                    ///区域
                    string workAreaId  = null;
                    var    getWorkArea = db.ProjectData_WorkArea.FirstOrDefault(x => x.ProjectId == projectId && x.WorkAreaName == item["BuildArea"].ToString());
                    if (getWorkArea != null)
                    {
                        workAreaId = getWorkArea.WorkAreaId;
                    }
                    ///岗位
                    string workPostId  = null;
                    var    getWorkPost = db.Base_WorkPost.FirstOrDefault(x => x.WorkPostName == item["Station"].ToString());
                    if (getWorkPost != null)
                    {
                        workPostId = getWorkPost.WorkPostId;
                    }
                    DateTime?inTime  = Funs.GetNewDateTime(item["EntranceDate"].ToString());
                    DateTime?outTime = Funs.GetNewDateTime(item["LeaveDate"].ToString());
                    if (outTime < inTime)
                    {
                        outTime = null;
                    }
                    string IdentifyID = item["IdentifyID"].ToString();
                    if (!string.IsNullOrEmpty(IdentifyID))
                    {
                        Model.SitePerson_Person newPerson = new Model.SitePerson_Person
                        {
                            FromPersonId = item["ID"].ToString(),
                            CardNo       = item["JobNumber"].ToString(),
                            PersonName   = item["Name"].ToString(),
                            Sex          = item["Sex"].ToString(),
                            IdentityCard = IdentifyID,
                            Address      = item["Address"].ToString(),
                            ProjectId    = projectId,
                            UnitId       = unitId,   /////映射取值
                            //TeamGroupId = person.TeamGroupId,
                            WorkAreaId = workAreaId, /////关联映射取值
                            WorkPostId = workPostId, /////关联映射取值
                            InTime     = inTime,
                            OutTime    = outTime,
                            Telephone  = item["ContactTel"].ToString(),
                            IsUsed     = true,
                            IsCardUsed = true,
                        };

                        var getPerson = db.SitePerson_Person.FirstOrDefault(x => x.ProjectId == projectId && x.IdentityCard == IdentifyID);
                        if (getPerson == null)
                        {
                            newPerson.PersonId = SQLHelper.GetNewID(typeof(Model.SitePerson_Person));
                            PersonService.AddPerson(newPerson);
                            BLL.LogService.AddSys_Log(user, newPerson.PersonName, newPerson.PersonId, BLL.Const.PersonListMenuId, BLL.Const.BtnAdd);
                        }
                        else
                        {
                            getPerson.FromPersonId = newPerson.FromPersonId;
                            getPerson.InTime       = newPerson.InTime;
                            getPerson.OutTime      = newPerson.OutTime;
                            getPerson.Telephone    = newPerson.Telephone;
                            if (!string.IsNullOrEmpty(unitId))
                            {
                                getPerson.UnitId = unitId;
                            }
                            if (!string.IsNullOrEmpty(workAreaId))
                            {
                                getPerson.WorkAreaId = workAreaId;
                            }
                            if (!string.IsNullOrEmpty(workPostId))
                            {
                                getPerson.WorkPostId = workPostId;
                            }
                            PersonService.UpdatePerson(getPerson);
                            BLL.LogService.AddSys_Log(user, getPerson.PersonName, getPerson.PersonId, BLL.Const.PersonListMenuId, BLL.Const.BtnModify);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                isOk = false;
                ErrLogInfo.WriteLog(string.Empty, ex);
            }

            return(isOk);
        }