Example #1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public XHD.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;

            XHD.Model.public_notice model = new XHD.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);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(XHD.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("receive_id=@receive_id,");
            strSql.Append("receive_name=@receive_name");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@notice_title",   MySqlDbType.VarChar,   200),
                new MySqlParameter("@notice_content", MySqlDbType.VarChar),
                new MySqlParameter("@create_id",      MySqlDbType.Int32,       4),
                new MySqlParameter("@create_name",    MySqlDbType.VarChar,    50),
                new MySqlParameter("@dep_id",         MySqlDbType.Int32,       4),
                new MySqlParameter("@dep_name",       MySqlDbType.VarChar,    50),
                new MySqlParameter("@notice_time",    MySqlDbType.DateTime),
                new MySqlParameter("@receive_id",     MySqlDbType.VarChar,    -1),
                new MySqlParameter("@receive_name",   MySqlDbType.VarChar,    -1),
                new MySqlParameter("@id",             MySqlDbType.Int32, 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.receive_id;
            parameters[8].Value = model.receive_name;
            parameters[9].Value = model.id;

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

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

            strSql.Append("insert into public_notice(");
            strSql.Append("Factory_Id,notice_title,notice_content,create_id,create_name,dep_id,dep_name,notice_time,receive_id,receive_name)");
            strSql.Append(" values (");
            strSql.Append("@Factory_Id,@notice_title,@notice_content,@create_id,@create_name,@dep_id,@dep_name,@notice_time,@receive_id,@receive_name)");
            strSql.Append(";select @@IDENTITY");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("Factory_Id",      MySqlDbType.VarChar,    60),
                new MySqlParameter("@notice_title",   MySqlDbType.VarChar,   200),
                new MySqlParameter("@notice_content", MySqlDbType.VarChar,    -1),
                new MySqlParameter("@create_id",      MySqlDbType.Int32,       4),
                new MySqlParameter("@create_name",    MySqlDbType.VarChar,    50),
                new MySqlParameter("@dep_id",         MySqlDbType.Int32,       4),
                new MySqlParameter("@dep_name",       MySqlDbType.VarChar,    50),
                new MySqlParameter("@notice_time",    MySqlDbType.DateTime),
                new MySqlParameter("@receive_id",     MySqlDbType.VarChar,    -1),
                new MySqlParameter("@receive_name",   MySqlDbType.VarChar, -1)
            };
            parameters[0].Value = model.Factory_Id;
            parameters[1].Value = model.notice_title;
            parameters[2].Value = model.notice_content;
            parameters[3].Value = model.create_id;
            parameters[4].Value = model.create_name;
            parameters[5].Value = model.dep_id;
            parameters[6].Value = model.dep_name;
            parameters[7].Value = model.notice_time;
            parameters[8].Value = model.receive_id;
            parameters[9].Value = model.receive_name;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Example #4
0
        /// <summary>
        /// �õ�һ������ʵ��
        /// </summary>
        public XHD.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;

            XHD.Model.public_notice model=new XHD.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;
            }
        }