Esempio n. 1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Hoto.Model.attributes GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,channel_id,title,remark,type,default_value,sort_id,add_time from dt_attributes ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Hoto.Model.attributes model = new Hoto.Model.attributes();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["channel_id"] != null && ds.Tables[0].Rows[0]["channel_id"].ToString() != "")
                {
                    model.channel_id = int.Parse(ds.Tables[0].Rows[0]["channel_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "")
                {
                    model.title = ds.Tables[0].Rows[0]["title"].ToString();
                }
                if (ds.Tables[0].Rows[0]["remark"] != null && ds.Tables[0].Rows[0]["remark"].ToString() != "")
                {
                    model.remark = ds.Tables[0].Rows[0]["remark"].ToString();
                }
                if (ds.Tables[0].Rows[0]["type"] != null && ds.Tables[0].Rows[0]["type"].ToString() != "")
                {
                    model.type = int.Parse(ds.Tables[0].Rows[0]["type"].ToString());
                }
                if (ds.Tables[0].Rows[0]["default_value"] != null && ds.Tables[0].Rows[0]["default_value"].ToString() != "")
                {
                    model.default_value = ds.Tables[0].Rows[0]["default_value"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sort_id"] != null && ds.Tables[0].Rows[0]["sort_id"].ToString() != "")
                {
                    model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["add_time"] != null && ds.Tables[0].Rows[0]["add_time"].ToString() != "")
                {
                    model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Hoto.Model.attributes model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update dt_attributes set ");
            strSql.Append("channel_id=@channel_id,");
            strSql.Append("title=@title,");
            strSql.Append("remark=@remark,");
            strSql.Append("type=@type,");
            strSql.Append("default_value=@default_value,");
            strSql.Append("sort_id=@sort_id,");
            strSql.Append("add_time=@add_time");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@channel_id",    SqlDbType.Int,         4),
                new SqlParameter("@title",         SqlDbType.NVarChar,  100),
                new SqlParameter("@remark",        SqlDbType.NVarChar,  500),
                new SqlParameter("@type",          SqlDbType.Int,         4),
                new SqlParameter("@default_value", SqlDbType.NVarChar,  500),
                new SqlParameter("@sort_id",       SqlDbType.Int,         4),
                new SqlParameter("@add_time",      SqlDbType.DateTime),
                new SqlParameter("@id",            SqlDbType.Int, 4)
            };
            parameters[0].Value = model.channel_id;
            parameters[1].Value = model.title;
            parameters[2].Value = model.remark;
            parameters[3].Value = model.type;
            parameters[4].Value = model.default_value;
            parameters[5].Value = model.sort_id;
            parameters[6].Value = model.add_time;
            parameters[7].Value = model.id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Hoto.Model.attributes model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into dt_attributes(");
            strSql.Append("channel_id,title,remark,type,default_value,sort_id,add_time)");
            strSql.Append(" values (");
            strSql.Append("@channel_id,@title,@remark,@type,@default_value,@sort_id,@add_time)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@channel_id",    SqlDbType.Int,        4),
                new SqlParameter("@title",         SqlDbType.NVarChar, 100),
                new SqlParameter("@remark",        SqlDbType.NVarChar, 500),
                new SqlParameter("@type",          SqlDbType.Int,        4),
                new SqlParameter("@default_value", SqlDbType.NVarChar, 500),
                new SqlParameter("@sort_id",       SqlDbType.Int,        4),
                new SqlParameter("@add_time",      SqlDbType.DateTime)
            };
            parameters[0].Value = model.channel_id;
            parameters[1].Value = model.title;
            parameters[2].Value = model.remark;
            parameters[3].Value = model.type;
            parameters[4].Value = model.default_value;
            parameters[5].Value = model.sort_id;
            parameters[6].Value = model.add_time;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// �õ�һ������ʵ��
        /// </summary>
        public Hoto.Model.attributes GetModel(int id)
        {
            StringBuilder strSql=new StringBuilder();
            strSql.Append("select  top 1 id,channel_id,title,remark,type,default_value,sort_id,add_time from dt_attributes ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int,4)
            };
            parameters[0].Value = id;

            Hoto.Model.attributes model=new Hoto.Model.attributes();
            DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
            if(ds.Tables[0].Rows.Count>0)
            {
                if(ds.Tables[0].Rows[0]["id"]!=null && ds.Tables[0].Rows[0]["id"].ToString()!="")
                {
                    model.id=int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if(ds.Tables[0].Rows[0]["channel_id"]!=null && ds.Tables[0].Rows[0]["channel_id"].ToString()!="")
                {
                    model.channel_id=int.Parse(ds.Tables[0].Rows[0]["channel_id"].ToString());
                }
                if(ds.Tables[0].Rows[0]["title"]!=null && ds.Tables[0].Rows[0]["title"].ToString()!="")
                {
                    model.title=ds.Tables[0].Rows[0]["title"].ToString();
                }
                if(ds.Tables[0].Rows[0]["remark"]!=null && ds.Tables[0].Rows[0]["remark"].ToString()!="")
                {
                    model.remark=ds.Tables[0].Rows[0]["remark"].ToString();
                }
                if(ds.Tables[0].Rows[0]["type"]!=null && ds.Tables[0].Rows[0]["type"].ToString()!="")
                {
                    model.type=int.Parse(ds.Tables[0].Rows[0]["type"].ToString());
                }
                if(ds.Tables[0].Rows[0]["default_value"]!=null && ds.Tables[0].Rows[0]["default_value"].ToString()!="")
                {
                    model.default_value=ds.Tables[0].Rows[0]["default_value"].ToString();
                }
                if(ds.Tables[0].Rows[0]["sort_id"]!=null && ds.Tables[0].Rows[0]["sort_id"].ToString()!="")
                {
                    model.sort_id=int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString());
                }
                if(ds.Tables[0].Rows[0]["add_time"]!=null && ds.Tables[0].Rows[0]["add_time"].ToString()!="")
                {
                    model.add_time=DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }