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

            strSql.Append("select  top 1 id,notice_title,notice_content,create_id,create_name,dep_id,dep_name,notice_time from public_notice ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Garfield.Model.public_notice model = new Garfield.Model.public_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]["notice_title"] != null && ds.Tables[0].Rows[0]["notice_title"].ToString() != "")
                {
                    model.notice_title = ds.Tables[0].Rows[0]["notice_title"].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]["create_id"] != null && ds.Tables[0].Rows[0]["create_id"].ToString() != "")
                {
                    model.create_id = int.Parse(ds.Tables[0].Rows[0]["create_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["create_name"] != null && ds.Tables[0].Rows[0]["create_name"].ToString() != "")
                {
                    model.create_name = ds.Tables[0].Rows[0]["create_name"].ToString();
                }
                if (ds.Tables[0].Rows[0]["dep_id"] != null && ds.Tables[0].Rows[0]["dep_id"].ToString() != "")
                {
                    model.dep_id = int.Parse(ds.Tables[0].Rows[0]["dep_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["dep_name"] != null && ds.Tables[0].Rows[0]["dep_name"].ToString() != "")
                {
                    model.dep_name = ds.Tables[0].Rows[0]["dep_name"].ToString();
                }
                if (ds.Tables[0].Rows[0]["notice_time"] != null && ds.Tables[0].Rows[0]["notice_time"].ToString() != "")
                {
                    model.notice_time = DateTime.Parse(ds.Tables[0].Rows[0]["notice_time"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Garfield.Model.public_notice model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update public_notice set ");
            strSql.Append("notice_title=@notice_title,");
            strSql.Append("notice_content=@notice_content,");
            strSql.Append("create_id=@create_id,");
            strSql.Append("create_name=@create_name,");
            strSql.Append("dep_id=@dep_id,");
            strSql.Append("dep_name=@dep_name,");
            strSql.Append("notice_time=@notice_time");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@notice_title",   SqlDbType.VarChar,   250),
                new SqlParameter("@notice_content", SqlDbType.VarChar),
                new SqlParameter("@create_id",      SqlDbType.Int,         4),
                new SqlParameter("@create_name",    SqlDbType.VarChar,   250),
                new SqlParameter("@dep_id",         SqlDbType.Int,         4),
                new SqlParameter("@dep_name",       SqlDbType.VarChar,   250),
                new SqlParameter("@notice_time",    SqlDbType.DateTime),
                new SqlParameter("@id",             SqlDbType.Int, 4)
            };
            parameters[0].Value = model.notice_title;
            parameters[1].Value = model.notice_content;
            parameters[2].Value = model.create_id;
            parameters[3].Value = model.create_name;
            parameters[4].Value = model.dep_id;
            parameters[5].Value = model.dep_name;
            parameters[6].Value = model.notice_time;
            parameters[7].Value = model.id;

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

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

            strSql.Append("insert into public_notice(");
            strSql.Append("notice_title,notice_content,create_id,create_name,dep_id,dep_name,notice_time)");
            strSql.Append(" values (");
            strSql.Append("@notice_title,@notice_content,@create_id,@create_name,@dep_id,@dep_name,@notice_time)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@notice_title",   SqlDbType.VarChar, 250),
                new SqlParameter("@notice_content", SqlDbType.VarChar,  -1),
                new SqlParameter("@create_id",      SqlDbType.Int,       4),
                new SqlParameter("@create_name",    SqlDbType.VarChar, 250),
                new SqlParameter("@dep_id",         SqlDbType.Int,       4),
                new SqlParameter("@dep_name",       SqlDbType.VarChar, 250),
                new SqlParameter("@notice_time",    SqlDbType.DateTime)
            };
            parameters[0].Value = model.notice_title;
            parameters[1].Value = model.notice_content;
            parameters[2].Value = model.create_id;
            parameters[3].Value = model.create_name;
            parameters[4].Value = model.dep_id;
            parameters[5].Value = model.dep_name;
            parameters[6].Value = model.notice_time;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }