Exemplo n.º 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.notice model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into notice(");
            strSql.Append("title,summary,intro,notice_content,CreateUserID,CreateTime,UpdateUserID,UpdateTime,url,show,status,v1,v2,v3,v4)");
            strSql.Append(" values (");
            strSql.Append("@title,@summary,@intro,@notice_content,@CreateUserID,@CreateTime,@UpdateUserID,@UpdateTime,@url,@show,@status,@v1,@v2,@v3,@v4)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@title",          SqlDbType.NVarChar),
                new SqlParameter("@summary",        SqlDbType.NVarChar),
                new SqlParameter("@intro",          SqlDbType.NVarChar),
                new SqlParameter("@notice_content", SqlDbType.NVarChar),
                new SqlParameter("@CreateUserID",   SqlDbType.BigInt,      8),
                new SqlParameter("@CreateTime",     SqlDbType.DateTime),
                new SqlParameter("@UpdateUserID",   SqlDbType.BigInt,      8),
                new SqlParameter("@UpdateTime",     SqlDbType.DateTime),
                new SqlParameter("@url",            SqlDbType.NVarChar,  400),
                new SqlParameter("@show",           SqlDbType.Int,         4),
                new SqlParameter("@status",         SqlDbType.Int,         4),
                new SqlParameter("@v1",             SqlDbType.NVarChar,  500),
                new SqlParameter("@v2",             SqlDbType.NVarChar,  500),
                new SqlParameter("@v3",             SqlDbType.NVarChar,  500),
                new SqlParameter("@v4",             SqlDbType.NVarChar, 500)
            };
            parameters[0].Value  = model.title;
            parameters[1].Value  = model.summary;
            parameters[2].Value  = model.intro;
            parameters[3].Value  = model.notice_content;
            parameters[4].Value  = model.CreateUserID;
            parameters[5].Value  = model.CreateTime;
            parameters[6].Value  = model.UpdateUserID;
            parameters[7].Value  = model.UpdateTime;
            parameters[8].Value  = model.url;
            parameters[9].Value  = model.show;
            parameters[10].Value = model.status;
            parameters[11].Value = model.v1;
            parameters[12].Value = model.v2;
            parameters[13].Value = model.v3;
            parameters[14].Value = model.v4;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.notice GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,title,summary,intro,notice_content,CreateUserID,CreateTime,UpdateUserID,UpdateTime,url,show,status,v1,v2,v3,v4 from notice ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Maticsoft.Model.notice model = new Maticsoft.Model.notice();
            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]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "")
                {
                    model.title = ds.Tables[0].Rows[0]["title"].ToString();
                }
                if (ds.Tables[0].Rows[0]["summary"] != null && ds.Tables[0].Rows[0]["summary"].ToString() != "")
                {
                    model.summary = ds.Tables[0].Rows[0]["summary"].ToString();
                }
                if (ds.Tables[0].Rows[0]["intro"] != null && ds.Tables[0].Rows[0]["intro"].ToString() != "")
                {
                    model.intro = ds.Tables[0].Rows[0]["intro"].ToString();
                }
                if (ds.Tables[0].Rows[0]["notice_content"] != null && ds.Tables[0].Rows[0]["notice_content"].ToString() != "")
                {
                    model.notice_content = ds.Tables[0].Rows[0]["notice_content"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CreateUserID"] != null && ds.Tables[0].Rows[0]["CreateUserID"].ToString() != "")
                {
                    model.CreateUserID = long.Parse(ds.Tables[0].Rows[0]["CreateUserID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreateTime"] != null && ds.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UpdateUserID"] != null && ds.Tables[0].Rows[0]["UpdateUserID"].ToString() != "")
                {
                    model.UpdateUserID = long.Parse(ds.Tables[0].Rows[0]["UpdateUserID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UpdateTime"] != null && ds.Tables[0].Rows[0]["UpdateTime"].ToString() != "")
                {
                    model.UpdateTime = DateTime.Parse(ds.Tables[0].Rows[0]["UpdateTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["url"] != null && ds.Tables[0].Rows[0]["url"].ToString() != "")
                {
                    model.url = ds.Tables[0].Rows[0]["url"].ToString();
                }
                if (ds.Tables[0].Rows[0]["show"] != null && ds.Tables[0].Rows[0]["show"].ToString() != "")
                {
                    model.show = int.Parse(ds.Tables[0].Rows[0]["show"].ToString());
                }
                if (ds.Tables[0].Rows[0]["status"] != null && ds.Tables[0].Rows[0]["status"].ToString() != "")
                {
                    model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
                }
                if (ds.Tables[0].Rows[0]["v1"] != null && ds.Tables[0].Rows[0]["v1"].ToString() != "")
                {
                    model.v1 = ds.Tables[0].Rows[0]["v1"].ToString();
                }
                if (ds.Tables[0].Rows[0]["v2"] != null && ds.Tables[0].Rows[0]["v2"].ToString() != "")
                {
                    model.v2 = ds.Tables[0].Rows[0]["v2"].ToString();
                }
                if (ds.Tables[0].Rows[0]["v3"] != null && ds.Tables[0].Rows[0]["v3"].ToString() != "")
                {
                    model.v3 = ds.Tables[0].Rows[0]["v3"].ToString();
                }
                if (ds.Tables[0].Rows[0]["v4"] != null && ds.Tables[0].Rows[0]["v4"].ToString() != "")
                {
                    model.v4 = ds.Tables[0].Rows[0]["v4"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.notice model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update notice set ");
            strSql.Append("title=@title,");
            strSql.Append("summary=@summary,");
            strSql.Append("intro=@intro,");
            strSql.Append("notice_content=@notice_content,");
            strSql.Append("UpdateUserID=@UpdateUserID,");
            strSql.Append("UpdateTime=@UpdateTime,");
            strSql.Append("url=@url,");
            strSql.Append("show=@show,");
            strSql.Append("status=@status,");
            strSql.Append("v1=@v1,");
            strSql.Append("v2=@v2,");
            strSql.Append("v3=@v3,");
            strSql.Append("v4=@v4");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@title",          SqlDbType.NVarChar),
                new SqlParameter("@summary",        SqlDbType.NVarChar),
                new SqlParameter("@intro",          SqlDbType.NVarChar),
                new SqlParameter("@notice_content", SqlDbType.NVarChar),
                new SqlParameter("@UpdateUserID",   SqlDbType.BigInt,      8),
                new SqlParameter("@UpdateTime",     SqlDbType.DateTime),
                new SqlParameter("@url",            SqlDbType.NVarChar,  400),
                new SqlParameter("@show",           SqlDbType.Int,         4),
                new SqlParameter("@status",         SqlDbType.Int,         4),
                new SqlParameter("@v1",             SqlDbType.NVarChar,  500),
                new SqlParameter("@v2",             SqlDbType.NVarChar,  500),
                new SqlParameter("@v3",             SqlDbType.NVarChar,  500),
                new SqlParameter("@v4",             SqlDbType.NVarChar,  500),
                new SqlParameter("@id",             SqlDbType.Int, 4)
            };
            parameters[0].Value  = model.title;
            parameters[1].Value  = model.summary;
            parameters[2].Value  = model.intro;
            parameters[3].Value  = model.notice_content;
            parameters[4].Value  = model.UpdateUserID;
            parameters[5].Value  = model.UpdateTime;
            parameters[6].Value  = model.url;
            parameters[7].Value  = model.show;
            parameters[8].Value  = model.status;
            parameters[9].Value  = model.v1;
            parameters[10].Value = model.v2;
            parameters[11].Value = model.v3;
            parameters[12].Value = model.v4;
            parameters[13].Value = model.id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }