예제 #1
0
        /// <summary>
        /// InsertInfo
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public long InsertInfo(UserInfo info)
        {
            ///系统默认密码
            string defaultPassword = new ConfigBLL().GetValueByCode("USER_DEFAULT_PASSWORD");

            if (string.IsNullOrEmpty(defaultPassword))
            {
                defaultPassword = emptyDefaultPassword;
            }
            info.Password = SignatureHelper.GetSignature(defaultPassword);
            ///默认状态为未启用
            info.UserStatus = (int)UserStatusConstants.Disable;

            int cnt = dal.GetCounts("[LOGIN_NAME] = N'" + info.LoginName + "'");

            if (cnt > 0)
            {
                throw new Exception("MC:0x00000202");///用户名重复
            }
            return(dal.Add(info));
        }
예제 #2
0
        /// <summary>
        /// 执行导入EXCEL数据
        /// </summary>
        /// <param name="dataTable"></param>
        /// <param name="fieldNames"></param>
        /// <returns></returns>
        public bool ImportDataByExcel(DataTable dataTable, Dictionary <string, string> fieldNames, string loginUser)
        {
            List <UserInfo> userExcelInfos = CommonDAL.DatatableConvertToList <UserInfo>(dataTable).ToList();

            if (userExcelInfos.Count == 0)
            {
                throw new Exception("MC:1x00000043");///数据格式不符合导入规范
            }
            ///获取业务表中要变更的数据集合,准备对比
            List <UserInfo> userInfos = new UserDAL().GetList("[LOGIN_NAME] in ('" + string.Join("','", userExcelInfos.Select(d => d.LoginName).ToArray()) + "')", string.Empty);
            ///执行的SQL语句
            string sql = string.Empty;

            List <string> fields = new List <string>(fieldNames.Keys);

            ///逐条处理中间表数据
            foreach (var userExcelInfo in userExcelInfos)
            {
                if (userExcelInfo.LoginName.ToLower() == "admin")
                {
                    continue;
                }
                ///
                UserInfo userInfo = userInfos.FirstOrDefault(d => d.LoginName == userExcelInfo.LoginName);
                if (userInfo == null)
                {
                    ///物料号①、物料中文名称②为必填项
                    if (string.IsNullOrEmpty(userExcelInfo.LoginName) || string.IsNullOrEmpty(userExcelInfo.EmployeeName))
                    {
                        throw new Exception("MC:0x00000238");///用户名与用户姓名是必填项
                    }
                    ///字段
                    string insertFieldString = string.Empty;
                    ///值
                    string insertValueString = string.Empty;
                    for (int i = 0; i < fields.Count; i++)
                    {
                        string valueStr = CommonDAL.GetFieldValueForSql(userExcelInfo, fields[i]);
                        if (string.IsNullOrEmpty(valueStr))
                        {
                            throw new Exception("MC:1x00000043");///数据格式不符合导入规范
                        }
                        insertFieldString += "[" + fieldNames[fields[i]] + "],";
                        insertValueString += valueStr + ",";
                    }
                    ///默认密码
                    string defaultPassword = new ConfigBLL().GetValueByCode("USER_DEFAULT_PASSWORD");
                    if (string.IsNullOrEmpty(defaultPassword))
                    {
                        defaultPassword = emptyDefaultPassword;
                    }

                    sql += "if not exists (select * from dbo.TS_SYS_USER with(nolock) where [LOGIN_NAME] = N'" + userExcelInfo.LoginName + "' and [VALID_FLAG] = 1) "
                           + "insert into dbo.[TS_SYS_USER] ("
                           + "[FID],"
                           + insertFieldString
                           + "[PASSWORD],"
                           + "[USER_STATUS],"
                           + "[CREATE_USER],"
                           + "[CREATE_DATE],"
                           + "[VALID_FLAG]"
                           + ") values ("
                           + "NEWID(),"                                                  ///FID
                           + insertValueString
                           + "N'" + SignatureHelper.GetSignature(defaultPassword) + "'," ///PASSWORD
                           + "" + (int)UserStatusConstants.Disable + ","                 ///USER_STATUS
                           + "N'" + loginUser + "',"                                     ///CREATE_USER
                           + "GETDATE(),"                                                ///CREATE_DATE
                           + "1"                                                         ///VALID_FLAG
                           + ");";
                    continue;
                }
                ///物料中文名称②为必填项
                if (string.IsNullOrEmpty(userExcelInfo.EmployeeName))
                {
                    throw new Exception("MC:0x00000238");///用户名与用户姓名是必填项
                }
                ///值
                string valueString = string.Empty;
                for (int i = 0; i < fields.Count; i++)
                {
                    string valueStr = CommonDAL.GetFieldValueForSql(userExcelInfo, fields[i]);
                    if (string.IsNullOrEmpty(valueStr))
                    {
                        throw new Exception("MC:1x00000043");///数据格式不符合导入规范
                    }
                    valueString += "[" + fieldNames[fields[i]] + "] = " + valueStr + ",";
                }
                sql += "update dbo.[TS_SYS_USER] set "
                       + valueString
                       + "[MODIFY_USER] = N'" + loginUser + "',"
                       + "[MODIFY_DATE] = GETDATE() "
                       + "where [ID] = " + userInfo.Id + ";";
            }
            ///
            if (string.IsNullOrEmpty(sql))
            {
                return(false);
            }

            return(CommonDAL.ExecuteNonQueryBySql(sql));
        }