//------------------------------------------------------------------------------------------
 /// <summary>
 /// 新增一条记录
 /// </summary>
 /// <param name="entity"></param>
 public bool Append(Role_resource entity)
 {
     try
     {
        bool result = _Role_resourceDal.Append(entity);
        ClearCacheData();
        return result;
     }
     catch (Exception ex)
     {
         DealError(ex);
         return false;
     }
 }
        //------------------------------------------------------------------------------------------
        /// <summary>
        /// 增加一条记录
        /// </summary>
        /// <param name="entity"></param>
        public bool Append(Role_resource entity)
        {
            string sqlCmd = "insert into mp_role_resource (ResourceName ,ParentID ,Sort ,ShowInMenu ,State ,CreateTime ,Url) values (@ResourceName ,@ParentID ,@Sort ,@ShowInMenu ,@State ,@CreateTime ,@Url);SELECT  LAST_INSERT_ID();";
            MySqlParameter[] pars = new MySqlParameter[7];
            pars[0] = new MySqlParameter("@ResourceName",entity.ResourceName);
            pars[1] = new MySqlParameter("@ParentID",entity.ParentID);
            pars[2] = new MySqlParameter("@Sort",entity.Sort);
            pars[3] = new MySqlParameter("@ShowInMenu",entity.ShowInMenu);
            pars[4] = new MySqlParameter("@State",entity.State);
            pars[5] = new MySqlParameter("@CreateTime",entity.CreateTime);
            pars[6] = new MySqlParameter("@Url",entity.Url);

            entity.ResourceID = Convert.ToInt32(MySqlHelper.ExecuteScalar(CommandType.Text, sqlCmd,pars));
            return true;
        }
        //------------------------------------------------------------------------------------------
        /// <summary>
        /// 更新一条记录
        /// </summary>
        /// <param name="entity"></param>
        public bool Update(Role_resource entity)
        {
            string sqlCmd = "update mp_role_resource set  ResourceName = @ResourceName, ParentID = @ParentID, Sort = @Sort, ShowInMenu = @ShowInMenu, State = @State, CreateTime = @CreateTime, Url = @Url  where   ResourceID =  @ResourceID ";

            MySqlParameter[] pars = new MySqlParameter[8];
            pars[0] = new MySqlParameter("@ResourceID",entity.ResourceID);
            pars[1] = new MySqlParameter("@ResourceName",entity.ResourceName);
            pars[2] = new MySqlParameter("@ParentID",entity.ParentID);
            pars[3] = new MySqlParameter("@Sort",entity.Sort);
            pars[4] = new MySqlParameter("@ShowInMenu",entity.ShowInMenu);
            pars[5] = new MySqlParameter("@State",entity.State);
            pars[6] = new MySqlParameter("@CreateTime",entity.CreateTime);
            pars[7] = new MySqlParameter("@Url",entity.Url);

            return MySqlHelper.ExecuteNonQuery(CommandType.Text,sqlCmd,  pars);
        }
 //------------------------------------------------------------------------------------------
 /// <summary>
 /// 把reader转换成Entity
 /// </summary>
 /// <param name="table">表数据</param>
 /// <returns></returns>
 private Role_resource DataReaderToEntity(IDataReader reader)
 {
     Role_resource entity= new Role_resource();
     entity.ResourceID = Convert.ToInt32(reader["ResourceID"]) ;
     entity.ResourceName = Convert.ToString(reader["ResourceName"]) ;
     entity.ParentID = Convert.ToInt32(reader["ParentID"]) ;
     entity.Sort = Convert.ToInt32(reader["Sort"]) ;
     entity.ShowInMenu = Convert.ToInt32(reader["ShowInMenu"]) ;
     entity.State = Convert.ToInt32(reader["State"]) ;
     entity.CreateTime = Convert.ToDateTime(reader["CreateTime"]) ;
     entity.Url = Convert.ToString(reader["Url"]) ;
     return entity;
 }
Beispiel #5
0
        public ActionResult SaveResource()
        {
            List<Role_resource> newResource = new List<Role_resource>();
            List<Role_resource> updateResource = new List<Role_resource>();

            foreach (string item in Request.Form.Keys)
            {
                Match match = Regex.Match(item, @"ResourceName\[(?<id>\d+)\]");
                if (match.Success)
                {
                    int id = Convert.ToInt32(match.Groups["id"].Value);
                    Role_resource res = new Role_resource();
                    res.ResourceID = id;
                    res.ResourceName = DTLRequest.GetString(string.Format("ResourceName[{0}]", id));
                    res.ParentID = DTLRequest.GetInt(string.Format("ParentID[{0}]", id), 0);
                    res.Url = DTLRequest.GetString(string.Format("Url[{0}]", id));
                    res.Sort = DTLRequest.GetInt(string.Format("Sort[{0}]", id), 0);
                    res.State = DTLRequest.GetInt(string.Format("State[{0}]", id), 0);
                    res.ShowInMenu = DTLRequest.GetInt(string.Format("ShowInMenu[{0}]", id), 0);
                    updateResource.Add(res);
                }
            }

            if (!string.IsNullOrEmpty(DTLRequest.GetString("new[ResourceName]")))
            {
                string[] names = DTLRequest.GetString("new[ResourceName]").Split(',');
                string[] urls = DTLRequest.GetString("new[Url]").Split(',');
                string[] sorts = DTLRequest.GetString("new[Sort]").Split(',');
                string[] states = DTLRequest.GetString("new[State]").Split(',');
                string[] parents = DTLRequest.GetString("new[ParentID]").Split(',');
                string[] showmenus = DTLRequest.GetString("new[ShowInMenu]").Split(',');
                for (int i = 0; i < names.Length; i++)
                {
                    try
                    {
                        Role_resource res = new Role_resource();

                        res.ResourceName = names[i];
                        res.Url = urls[i];
                        int temp = 0;
                        if (int.TryParse(sorts[i], out temp))
                        {
                            res.Sort = temp;
                        }

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

                        if (int.TryParse(parents[i], out temp))
                        {
                            res.ParentID = temp;
                        }
                        if (int.TryParse(showmenus[i], out temp))
                        {
                            res.ShowInMenu = temp;

                        }

                        if (!string.IsNullOrEmpty(res.ResourceName))
                        {
                            newResource.Add(res);
                        }
                    }
                    catch (Exception ex)
                    {

                        Log.Default.Info(ex);
                    }

                }
            }
            foreach (var item in newResource)
            {
                Role_resourceBLL.Current.Append(item);
            }

            foreach (var item in updateResource)
            {
                Role_resourceBLL.Current.Update(item);
            }
            return CommonResult.ShowMessage("保存成功!", Url.Action("resources"));
        }