private void SaveBackupPersonInfo(List <Personnel> Perlst)
        {
            PersonnelInfoBackupList backUpList = new PersonnelInfoBackupList();

            backUpList.PerList = new List <PersonnelInfoBackup>();
            foreach (var item in Perlst)
            {
                PersonnelInfoBackup Per = new PersonnelInfoBackup();
                if (item.Abutment_Id != null)
                {
                    Per.Abutment_Id = (int)item.Abutment_Id;
                }
                else
                {
                    Per.Abutment_Id = -1;
                }

                Per.Name           = item.Name;
                Per.Sex            = item.Sex;
                Per.Phone          = item.Photo;
                Per.BirthDay       = item.BirthDay;
                Per.BirthTimeStamp = item.BirthTimeStamp;
                Per.Nation         = item.Nation;
                Per.Address        = item.Address;


                if (item.WorkNumber != null)
                {
                    Per.WorkNumber = item.WorkNumber;
                }
                else
                {
                    Per.WorkNumber = null;
                }

                Per.Email   = item.Email;
                Per.Phone   = item.Phone;
                Per.Mobile  = item.Mobile;
                Per.Enabled = item.Enabled;

                if (item.ParentId != null)
                {
                    Per.ParentId = (int)item.ParentId;
                }
                else
                {
                    Per.ParentId = -1;
                }

                Per.Pst = item.Pst;

                backUpList.PerList.Add(Per);
            }

            string initFile = InitPaths.GetBackupPersonnelInfo();

            XmlSerializeHelper.Save(backUpList, initFile, Encoding.UTF8);
        }
Esempio n. 2
0
        public void InitDepartments()
        {
            Log.InfoStart(LogTags.DbInit, "InitDepartments");

            bool r1 = LocationCardToPersonnels.Clear();
            bool r2 = LocationCardPositions.Clear();
            bool r3 = Personnels.Clear();
            bool r4 = Departments.Clear();

            Log.Info(LogTags.DbInit, "导入部门信息");
            string filePath = InitPaths.GetBackupDepartmentsInfo();
            bool   value    = DepartmentsBackupHelper.ImportDepartmentInfoFromFile(filePath, _bll);

            Log.Info(LogTags.DbInit, string.Format("导入部门信息结果:{0}", value));

            //Department dep0 = new Department() { Name = "根节点", ShowOrder = 0, Parent = null, Type = DepartType.本厂 };
            //Departments.Add(dep0);
            //Department dep11 = new Department() { Name = "四会电厂", ShowOrder = 0, Parent = dep0, Type = DepartType.本厂 };
            //Departments.Add(dep11);
            //Department dep12 = new Department() { Name = "维修部门", ShowOrder = 0, Parent = dep11, Type = DepartType.本厂 };
            //Departments.Add(dep12);//单个添加可以只是设置Parent
            //Department dep13 = new Department() { Name = "发电部门", ShowOrder = 1, ParentId = dep11.Id, Type = DepartType.本厂 };//批量添加必须设置ParentId
            //Department dep14 = new Department() { Name = "外委人员", ShowOrder = 2, ParentId = dep11.Id, Type = DepartType.本厂 };
            //Department dep15 = new Department() { Name = "访客", ShowOrder = 0, ParentId = dep11.Id, Type = DepartType.本厂 };
            //Department dep16 = new Department() { Name = "未绑定", ShowOrder = 0, ParentId = null, Type = DepartType.本厂 };


            // List<Department> subDeps = new List<Department>() { dep12,dep13, dep14,dep15,dep16};
            // List<Department> subDeps2 = new List<Department>() { dep13, dep14, dep15 };
            // Departments.AddRange(subDeps2);
            //Departments.Add(dep16);

            Posts.Clear();
            Post post1 = new Post()
            {
                Name = "前台"
            };
            Post post2 = new Post()
            {
                Name = "电工"
            };
            Post post3 = new Post()
            {
                Name = "维修工"
            };
            Post post4 = new Post()
            {
                Name = "保安"
            };
            Post post5 = new Post()
            {
                Name = "经理"
            };
            Post post6 = new Post()
            {
                Name = "电工"
            };
            Post post7 = new Post()
            {
                Name = "访客"
            };
            Post post8 = new Post()
            {
                Name = "检修"
            };
            var posts = new List <Post>()
            {
                post1, post2, post3, post4, post5, post6, post7, post8
            };

            Posts.AddRange(posts);
            List <LocationCard> tagsT = LocationCards.ToList();
            RandomTool          rt    = new RandomTool();


            Log.Info(LogTags.DbInit, "导入人员信息");
            var basePath = AppDomain.CurrentDomain.BaseDirectory;

            filePath = InitPaths.GetBackupPersonnelInfo();
            value    = PersonBackupHelper.ImportPersonInfoFromFile(filePath, _bll);
            Log.Info(LogTags.DbInit, string.Format("导入人员信息结果:{0}", value));

            List <Personnel> pList = Personnels.ToList();


            Log.Info(LogTags.DbInit, "开始  导入人员和定位卡关联关系");
            //人员和定位卡关联关系
            filePath = InitPaths.GetPersonAndCard();
            LocationCardToPersonnelsBackupHelper.ImportRelationFromFile(new FileInfo(filePath));
            Log.Info(LogTags.DbInit, "结束 导入人员和定位卡关联关系");
            List <LocationCardToPersonnel> rList = LocationCardToPersonnels.ToList();

            List <LocationCard> tagsTemp = new List <LocationCard>();

            foreach (LocationCardToPersonnel ctp in rList)
            {
                LocationCard card = tagsT.Find((item) => item.Id == ctp.LocationCardId);
                if (card != null)
                {
                    card.IsActive = true;
                    tagsTemp.Add(card);
                }
            }
            LocationCards.EditRange(tagsTemp);
        }