Exemple #1
0
        /// <summary>
        /// 添加IP地址或者Mac地址
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //检查输入是否有效
            if (!this.CheckInput())
            {
                return;
            }

            string statusCode  = string.Empty;
            string returnValue = string.Empty;

            string[]             nameArr          = new string[2];
            string[]             valueArr         = new string[2];
            BaseParameterManager parameterManager = new BaseParameterManager(this.UserCenterDbHelper, this.UserInfo);
            BaseSequenceManager  sequenceManager  = new BaseSequenceManager(this.UserCenterDbHelper, this.UserInfo);
            // 增加ip
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            if (!string.IsNullOrEmpty(this.txtIPAddress.Text.Trim()))
            {
                parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterId, this.ucUser.SelectedId));
                parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterContent, this.txtIPAddress.Text.Trim()));
                // 检查是否存在IpAddress
                if (parameterManager.Exists(parameters))
                {
                    statusCode = AppMessage.MSG0055;
                    MessageBox.Show(statusCode, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                BaseParameterEntity entityIp = new BaseParameterEntity();
                entityIp.Id          = sequenceManager.GetSequence(BaseParameterEntity.TableName);
                entityIp.CategoryId  = "IPAddress";
                entityIp.ParameterId = this.ucUser.SelectedId;
                string ipStr = this.txtIPAddress.Text.Trim();

                //Range Mask  和Single  在CheckInput 方法中使用正则表达式对输入进行验证
                //如果是地址段
                if (ipStr.IndexOf('-') > 0)
                {
                    entityIp.ParameterCode = "Range";// mask range
                }
                else if (ipStr.IndexOf('*') > 0)
                { //如果有mask
                    entityIp.ParameterCode = "Mask";
                }
                else
                {
                    entityIp.ParameterCode = "Single";
                }
                //如果是单个ip

                entityIp.ParameterContent = this.txtIPAddress.Text.Trim();
                returnValue = parameterManager.AddEntity(entityIp);
                if (!string.IsNullOrEmpty(returnValue))
                {
                    statusCode = AppMessage.MSG0056;
                }
                else
                {
                    statusCode = AppMessage.MSG0057;
                }
            }
            // 增加Mac
            if (!string.IsNullOrEmpty(this.txtMacAddress.Text.Trim()))
            {
                parameters = new List <KeyValuePair <string, object> >();
                parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterId, this.ucUser.SelectedId));
                parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterContent, this.txtMacAddress.Text.Trim()));
                // 检查是否存在MacAddress
                if (parameterManager.Exists(parameters))
                {
                    statusCode = AppMessage.MSG0058;
                    MessageBox.Show(statusCode, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                BaseParameterEntity entityMac = new BaseParameterEntity();
                entityMac.Id               = sequenceManager.GetSequence(BaseParameterEntity.TableName);
                entityMac.CategoryId       = "MacAddress";
                entityMac.ParameterId      = this.ucUser.SelectedId;
                entityMac.ParameterCode    = "Single";
                entityMac.ParameterContent = this.txtMacAddress.Text.Trim();
                returnValue = parameterManager.AddEntity(entityMac);

                if (!string.IsNullOrEmpty(returnValue))
                {
                    statusCode += AppMessage.MSG0059;
                }
                else
                {
                    statusCode += AppMessage.MSG0061;
                }
            }

            MessageBox.Show(statusCode, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
            // 重新绑定listbox
            this.GetIpList(this.ucUser.SelectedId);
            this.GetMacList(this.ucUser.SelectedId);
            this.CleanScreen();
        }
Exemple #2
0
        /// <summary>
        /// 更新密码
        /// </summary>
        /// <param name="oldPassword">原密码</param>
        /// <param name="newPassword">新密码</param>
        /// <param name="statusCode">返回状态码</param>
        /// <returns>影响行数</returns>
        public virtual int ChangePassword(string oldPassword, string newPassword, out string statusCode)
        {
            #if (DEBUG)
            int milliStart = Environment.TickCount;
            #endif

            int returnValue = 0;
            // 密码强度检查
            if (BaseSystemInfo.CheckPasswordStrength)
            {
                if (String.IsNullOrEmpty(newPassword))
                {
                    statusCode = StatusCode.PasswordCanNotBeNull.ToString();
                    return(returnValue);
                }
            }
            // 加密密码
            if (BaseSystemInfo.ServerEncryptPassword)
            {
                oldPassword = this.EncryptUserPassword(oldPassword);
                newPassword = this.EncryptUserPassword(newPassword);
            }
            // 判断输入原始密码是否正确
            BaseUserEntity userEntity = new BaseUserEntity();
            userEntity.GetSingle(this.GetDataTableById(UserInfo.Id));
            if (userEntity.UserPassword == null)
            {
                userEntity.UserPassword = string.Empty;
            }
            // 密码错误
            if (!userEntity.UserPassword.Equals(oldPassword))
            {
                statusCode = StatusCode.OldPasswordError.ToString();
                return(returnValue);
            }
            // 对比是否最近2次用过这个密码
            if (BaseSystemInfo.CheckPasswordStrength)
            {
                int i = 0;
                BaseParameterManager parameterManager = new BaseParameterManager(this.DbHelper, this.UserInfo);
                DataTable            dataTable        = parameterManager.GetDataTableParameterCode("User", this.UserInfo.Id, "Password");
                foreach (DataRow dataRow in dataTable.Rows)
                {
                    string parameter = dataRow[BaseParameterEntity.FieldParameterContent].ToString();
                    if (parameter.Equals(newPassword))
                    {
                        statusCode = StatusCode.PasswordCanNotBeRepeat.ToString();
                        return(returnValue);
                    }
                    i++;
                    {
                        // 判断连续2个密码就是可以了
                        if (i > 2)
                        {
                            break;
                        }
                    }
                }
            }
            // 更改密码,同时修改密码的修改日期
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
            parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldUserPassword, newPassword));
            // 注意日期格式,ACCESS中要用字符
            parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldChangePasswordDate, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
            returnValue = this.SetProperty(new KeyValuePair <string, object>(BaseUserEntity.FieldId, UserInfo.Id), parameters);
            if (returnValue == 1)
            {
                statusCode = StatusCode.ChangePasswordOK.ToString();
                // 若是强类型密码检查,那就保存密码修改历史,防止最近2-3次的密码相同的功能实现。
                if (BaseSystemInfo.CheckPasswordStrength)
                {
                    BaseParameterManager parameterManager = new BaseParameterManager(this.DbHelper, this.UserInfo);
                    BaseParameterEntity  parameterEntity  = new BaseParameterEntity();
                    parameterEntity.CategoryId        = "User";
                    parameterEntity.ParameterId       = this.UserInfo.Id;
                    parameterEntity.ParameterCode     = "Password";
                    parameterEntity.ParameterContent  = newPassword;
                    parameterEntity.DeletionStateCode = 0;
                    parameterEntity.Enabled           = true;
                    parameterEntity.Worked            = true;
                    parameterManager.AddEntity(parameterEntity);
                }
            }
            else
            {
                // 数据可能被删除
                statusCode = StatusCode.ErrorDeleted.ToString();
            }

            // 写入调试信息
            #if (DEBUG)
            int milliEnd = Environment.TickCount;
            Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " " + " BaseUserManager.ChangePassword(" + userEntity.Id + ")");
            #endif

            return(returnValue);
        }