Пример #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Light.Model.roleinfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into roleinfo(");
            strSql.Append("id,rolename,remark,createman,createtime");
            strSql.Append(") values (");
            strSql.Append("@id,@rolename,@remark,@createman,@createtime");
            strSql.Append(") ");

            MySqlParameter[] parameters =
            {
                new MySqlParameter("@id",         MySqlDbType.Int32,    10),
                new MySqlParameter("@rolename",   MySqlDbType.VarChar,  10),
                new MySqlParameter("@remark",     MySqlDbType.VarChar, 200),
                new MySqlParameter("@createman",  MySqlDbType.Int32,    10),
                new MySqlParameter("@createtime", MySqlDbType.DateTime)
            };

            parameters[0].Value = model.id;
            parameters[1].Value = model.rolename;
            parameters[2].Value = model.remark;
            parameters[3].Value = model.createman;
            parameters[4].Value = model.createtime;
            DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
        }
Пример #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Light.Model.roleinfo GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id, rolename, remark, createman, createtime  ");
            strSql.Append("  from roleinfo ");
            strSql.Append(" where id=@id ");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@id", MySqlDbType.Int32, 10)
            };
            parameters[0].Value = id;


            Light.Model.roleinfo model = new Light.Model.roleinfo();
            DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                model.rolename = ds.Tables[0].Rows[0]["rolename"].ToString();
                model.remark   = ds.Tables[0].Rows[0]["remark"].ToString();
                if (ds.Tables[0].Rows[0]["createman"].ToString() != "")
                {
                    model.createman = int.Parse(ds.Tables[0].Rows[0]["createman"].ToString());
                }
                if (ds.Tables[0].Rows[0]["createtime"].ToString() != "")
                {
                    model.createtime = DateTime.Parse(ds.Tables[0].Rows[0]["createtime"].ToString());
                }

                return(model);
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Light.Model.roleinfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update roleinfo set ");

            strSql.Append(" id = @id , ");
            strSql.Append(" rolename = @rolename , ");
            strSql.Append(" remark = @remark , ");
            strSql.Append(" createman = @createman , ");
            strSql.Append(" createtime = @createtime  ");
            strSql.Append(" where id=@id  ");

            MySqlParameter[] parameters =
            {
                new MySqlParameter("@id",         MySqlDbType.Int32,    10),
                new MySqlParameter("@rolename",   MySqlDbType.VarChar,  10),
                new MySqlParameter("@remark",     MySqlDbType.VarChar, 200),
                new MySqlParameter("@createman",  MySqlDbType.Int32,    10),
                new MySqlParameter("@createtime", MySqlDbType.DateTime)
            };

            parameters[0].Value = model.id;
            parameters[1].Value = model.rolename;
            parameters[2].Value = model.remark;
            parameters[3].Value = model.createman;
            parameters[4].Value = model.createtime;
            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Light.Model.roleinfo GetModel(int id)
        {
            StringBuilder strSql=new StringBuilder();
            strSql.Append("select id, rolename, remark, createman, createtime  ");
            strSql.Append("  from roleinfo ");
            strSql.Append(" where id=@id ");
                        MySqlParameter[] parameters = {
                    new MySqlParameter("@id", MySqlDbType.Int32,10)			};
            parameters[0].Value = id;

            Light.Model.roleinfo model=new Light.Model.roleinfo();
            DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);

            if(ds.Tables[0].Rows.Count>0)
            {
                                                if(ds.Tables[0].Rows[0]["id"].ToString()!="")
                {
                    model.id=int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                                                                                                                                                model.rolename= ds.Tables[0].Rows[0]["rolename"].ToString();
                                                                                                                                model.remark= ds.Tables[0].Rows[0]["remark"].ToString();
                                                                                                                if(ds.Tables[0].Rows[0]["createman"].ToString()!="")
                {
                    model.createman=int.Parse(ds.Tables[0].Rows[0]["createman"].ToString());
                }
                                                                                                                                if(ds.Tables[0].Rows[0]["createtime"].ToString()!="")
                {
                    model.createtime=DateTime.Parse(ds.Tables[0].Rows[0]["createtime"].ToString());
                }

                return model;
            }
            else
            {
                return null;
            }
        }