⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 infooperate.cs

📁 在线图书馆
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Info 的摘要说明
/// </summary>
public class InfoOperate
{
	public InfoOperate()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    public string getInfoList(string table, string keyid, ref DataSet ds, string dsName, string kindName)
    {
        //获取信息列表
        dataOperate dbop = new dataOperate();
        string sRet = "";
        string sql = "select * from " + table;
        switch (kindName)
        {
            case "news": sql += " where INKind = '新闻'"; break;
            case "notice": sql += " where INKind = '通知'"; break;
            case "broad": sql += " where INKind = '公告'"; break;
            default: break;
        }
        sql += " order by " + keyid + " desc";
        sRet = dbop.GetDataSet(sql, ref ds, dsName);
        return sRet;
    }

    public string getInfoList(string table, string keyid, ref DataSet ds, string dsName, string kindName, int count)
    {
        //获取信息列表重载1
        dataOperate dbop = new dataOperate();
        string sRet = "";
        string sql = "select top " + count + " * from " + table;
        switch (kindName)
        {
            case "news": sql += " where INKind = '新闻'"; break;
            case "notice": sql += " where INKind = '通知'"; break;
            case "broad": sql += " where INKind = '公告'"; break;
            default: break;
        }
        sql += " order by " + keyid + " desc";
        sRet = dbop.GetDataSet(sql, ref ds, dsName);
        return sRet;
    }

    public string addNewMsg(string author, string text, int reply, string ip)
    {
        //发表留言
        SqlConnection con = DB.CreateConnection();
        con.Open();
        string sRet = "";
        string sql = "insert into messageboard(MBAuthor, MBContext, MBReID, MBIP) values('" + author + "', '" + text + "', " + reply + ", '" + ip + "')";
        SqlCommand cmd = new SqlCommand(sql, con);
        if (cmd.ExecuteNonQuery() > 0)
        {
        }
        else
        {
            sRet = "留言失败,请重新尝试...";
        }
        con.Close();
        return sRet;
    }

    public string addNews(string kind, string title, string context, string UserID, string offdate)
    {
        //发布新闻
        SqlConnection con = DB.CreateConnection();
        con.Open();
        string sRet = "";
        string sql = "insert into infonews(INKind, INTitle, INContext, UserID, INOffDate) values('" +kind + "','" + title + "', '" + context + "','" + UserID + "','" + offdate + "')";
        SqlCommand cmd = new SqlCommand(sql, con);
        if (cmd.ExecuteNonQuery() > 0)
        {
        }
        else
        {
            sRet = "发布新闻失败,请重新尝试...";
        }
        con.Close();
        return sRet;
    }

    public string viewNews2(string newsID, ref DataSet ds, string dsName)
    {
        //查看新闻
        dataOperate dbop = new dataOperate();
        string sRet = "";
        string sql = "select * from Infonews where INID = " + newsID;
        sRet = dbop.GetDataSet(sql, ref ds, dsName);
        return sRet;
    }

    public string viewNews(string newsID, ref DataSet ds, string dsName)
    {
        //查看新闻-存储过程版本
        SqlConnection conn = DB.CreateConnection();
        string sRet = "";
        try
        {
            conn.Open();
            SqlDataAdapter sda = new SqlDataAdapter();
            sda.SelectCommand = new SqlCommand();
            sda.SelectCommand.CommandText = "viewNews";
            sda.SelectCommand.CommandType = CommandType.StoredProcedure;
            sda.SelectCommand.Connection = conn;
            SqlParameter sp = new SqlParameter("@newID", SqlDbType.Int);
            sp.Direction = ParameterDirection.Input;
            sp.Value = newsID;
            sda.SelectCommand.Parameters.Add(sp);
            sda.Fill(ds, dsName);
            conn.Close();
        }
        catch (Exception ex)
        {
            sRet = ex.Message.ToString();
        }
        return sRet;
    }

    public static string deleteInfo(int kind, string infoID)
    {
        //删除信息
        ///kind为0表示删除新闻,1表示删除留言
        SqlConnection con = DB.CreateConnection();
        con.Open();

        string sql = "";
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        if(kind == 0)
        {
            //删除新闻
            sql = "delete InfoNews where INID = " + infoID;
        }
        else if(kind == 1)
        {
            //删除留言
            sql = "delete messageboard where MBID = " + infoID;
        }
        cmd.CommandText = sql;
        if(cmd.ExecuteNonQuery()>0)
        {
            con.Close();
            return "";
        }
        else
        {
            con.Close();
            return "删除失败,请重新尝试...";
        }
    }

    public string getBookList(ref DataSet ds, string dsName, int count, string state)
    {
        //获取图书列表
        dataOperate dbop = new dataOperate();
        string sRet = "";
        string sql = "select";
        if (count > 0)
        {
            sql += " top " + count;
        }
        sql += " * from booklist inner join bookkind on booklist.bkid = bookkind.bkid";
        if (state == "order")
        {
            sql += " order by booklist.BLid desc";
        }
        sRet = dbop.GetDataSet(sql, ref ds, dsName);
        return sRet;
    }

    public string getBookList(ref DataSet ds, string dsName, int count, string state, string bookKind, string keyname, string text)
    {
        //获取图书列表
        dataOperate dbop = new dataOperate();
        string sRet = "";
        string sql = "select";
        if (count > 0)
        {
            sql += " top " + count;
        }
        sql += " * from booklist inner join bookkind on booklist.bkid = bookkind.bkid where ''=''";
        if (bookKind != "")
        {
            sql += " and bookkind.bkname like '%" + bookKind + "%'";
        }
        if (text != "")
        {
            sql += " and " + keyname + " like '%" + text + "%'";
        }
        if (state == "order")
        {
            sql += " order by booklist.BLid desc";
        }
        sRet = dbop.GetDataSet(sql, ref ds, dsName);
        return sRet;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -