//------------------------------------------------------------------------------------------
        /// <summary>
        /// 增加一条记录
        /// </summary>
        /// <param name="entity"></param>
        public bool Append(Role_group entity)
        {
            string sqlCmd = "insert into mp_role_group (GroupName ,CreateTime ,Auth_Action ,Auth_Resource ,State) values (@GroupName ,@CreateTime ,@Auth_Action ,@Auth_Resource ,@State);SELECT  LAST_INSERT_ID();";
            MySqlParameter[] pars = new MySqlParameter[5];
            pars[0] = new MySqlParameter("@GroupName",entity.GroupName);
            pars[1] = new MySqlParameter("@CreateTime",entity.CreateTime);
            pars[2] = new MySqlParameter("@Auth_Action",entity.Auth_Action);
            pars[3] = new MySqlParameter("@Auth_Resource",entity.Auth_Resource);
            pars[4] = new MySqlParameter("@State",entity.State);

            entity.GroupID = Convert.ToInt32(MySqlHelper.ExecuteScalar(CommandType.Text, sqlCmd,pars));
            return true;
        }
示例#2
0
        //------------------------------------------------------------------------------------------
        /// <summary>
        //更新一条的基础信息(不更新权限)
        /// </summary>
        /// <param name="entity"></param>
        public bool UpdateBaseInfo(Role_group entity)
        {
            try
            {
                ClearCacheData();
                return _Role_groupDal.UpdateBaseInfo(entity);

            }
            catch (Exception ex)
            {
                DealError(ex);
                return false;
            }
        }
 //------------------------------------------------------------------------------------------
 /// <summary>
 /// 新增一条记录
 /// </summary>
 /// <param name="entity"></param>
 public bool Append(Role_group entity)
 {
     try
     {
        bool result = _Role_groupDal.Append(entity);
        ClearCacheData();
        return result;
     }
     catch (Exception ex)
     {
         DealError(ex);
         return false;
     }
 }
 //------------------------------------------------------------------------------------------
 /// <summary>
 /// 把reader转换成Entity
 /// </summary>
 /// <param name="table">表数据</param>
 /// <returns></returns>
 private Role_group DataReaderToEntity(IDataReader reader)
 {
     Role_group entity= new Role_group();
     entity.GroupID = Convert.ToInt32(reader["GroupID"]) ;
     entity.GroupName = Convert.ToString(reader["GroupName"]) ;
     entity.CreateTime = Convert.ToDateTime(reader["CreateTime"]) ;
     entity.Auth_Action = Convert.ToString(reader["Auth_Action"]) ;
     entity.Auth_Resource = Convert.ToString(reader["Auth_Resource"]) ;
     entity.State = Convert.ToInt32(reader["State"]) ;
     return entity;
 }
        //------------------------------------------------------------------------------------------
        /// <summary>
        /// 更新一条记录
        /// </summary>
        /// <param name="entity"></param>
        public bool Update(Role_group entity)
        {
            string sqlCmd = "update mp_role_group set  GroupName = @GroupName, CreateTime = @CreateTime, Auth_Action = @Auth_Action, Auth_Resource = @Auth_Resource, State = @State  where   GroupID =  @GroupID ";

            MySqlParameter[] pars = new MySqlParameter[6];
            pars[0] = new MySqlParameter("@GroupID",entity.GroupID);
            pars[1] = new MySqlParameter("@GroupName",entity.GroupName);
            pars[2] = new MySqlParameter("@CreateTime",entity.CreateTime);
            pars[3] = new MySqlParameter("@Auth_Action",entity.Auth_Action);
            pars[4] = new MySqlParameter("@Auth_Resource",entity.Auth_Resource);
            pars[5] = new MySqlParameter("@State",entity.State);

            return MySqlHelper.ExecuteNonQuery(CommandType.Text,sqlCmd,  pars);
        }
示例#6
0
        public ActionResult SaveGroups()
        {
            //            ResourceName[2]	B角色
            //State[2]	0
            List<Role_group> newRole = new List<Role_group>();
            List<Role_group> updateRole = new List<Role_group>();

            foreach (string item in Request.Form.Keys)
            {
                Match match = Regex.Match(item, @"GroupName\[(?<id>\d+)\]");
                if (match.Success)
                {
                    int id = Convert.ToInt32(match.Groups["id"].Value);
                    Role_group group = new Role_group();
                    group.GroupID = id;
                    group.GroupName = DTLRequest.GetString(string.Format("GroupName[{0}]", id));
                    group.State = DTLRequest.GetInt(string.Format("State[{0}]", id), 0);
                    updateRole.Add(group);
                }
            }

            if (!string.IsNullOrEmpty(DTLRequest.GetString("new[GroupName]")))
            {
                string[] names = DTLRequest.GetString("new[GroupName]").Split(',');

                string[] states = DTLRequest.GetString("new[State]").Split(',');

                for (int i = 0; i < names.Length; i++)
                {
                    try
                    {
                        Role_group role = new Role_group();

                        role.GroupName = names[i];

                        int temp = 0;
                        if (int.TryParse(states[i], out temp))
                        {
                            role.State = temp;
                        }

                        if (!string.IsNullOrEmpty(role.GroupName))
                        {
                            newRole.Add(role);
                        }
                    }
                    catch (Exception ex)
                    {

                        Log.Default.Info(ex);
                    }

                }
            }
            foreach (var item in newRole)
            {
                Role_groupBLL.Current.Append(item);
            }

            foreach (var item in updateRole)
            {
                Role_groupBLL.Current.UpdateBaseInfo(item);
            }
            return CommonResult.ShowMessage("保存成功!", Url.Action("groups"));
        }