/// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="employeeId"></param>
       public int Add(int employeeId,string username,string passwd) {
           using (ChooseDishesEntities entities = new ChooseDishesEntities()) {
               Employee employee = entities.Employee.Find(employeeId);
               if (null == employee) {
                   throw new ServiceException("无法找到对应的员工,编号为:【"+employeeId+"】");
               }
               int authorId=SubjectUtils.GetAuthenticationId();
               UserInfo _UserInfo = new UserInfo();
              
               _UserInfo.EmployeeId = employeeId;
               if (null != username || null!=passwd) {
                   _UserInfo.Username = username;
                   _UserInfo.Salt = CryptoUtils.GetSalt();
                   _UserInfo.Password = CryptoUtils.MD5Encrypt(passwd);
                   _UserInfo.CreateBy = SubjectUtils.GetAuthenticationId();
               }
               _UserInfo.CreateDatetime = DateTime.Now;
               entities.UserInfo.Add(_UserInfo);
               try
               {
                   entities.SaveChanges();
                   Log.A(Loggers.USER_NEW, authorId, _UserInfo.UserId);
               }catch(DbEntityValidationException e){
                   throw new ServiceException(e.Message);
               }
               return _UserInfo.UserId;
           }

       }
 protected  void From(UserInfo userInfo) {
     this.UserId = userInfo.UserId;
     this.EmployeeId = userInfo.EmployeeId;
     this.Username = userInfo.Username;
     this.EmployeeName = userInfo.Employee.Name;
     if (null != userInfo.UserSaleRule) {
         this.AllowanceType = ""+userInfo.UserSaleRule.AlowanceType;
         this.AllowanceLimit = userInfo.UserSaleRule.AllowanceLimit;
         this.PresentType = ""+userInfo.UserSaleRule.PresentType;
         this.PresentLimit = userInfo.UserSaleRule.PresentLimit;
         this.DiscountAllowanceLimit = userInfo.UserSaleRule.DiscountAllowanceLimit;
         this.DiscountLimit = userInfo.UserSaleRule.DiscountLimit;
     }
 }
 /// <summary>
 /// 设置用户选择的权限
 /// </summary>
 /// <param name="_userInfo"></param>
  protected void SetUserRoles(UserInfo _userInfo) {
      var refs = _userInfo.UserRoleRef;
      foreach (var r in refs) {
          foreach (var t in Roles) {
              if (t.Id == r.RoleId) {
                  t.Had = true;
              }
          }
      }
  }
 /// <summary>
 /// 设置表单规则
 /// </summary>
 /// <param name="_UserInfo"></param>
 protected void SetUserInfoAndRuleForForm(UserInfo _UserInfo) {
     this.EmployeeId=_UserInfo.EmployeeId;
     this.Name=_UserInfo.Employee.Name;
 
 }
 /// <summary>
 /// 设置表单规则
 /// </summary>
 /// <param name="_UserInfo"></param>
 protected void SetUserInfoAndRuleForForm(UserInfo _UserInfo) {
     this.EmployeeId=_UserInfo.EmployeeId;
     this.Name=_UserInfo.Employee.Name;
     DiscountLimit = (double)_UserInfo.UserSaleRule.DiscountLimit;
     AllowanceLimit = (double)_UserInfo.UserSaleRule.AllowanceLimit;
     PresentLimit = (double)_UserInfo.UserSaleRule.PresentLimit;
 //    DiscountAllowance = (double)_UserInfo.UserSaleRule.DiscountAllowanceLimit;
    
 }
 public UserModel(UserInfo Info) {
     this.From(Info);
 }