/// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="parameterEntity">实体对象</param>
 /// <returns>主键</returns>
 public string AddEntity(BaseParameterEntity parameterEntity)
 {
     if (string.IsNullOrEmpty(parameterEntity.Id))
     {
         parameterEntity.Id = Guid.NewGuid().ToString();
     }
     SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);
     sqlBuilder.BeginInsert(this.CurrentTableName);
     sqlBuilder.SetValue(BaseParameterEntity.FieldId, parameterEntity.Id);
     sqlBuilder.SetValue(BaseParameterEntity.FieldCategoryId, parameterEntity.CategoryId);
     sqlBuilder.SetValue(BaseParameterEntity.FieldParameterId, parameterEntity.ParameterId);
     sqlBuilder.SetValue(BaseParameterEntity.FieldParameterCode, parameterEntity.ParameterCode);
     sqlBuilder.SetValue(BaseParameterEntity.FieldWorked, parameterEntity.Worked ? 1 : 0);
     sqlBuilder.SetValue(BaseParameterEntity.FieldParameterContent, parameterEntity.ParameterContent);
     sqlBuilder.SetValue(BaseParameterEntity.FieldEnabled, parameterEntity.Enabled ? 1 : 0);
     sqlBuilder.SetValue(BaseParameterEntity.FieldDeletionStateCode, parameterEntity.DeletionStateCode);
     sqlBuilder.SetValue(BaseParameterEntity.FieldDescription, parameterEntity.Description);
     if (UserInfo != null)
     {
         sqlBuilder.SetValue(BaseParameterEntity.FieldCreateUserId, UserInfo.Id);
         sqlBuilder.SetValue(BaseParameterEntity.FieldCreateBy, UserInfo.RealName);
     }
     sqlBuilder.SetDBNow(BaseParameterEntity.FieldCreateOn);
     return sqlBuilder.EndInsert() > 0 ? parameterEntity.Id : string.Empty;
 }
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="categoryId">类别主键</param>
 /// <param name="parameterId">标记主键</param>
 /// <param name="parameterCode">标记编码</param>
 /// <param name="parameterContent">标记内容</param>
 /// <param name="worked">工作状态</param>
 /// <param name="enabled">有效</param>
 /// <returns>主键</returns>
 public string Add(string categoryId, string parameterId, string parameterCode, string parameterContent, bool worked, bool enabled)
 {
     BaseParameterEntity parameterEntity = new BaseParameterEntity();
     parameterEntity.CategoryId = categoryId;
     parameterEntity.ParameterId = parameterId;
     parameterEntity.ParameterCode = parameterCode;
     parameterEntity.ParameterContent = parameterContent;
     parameterEntity.Worked = worked;
     parameterEntity.Enabled = enabled;
     return this.Add(parameterEntity);
 }
 /// <summary>
 /// 清除内容
 /// <param name="entity">实体</param>
 /// </summary>
 public void ClearProperty(BaseParameterEntity entity)
 {
     entity.Id               = string.Empty;
     entity.CategoryCode     = string.Empty;
     entity.ParameterId      = string.Empty;
     entity.ParameterCode    = string.Empty;
     entity.ParameterContent = string.Empty;
     entity.Worked           = false;
     entity.Enabled          = false;
     entity.SortCode         = null;
     entity.Description      = string.Empty;
     entity.CreateUserId     = string.Empty;
     entity.CreateOn         = null;
     entity.ModifiedUserId   = string.Empty;
     entity.ModifiedOn       = null;
 }
 /// <summary>
 /// 添加内容
 /// </summary>
 /// <param name="parameterEntity">内容</param>
 /// <returns>主键</returns>
 public string Add(BaseParameterEntity parameterEntity)
 {
     string returnValue = string.Empty;
     // 此处检查this.exist()
     List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
     parameters.Add(new KeyValuePair<string, object>(BaseParameterEntity.FieldCategoryId, parameterEntity.CategoryId));
     parameters.Add(new KeyValuePair<string, object>(BaseParameterEntity.FieldParameterId, parameterEntity.ParameterId));
     parameters.Add(new KeyValuePair<string, object>(BaseParameterEntity.FieldParameterCode, parameterEntity.ParameterCode));
     if (this.Exists(parameters))
     {
         // 编号已重复
         this.ReturnStatusCode = StatusCode.ErrorCodeExist.ToString();
     }
     else
     {
         returnValue = this.AddEntity(parameterEntity);
         // 运行成功
         this.ReturnStatusCode = StatusCode.OKAdd.ToString();
     }
     return returnValue;
 }
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="parameterEntity">实体</param>
 /// <returns>影响行数</returns>
 protected int UpdateEntity(BaseParameterEntity parameterEntity)
 {
     SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);
     sqlBuilder.BeginUpdate(this.CurrentTableName);
     sqlBuilder.SetValue(BaseParameterEntity.FieldCategoryId, parameterEntity.CategoryId);
     sqlBuilder.SetValue(BaseParameterEntity.FieldParameterCode, parameterEntity.ParameterCode);
     sqlBuilder.SetValue(BaseParameterEntity.FieldParameterId, parameterEntity.ParameterId);
     sqlBuilder.SetValue(BaseParameterEntity.FieldParameterContent, parameterEntity.ParameterContent);
     sqlBuilder.SetValue(BaseParameterEntity.FieldWorked, parameterEntity.Worked ? 1 : 0);
     sqlBuilder.SetValue(BaseParameterEntity.FieldEnabled, parameterEntity.Enabled ? 1 : 0);
     sqlBuilder.SetValue(BaseParameterEntity.FieldDeletionStateCode, parameterEntity.DeletionStateCode);
     sqlBuilder.SetValue(BaseParameterEntity.FieldModifiedUserId, UserInfo.Id);
     sqlBuilder.SetValue(BaseParameterEntity.FieldModifiedBy, UserInfo.RealName);
     sqlBuilder.SetDBNow(BaseParameterEntity.FieldModifiedOn);
     sqlBuilder.SetWhere(BaseParameterEntity.FieldId, parameterEntity.Id);
     return sqlBuilder.EndUpdate();
 }
        /// <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;
        }
 /// <summary>
 /// 清除内容
 /// <param name="ParameterEntity">实体</param>
 /// </summary>
 public void ClearProperty(BaseParameterEntity ParameterEntity)
 {
     ParameterEntity.Id = string.Empty;
     ParameterEntity.CategoryId = string.Empty;
     ParameterEntity.ParameterId = string.Empty;
     ParameterEntity.ParameterCode = string.Empty;
     ParameterEntity.ParameterContent = string.Empty;
     ParameterEntity.Worked = false;
     ParameterEntity.Enabled = false;
     ParameterEntity.SortCode = string.Empty;
     ParameterEntity.Description = string.Empty;
     ParameterEntity.CreateUserId = string.Empty;
     ParameterEntity.CreateOn = string.Empty;
     ParameterEntity.ModifiedUserId = string.Empty;
     ParameterEntity.ModifiedOn = string.Empty;
 }
