📄 news.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
namespace TBLibrary.Shop.ShopManage
{
/// <summary>
/// News 的摘要说明。
/// </summary>
public class News:TBLibrary.Shop.DbBase.Base
{
public News()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region 添加新闻分类
/// <summary>
/// 添加分类
/// </summary>
/// <param name="compositor"></param>
/// <param name="name"></param>
public static void InsertNewsClassToDB(int compositor,string name)
{
string strSql = "Insert into NewsClass(Compositor,ClassName)Values("+compositor+",'"+name+"')";
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 读取分类信息
/// </summary>
/// <returns></returns>
public static DataView ReadNewsClass()
{
string strSql ="Select * From NewsClass Order by Compositor";
try
{
DataSet ds = new DataSet();
ds = ExecuteSqlDs(strSql);
return ds.Tables[0].DefaultView;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 删除分类信息
/// </summary>
/// <param name="id"></param>
public static void DeleteNewsClass(int id)
{
string strSql ="Delete From NewsClass where ID ="+id;
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 更新分类信息
/// </summary>
/// <param name="id"></param>
/// <param name="className"></param>
/// <param name="compositor"></param>
public static void UpdateNewsClass(int id,string className,int compositor)
{
string strSql="Update NewsClass Set ClassName = '"+className+"',Compositor = "+compositor+" Where ID="+id;
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
#endregion
#region 添加新闻内容
public static void InsertNews(string caption ,string de,string imageUrl,int days,int classID)
{
DateTime dt = DateTime.Now.AddDays(days);
string strSql = "Insert News(Caption,Description,ImageUrl,mature,AddTime,ClassID)Values"
+"('"+caption+"','"+de+"','"+imageUrl+"','"+dt.ToString()+"','"+DateTime.Now.ToString()+"',"+classID+")";
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
#endregion
#region 显示新闻内容
public static DataView ShowSimpleNews()
{
string strSql ="Select * From NewsSimple";
try
{
DataSet ds = new DataSet();
ds = ExecuteSqlDs(strSql);
return ds.Tables[0].DefaultView;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
public static void DeleteNews(int id)
{
string strSql="Delete From News Where ID="+id;
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 查找新闻的标题
/// </summary>
/// <param name="id"></param>
public static DataView ShowNewsCaption(int id)
{
string strSql ="Select ID,Caption From News Where (ClassID="+id+")And(mature>='"+DateTime.Now.ToString()+"')";
try
{
DataSet ds = new DataSet();
ds = ExecuteSqlDs(strSql);
return ds.Tables[0].DefaultView;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 显示新闻详细信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static DataView ShowDetailsMessage(int id)
{
string strSql = "Select * From DetailNewsV Where ID="+id;
try
{
DataSet ds = new DataSet();
ds = ExecuteSqlDs(strSql);
return ds.Tables[0].DefaultView;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 前十名新闻
/// </summary>
/// <returns></returns>
public static DataView ShowTopNews()
{
string strSql="Select top 10 ID,Caption From News Where mature>='"+DateTime.Now.ToString()+"' Order by Hits DESC";
try
{
DataSet ds = new DataSet();
ds = ExecuteSqlDs(strSql);
return ds.Tables[0].DefaultView;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 点击率加1
/// </summary>
/// <param name="id"></param>
public static void AddHits(int id)
{
string strSql ="Update News Set Hits=Hits+1 Where ID="+id;
try
{
ExecuteSql(strSql);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
#endregion
/// <summary>
/// 取得头条头板新闻
/// </summary>
/// <returns></returns>
public static DataView ShowTop1()
{
string strSql = "Select Top 1 * From DetailNewsV Order by Hits DESC";
try
{
DataSet ds = new DataSet();
ds = ExecuteSqlDs(strSql);
return ds.Tables[0].DefaultView;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
//用户凳陆
public static int Login(string userName,string password)
{
string strSql="Select ID From Users Where (userName='"+userName+"')And(password='"+password+"')";
try
{
//bool login;
int i = (int)EexecuteSqlValue(strSql);
//LoginTimes(name);
return i;
}
catch//(Exception ex)
{
//throw new Exception(ex.Message);
return -1;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -