コード例 #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(FishEntity.UserRoleEntity model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update t_userrole set ");
            strSql.Append("userid=@userid,");
            strSql.Append("roleid=@roleid");
            strSql.Append(" where id=@id ");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@userid", MySqlDbType.Int32, 11),
                new MySqlParameter("@roleid", MySqlDbType.Int32, 11),
                new MySqlParameter("@id",     MySqlDbType.Int32, 11)
            };
            parameters[0].Value = model.userid;
            parameters[1].Value = model.roleid;
            parameters[2].Value = model.id;

            int rows = MySqlHelper.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
ファイル: FormUserRole.cs プロジェクト: icprog/ZhengDong
        public override void Save()
        {
            if (treeView1.Nodes.Count < 1)
            {
                MessageBox.Show("没有权限需要保存");
                return;
            }

            treeView1.EndUpdate();

            List <FishEntity.UserRoleEntity> newRoles = new List <FishEntity.UserRoleEntity>();

            foreach (TreeNode node in treeView1.Nodes)
            {
                FishEntity.RoleEntity role = node.Tag as FishEntity.RoleEntity;
                if (role == null)
                {
                    continue;
                }
                if (node.Checked)
                {
                    FishEntity.UserRoleEntity uRole = new FishEntity.UserRoleEntity();
                    uRole.roleid = role.roleid;
                    uRole.userid = _user.id;
                    newRoles.Add(uRole);
                }
            }

            FishBll.Bll.UserRoleBll bll = new FishBll.Bll.UserRoleBll();
            if (newRoles == null || newRoles.Count == 0)
            {
                bll.DeleteByUserId(_user.id);
                return;
            }

            _oldRoles = bll.GetModelList("userid=" + _user.id);

            if (_oldRoles != null)
            {
                foreach (FishEntity.UserRoleEntity item in _oldRoles)
                {
                    bool isExist = newRoles.Exists((i) => { return(i.roleid == item.roleid); });
                    if (false == isExist)
                    {
                        bll.Delete(item.id);
                    }
                }
            }

            foreach (FishEntity.UserRoleEntity item in newRoles)
            {
                bool isExist = _oldRoles == null ? false : _oldRoles.Exists((i) => { return(i.roleid == item.roleid); });
                if (isExist == false)
                {
                    bll.Add(item);
                }
            }

            MessageBox.Show("设置成功");
        }
コード例 #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(FishEntity.UserRoleEntity model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into t_userrole(");
            strSql.Append("userid,roleid)");
            strSql.Append(" values (");
            strSql.Append("@userid,@roleid)");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@userid", MySqlDbType.Int32, 11),
                new MySqlParameter("@roleid", MySqlDbType.Int32, 11)
            };
            parameters[0].Value = model.userid;
            parameters[1].Value = model.roleid;

            int rows = MySqlHelper.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public FishEntity.UserRoleEntity DataRowToModel(DataRow row)
 {
     FishEntity.UserRoleEntity model = new FishEntity.UserRoleEntity();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["userid"] != null && row["userid"].ToString() != "")
         {
             model.userid = int.Parse(row["userid"].ToString());
         }
         if (row["roleid"] != null && row["roleid"].ToString() != "")
         {
             model.roleid = int.Parse(row["roleid"].ToString());
         }
     }
     return(model);
 }
コード例 #5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FishEntity.UserRoleEntity GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id,userid,roleid from t_userrole ");
            strSql.Append(" where id=@id ");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@id", MySqlDbType.Int32, 11)
            };
            parameters[0].Value = id;

            FishEntity.UserRoleEntity model = new FishEntity.UserRoleEntity();
            DataSet ds = MySqlHelper.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
コード例 #6
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(FishEntity.UserRoleEntity model)
 {
     return(dal.Update(model));
 }
コード例 #7
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public bool Add(FishEntity.UserRoleEntity model)
 {
     return(dal.Add(model));
 }