Example #1
0
        /// <summary>
        /// 导入数据
        /// </summary>
        /// <param name="impdto"></param>
        /// <returns></returns>
        public bool ImportData(List <ExcelImportDataDTO> impdtolst)
        {
            bool blResult = false;

            using (var tcdms = new Entities.TCDMS_UserApplyEntities())
            {
                foreach (var p in impdtolst)
                {
                    if (p is ExcelBatch) // 判断是否为用户信息
                    {
                        #region 用户申请批次表导入
                        ExcelBatch exrdt = p as ExcelBatch;

                        UserApply_ApplyBatch userbatch = new UserApply_ApplyBatch();
                        userbatch.BatchID        = exrdt.BatchID.Value;
                        userbatch.BatchName      = exrdt.BatchName;
                        userbatch.ApplyUserEamil = exrdt.ApplyUserEamil;
                        userbatch.ApplyUserPhone = exrdt.ApplyUserPhone;
                        userbatch.Status         = Convert.ToInt16(exrdt.Status);
                        userbatch.ApplyUser      = exrdt.ApplyUser;
                        userbatch.CreateTime     = DateTime.Now;
                        userbatch.CreateUser     = p.Importer;
                        userbatch.AuditStatus    = exrdt.AuditStatus;
                        userbatch.ApplyTime      = DateTime.Now;
                        tcdms.UserApply_ApplyBatch.Add(userbatch);
                        #endregion
                        #region 用户申请表导入
                        foreach (var q in exrdt.ExcelUserApply)
                        {
                            UserApply_UserApplyInfo Userappinfo = new UserApply_UserApplyInfo();
                            Userappinfo.UserApplyName      = q.UserApplyName;
                            Userappinfo.BatchID            = exrdt.BatchID;
                            Userappinfo.UserApplyTelNumber = q.UserPhone;
                            Userappinfo.UserApplyEmail     = q.UserEmail;
                            Userappinfo.UserApplyType      = Convert.ToInt16(q.UserApplyType);
                            Userappinfo.AuditRoleIDList    = q.Userroleidstr;
                            Userappinfo.CreateUser         = p.Importer;
                            Userappinfo.CreateTime         = DateTime.Now;
                            Userappinfo.AuditStatus        = q.AuditStatus;
                            Userappinfo.DistributorIDList  = q.DistriButorIDStr;
                            tcdms.UserApply_UserApplyInfo.Add(Userappinfo);

                            foreach (var i in q.userapplyAut)
                            {
                                UserApply_UserApplyAuthority userappluauthority = new UserApply_UserApplyAuthority();
                                userappluauthority.UserApply_UserApplyInfo = Userappinfo;
                                userappluauthority.StructureID             = i.StructureID;
                                userappluauthority.AppyUserButtonAuthority = i.ButtonAuthority;

                                tcdms.UserApply_UserApplyAuthority.Add(userappluauthority);
                            }
                        }
                        #endregion
                    }
                }
                blResult = tcdms.SaveChanges() > 0;
            }

            return(blResult);
        }
Example #2
0
        /// <summary>
        /// 保存批次及用户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public bool AddApplyUser(BatchApplyOperateDTO dto)
        {
            bool blResult = false;

            using (var tcdmse = new Entities.TCDMS_UserApplyEntities())
            {
                UserApply_ApplyBatch batch = null;
                var pp = tcdmse.UserApply_ApplyBatch.Where(p => p.BatchID == dto.BatchID).FirstOrDefault();
                if (pp == null)
                {
                    batch = new UserApply_ApplyBatch();
                    Mapper.Map <BatchApplyOperateDTO, UserApply_ApplyBatch>(dto, batch);
                    tcdmse.UserApply_ApplyBatch.Add(batch);
                }
                else
                {
                    pp.AuditStatus = dto.AuditStatus;
                    var qq = tcdmse.UserApply_UserApplyInfo.Where(q => q.BatchID == pp.BatchID);
                    foreach (var q in qq)
                    {
                        tcdmse.UserApply_UserApplyAuthority.RemoveRange(q.UserApply_UserApplyAuthority);
                    }
                    tcdmse.UserApply_UserApplyInfo.RemoveRange(qq);
                    batch = pp;
                }

                foreach (var e in dto.BatchApplyUser)
                {
                    UserApply_UserApplyInfo userapply = new UserApply_UserApplyInfo();

                    Mapper.Map <UserApplyOperateDTO, UserApply_UserApplyInfo>(e, userapply);
                    string strRoleIdList = String.Empty;
                    // roleid 2-13为模块管理员
                    if (e.UserChangeID != null)
                    {
                        userapply.AuditRoleIDList = e.AuditRoleIDList;
                    }
                    else
                    {
                        var gg = ModelRoleDTO.ModelRolelist.Where(p => p.RoleID >= 2 && p.RoleID <= 13).ToList();
                        var mm = gg.Where(p => e.ApplyUserAuthority.Any(g => g.StructureID == p.ModelID)).Select(s => s.RoleID).Distinct().ToList();
                        mm.ForEach(u =>
                        {
                            strRoleIdList += "," + u.ToString();
                        });
                        userapply.AuditRoleIDList = strRoleIdList + ",";
                    }

                    if (batch != null)
                    {
                        userapply.UserApply_ApplyBatch = batch;
                    }
                    tcdmse.UserApply_UserApplyInfo.Add(userapply);
                    foreach (var i in e.ApplyUserAuthority)
                    {
                        UserApply_UserApplyAuthority userappluauthority = new UserApply_UserApplyAuthority();
                        userappluauthority.UserApply_UserApplyInfo = userapply;
                        userappluauthority.StructureID             = i.StructureID;
                        userappluauthority.AppyUserButtonAuthority = i.AppyUserButtonAuthority;
                        userappluauthority.IsAdopt = false;

                        tcdmse.UserApply_UserApplyAuthority.Add(userappluauthority);
                    }
                }

                blResult = tcdmse.SaveChanges() > 0;
            }

            return(blResult);
        }