示例#8
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();
        }
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="parameterEntity">参数基类表结构定义</param>
 /// <returns>影响行数</returns>
 public int Update(BaseParameterEntity parameterEntity)
 {
     int returnValue = 0;
     // 检查是否已被其他人修改
     //if (DbLogic.IsModifed(DbHelper, BaseParameterEntity.TableName, parameterEntity.Id, parameterEntity.ModifiedUserId, parameterEntity.ModifiedOn))
     //{
     //    // 数据已经被修改
     //    this.ReturnStatusCode = StatusCode.ErrorChanged.ToString();
     //}
     //else
     //{
         // 检查编号是否重复
         if (this.Exists(new KeyValuePair<string, object>(BaseParameterEntity.FieldParameterCode, parameterEntity.ParameterCode), parameterEntity.Id))
         {
             // 文件夹名已重复
             this.ReturnStatusCode = StatusCode.ErrorCodeExist.ToString();
         }
         else
         {
             // 进行更新操作
             returnValue = this.UpdateEntity(parameterEntity);
             if (returnValue == 1)
             {
                 this.ReturnStatusCode = StatusCode.OKUpdate.ToString();
             }
             else
             {
                 // 数据可能被删除
                 this.ReturnStatusCode = StatusCode.ErrorDeleted.ToString();
             }
         }
     // }
     return returnValue;
 }
示例#10
0
        /// <summary>
        /// 更新参数设置
        /// </summary>
        /// <param name="categoryId">类别主键</param>
        /// <param name="parameterId">标志主键</param>
        /// <param name="parameterCode">编码</param>
        /// <param name="parameterContent">参数内容</param>
        /// <returns>影响行数</returns>
        public int SetParameter(string categoryId, string parameterId, string parameterCode, string parameterContent)
        {
            int returnValue = 0;

            List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
            parameters.Add(new KeyValuePair<string, object>(BaseParameterEntity.FieldCategoryId, categoryId));
            parameters.Add(new KeyValuePair<string, object>(BaseParameterEntity.FieldParameterId, parameterId));
            parameters.Add(new KeyValuePair<string, object>(BaseParameterEntity.FieldParameterCode, parameterCode));
            parameters.Add(new KeyValuePair<string, object>(BaseParameterEntity.FieldDeletionStateCode, 0));
            // 检测是否无效数据
            if ((parameterContent == null) || (parameterContent.Length == 0))
            {
                returnValue = this.Delete(parameters);
            }
            else
            {
                // 检测是否存在
                returnValue = this.SetProperty(parameters, new KeyValuePair<string, object>(BaseParameterEntity.FieldParameterContent, parameterContent));
                if (returnValue == 0)
                {
                    // 进行增加操作
                    BaseParameterEntity parameterEntity = new BaseParameterEntity();
                    parameterEntity.CategoryId = categoryId;
                    parameterEntity.ParameterId = parameterId;
                    parameterEntity.ParameterCode = parameterCode;
                    parameterEntity.ParameterContent = parameterContent;
                    parameterEntity.Enabled = true;
                    parameterEntity.DeletionStateCode = 0;
                    this.AddEntity(parameterEntity);
                    returnValue = 1;
                }
            }
            return returnValue;
        }