Files
g.hnyhua.cn/Mtxfw.DAL/Article.cs
2026-02-07 15:48:27 +08:00

588 lines
26 KiB
C#

using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Mtxfw.DAL
{
/// <summary>
/// 数据访问类:Article
/// </summary>
public partial class Article : Mtxfw.Utility.Myabstract
{
public Article() : base("Article") { }
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Mtxfw.Model.Article model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into Article(");
strSql.Append("senderid,receiverid,Title,AddTime,Author,Content,Content2,CategoryId,ParentID,Paths,Paths2,KeyWords,media_id,thumb_media_id,wtype,wtype2,LinkID,Seef,gtype)");
strSql.Append(" values (");
strSql.Append("@senderid,@receiverid,@Title,@AddTime,@Author,@Content,@Content2,@CategoryId,@ParentID,@Paths,@Paths2,@KeyWords,@media_id,@thumb_media_id,@wtype,@wtype2,@LinkID,@Seef,@gtype)");
strSql.Append(";select SCOPE_IDENTITY()");
SqlParameter[] parameters = {
new SqlParameter("@senderid", SqlDbType.Int),
new SqlParameter("@receiverid", SqlDbType.Int),
new SqlParameter("@Title", SqlDbType.VarChar,200),
new SqlParameter("@AddTime", SqlDbType.DateTime),
new SqlParameter("@Author", SqlDbType.VarChar,250),
new SqlParameter("@Content", SqlDbType.Text),
new SqlParameter("@Content2", SqlDbType.Text),
new SqlParameter("@CategoryId", SqlDbType.VarChar,50),
new SqlParameter("@ParentID", SqlDbType.Int,4),
new SqlParameter("@Paths", SqlDbType.VarChar,8000),
new SqlParameter("@Paths2", SqlDbType.VarChar,250),
new SqlParameter("@KeyWords", SqlDbType.VarChar,250),
new SqlParameter("@media_id", SqlDbType.VarChar,250),
new SqlParameter("@thumb_media_id", SqlDbType.VarChar,250),
new SqlParameter("@wtype", SqlDbType.Int,4),
new SqlParameter("@wtype2", SqlDbType.Int,4),
new SqlParameter("@LinkID", SqlDbType.Int,4),
new SqlParameter("@Seef", SqlDbType.Int,4),
new SqlParameter("@gtype", SqlDbType.Int)};
parameters[0].Value = model.senderid;
parameters[1].Value = model.receiverid;
parameters[2].Value = model.Title;
parameters[3].Value = model.AddTime;
parameters[4].Value = model.Author;
parameters[5].Value = model.Content;
parameters[6].Value = model.Content2;
parameters[7].Value = model.CategoryId;
parameters[8].Value = model.ParentID;
parameters[9].Value = model.Paths;
parameters[10].Value = model.Paths2;
parameters[11].Value = model.KeyWords;
parameters[12].Value = model.media_id;
parameters[13].Value = model.thumb_media_id;
parameters[14].Value = model.wtype;
parameters[15].Value = model.wtype2;
parameters[16].Value = model.LinkID;
parameters[17].Value = model.Seef;
parameters[18].Value = model.gtype;
string obj = Mtxfw.Utility.SqlDbHelper_U.GetObject(strSql.ToString(), parameters).ToString();
if (obj == "")
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public void Update(Mtxfw.Model.Article model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update Article set ");
strSql.Append("senderid=@senderid,");
strSql.Append("receiverid=@receiverid,");
strSql.Append("Title=@Title,");
strSql.Append("AddTime=@AddTime,");
strSql.Append("Author=@Author,");
strSql.Append("Content=@Content,");
strSql.Append("Content2=@Content2,");
strSql.Append("CategoryId=@CategoryId,");
strSql.Append("ParentID=@ParentID,");
strSql.Append("Paths=@Paths,");
strSql.Append("Paths2=@Paths2,");
strSql.Append("KeyWords=@KeyWords,");
strSql.Append("media_id=@media_id,");
strSql.Append("thumb_media_id=@thumb_media_id,");
strSql.Append("jlsecond=@jlsecond,");
strSql.Append("xfjmoney=@xfjmoney,");
strSql.Append("tfllmoney=@tfllmoney,");
strSql.Append("zscs=@zscs,");
strSql.Append("gxzmoney=@gxzmoney,");
strSql.Append("ltype=@ltype,");
strSql.Append("csday=@csday,");
strSql.Append("latitude=@latitude,");
strSql.Append("longitude=@longitude,");
strSql.Append("wtype=@wtype,");
strSql.Append("wtype2=@wtype2,");
strSql.Append("LinkID=@LinkID,");
strSql.Append("Seef=@Seef");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@senderid", SqlDbType.Int),
new SqlParameter("@receiverid", SqlDbType.Int),
new SqlParameter("@Title", SqlDbType.VarChar,200),
new SqlParameter("@AddTime", SqlDbType.DateTime),
new SqlParameter("@Author", SqlDbType.VarChar,250),
new SqlParameter("@Content", SqlDbType.Text),
new SqlParameter("@Content2", SqlDbType.Text),
new SqlParameter("@CategoryId", SqlDbType.VarChar,50),
new SqlParameter("@ParentID", SqlDbType.Int,4),
new SqlParameter("@Paths", SqlDbType.VarChar,8000),
new SqlParameter("@Paths2", SqlDbType.VarChar,250),
new SqlParameter("@KeyWords", SqlDbType.VarChar,250),
new SqlParameter("@media_id", SqlDbType.VarChar,250),
new SqlParameter("@thumb_media_id", SqlDbType.VarChar,250),
new SqlParameter("@jlsecond", SqlDbType.Int,4),
new SqlParameter("@xfjmoney", SqlDbType.Money),
new SqlParameter("@tfllmoney", SqlDbType.Money),
new SqlParameter("@zscs", SqlDbType.Int,4),
new SqlParameter("@gxzmoney", SqlDbType.Money),
new SqlParameter("@ltype", SqlDbType.Int,4),
new SqlParameter("@csday", SqlDbType.Int,4),
new SqlParameter("@latitude", SqlDbType.Decimal),
new SqlParameter("@longitude", SqlDbType.Decimal),
new SqlParameter("@wtype", SqlDbType.Int,4),
new SqlParameter("@wtype2", SqlDbType.Int,4),
new SqlParameter("@Seef", SqlDbType.Int,4),
new SqlParameter("@LinkID", SqlDbType.Int,4),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.senderid;
parameters[1].Value = model.receiverid;
parameters[2].Value = model.Title;
parameters[3].Value = model.AddTime;
parameters[4].Value = model.Author;
parameters[5].Value = model.Content;
parameters[6].Value = model.Content2;
parameters[7].Value = model.CategoryId;
parameters[8].Value = model.ParentID;
parameters[9].Value = model.Paths;
parameters[10].Value = model.Paths2;
parameters[11].Value = model.KeyWords;
parameters[12].Value = model.media_id;
parameters[13].Value = model.thumb_media_id;
parameters[14].Value = model.jlsecond;
parameters[15].Value = model.xfjmoney;
parameters[16].Value = model.tfllmoney;
parameters[17].Value = model.zscs;
parameters[18].Value = model.gxzmoney;
parameters[19].Value = model.ltype;
parameters[20].Value = model.csday;
parameters[21].Value = model.latitude;
parameters[22].Value = model.longitude;
parameters[23].Value = model.wtype;
parameters[24].Value = model.wtype2;
parameters[25].Value = model.Seef;
parameters[26].Value = model.LinkID;
parameters[27].Value = model.id;
Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool UpdateuSel(string Sel, int SelValue, int Id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update Article set ");
strSql.Append(Sel + "=@SelValue");
strSql.Append(" where Id=@Id");
SqlParameter[] parameters = {
new SqlParameter("@SelValue", SqlDbType.Int),
new SqlParameter("@Id", SqlDbType.Int)};
parameters[0].Value = SelValue;
parameters[1].Value = Id;
int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool UpdateuSel(string Sel, int SelValue, string where)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update Article set ");
strSql.Append(Sel + "=@SelValue");
strSql.Append(" where " + where);
SqlParameter[] parameters = {
new SqlParameter("@SelValue", SqlDbType.Int)};
parameters[0].Value = SelValue;
int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool UpdateuSel0(string Sel, int SelValue, int Id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update Article set ");
strSql.Append(Sel + "=" + Sel + "+@SelValue");
strSql.Append(" where Id=@Id");
SqlParameter[] parameters = {
new SqlParameter("@SelValue", SqlDbType.Int),
new SqlParameter("@Id", SqlDbType.Int)};
parameters[0].Value = SelValue;
parameters[1].Value = Id;
int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Updatecategoryid(string categoryid)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update Article set ");
strSql.Append("categoryid=@categoryid");
strSql.Append(" where parentid=16 And categoryid='0'");
SqlParameter[] parameters = {
new SqlParameter("@categoryid", SqlDbType.VarChar,50)};
parameters[0].Value = categoryid;
int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool UpdateuSel(string Sel, int SelValue, int parentid, int UserId, int Id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update Article set ");
strSql.Append(Sel + "=@SelValue");
strSql.Append(" where parentid=@parentid And UserId=@UserId And Id=@Id");
SqlParameter[] parameters = {
new SqlParameter("@SelValue", SqlDbType.Int),
new SqlParameter("@parentid", SqlDbType.Int),
new SqlParameter("@UserId", SqlDbType.Int),
new SqlParameter("@Id", SqlDbType.Int)};
parameters[0].Value = SelValue;
parameters[1].Value = parentid;
parameters[2].Value = UserId;
parameters[3].Value = Id;
int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool UpdateuSeef()
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update Article set ");
strSql.Append("Seef=0");
strSql.Append(" where (ParentID=18 Or ParentID=19) And Seef=1");
int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString());
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete2(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from Article ");
strSql.Append(" where (parentid=22 And (id=@id or CategoryId=@id)) Or (parentid=23 And CategoryId=@id)");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)
};
parameters[0].Value = id;
int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from Article ");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)
};
parameters[0].Value = id;
int rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Mtxfw.Model.Article GetModel(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 * from Article ");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)
};
parameters[0].Value = id;
Mtxfw.Model.Article model = new Mtxfw.Model.Article();
DataSet ds = Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["id"].ToString() != "")
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (ds.Tables[0].Rows[0]["senderid"].ToString() != "")
{
model.senderid = int.Parse(ds.Tables[0].Rows[0]["senderid"].ToString());
}
if (ds.Tables[0].Rows[0]["receiverid"].ToString() != "")
{
model.receiverid = int.Parse(ds.Tables[0].Rows[0]["receiverid"].ToString());
}
model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
if (ds.Tables[0].Rows[0]["AddTime"].ToString() != "")
{
model.AddTime = DateTime.Parse(ds.Tables[0].Rows[0]["AddTime"].ToString());
}
model.Author = ds.Tables[0].Rows[0]["Author"].ToString();
model.Content = ds.Tables[0].Rows[0]["Content"].ToString();
model.Content2 = ds.Tables[0].Rows[0]["Content2"].ToString();
model.CategoryId = ds.Tables[0].Rows[0]["CategoryId"].ToString();
if (ds.Tables[0].Rows[0]["ParentID"].ToString() != "")
{
model.ParentID = int.Parse(ds.Tables[0].Rows[0]["ParentID"].ToString());
}
model.hasRead = int.Parse(ds.Tables[0].Rows[0]["hasRead"].ToString());
if (ds.Tables[0].Rows[0]["Seef"].ToString() != "")
{
model.Seef = int.Parse(ds.Tables[0].Rows[0]["Seef"].ToString());
}
if (ds.Tables[0].Rows[0]["LinkID"].ToString() != "")
{
model.LinkID = int.Parse(ds.Tables[0].Rows[0]["LinkID"].ToString());
}
model.Paths = ds.Tables[0].Rows[0]["Paths"].ToString();
model.Paths2 = ds.Tables[0].Rows[0]["Paths2"].ToString();
model.KeyWords = ds.Tables[0].Rows[0]["KeyWords"].ToString();
model.media_id = ds.Tables[0].Rows[0]["media_id"].ToString();
model.thumb_media_id = ds.Tables[0].Rows[0]["thumb_media_id"].ToString();
model.jlsecond = Convert.ToInt32(ds.Tables[0].Rows[0]["jlsecond"].ToString());
model.xfjmoney = Convert.ToDouble(ds.Tables[0].Rows[0]["xfjmoney"].ToString());
model.tfllmoney = Convert.ToDouble(ds.Tables[0].Rows[0]["tfllmoney"].ToString());
model.zscs = Convert.ToInt32(ds.Tables[0].Rows[0]["zscs"].ToString());
model.gxzmoney = Convert.ToDouble(ds.Tables[0].Rows[0]["gxzmoney"].ToString());
model.ltype = Convert.ToInt32(ds.Tables[0].Rows[0]["ltype"].ToString());
model.csday = Convert.ToInt32(ds.Tables[0].Rows[0]["csday"].ToString());
model.latitude = Convert.ToDecimal(ds.Tables[0].Rows[0]["latitude"].ToString());
model.longitude = Convert.ToDecimal(ds.Tables[0].Rows[0]["longitude"].ToString());
if (ds.Tables[0].Rows[0]["wtype"].ToString() != "")
{
model.wtype = int.Parse(ds.Tables[0].Rows[0]["wtype"].ToString());
}
if (ds.Tables[0].Rows[0]["wtype2"].ToString() != "")
{
model.wtype2 = int.Parse(ds.Tables[0].Rows[0]["wtype2"].ToString());
}
model.IFTJ = Convert.ToInt32(ds.Tables[0].Rows[0]["IFTJ"].ToString());
model.IFTop = Convert.ToInt32(ds.Tables[0].Rows[0]["IFTop"].ToString());
model.gtype = int.Parse(ds.Tables[0].Rows[0]["gtype"].ToString());
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获取上一条记录
/// </summary>
public Mtxfw.Model.Article GetMinModel(int gtype, int id, int ParentID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 * from Article ");
strSql.Append(" where gtype=@gtype and id>@id and ParentID=@ParentID order by id desc");
SqlParameter[] parameters = { new SqlParameter("@gtype", SqlDbType.Int, 4),
new SqlParameter("@id", SqlDbType.Int, 4),
new SqlParameter("@ParentID", SqlDbType.Int, 4) };
parameters[0].Value = gtype;
parameters[1].Value = id;
parameters[2].Value = ParentID;
Mtxfw.Model.Article model = new Mtxfw.Model.Article();
DataSet ds = Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["id"].ToString() != "")
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (ds.Tables[0].Rows[0]["senderid"].ToString() != "")
{
model.senderid = int.Parse(ds.Tables[0].Rows[0]["senderid"].ToString());
}
if (ds.Tables[0].Rows[0]["receiverid"].ToString() != "")
{
model.receiverid = int.Parse(ds.Tables[0].Rows[0]["receiverid"].ToString());
}
model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
if (ds.Tables[0].Rows[0]["AddTime"].ToString() != "")
{
model.AddTime = DateTime.Parse(ds.Tables[0].Rows[0]["AddTime"].ToString());
}
model.Author = ds.Tables[0].Rows[0]["Author"].ToString();
model.Content = ds.Tables[0].Rows[0]["Content"].ToString();
model.CategoryId = ds.Tables[0].Rows[0]["CategoryId"].ToString();
if (ds.Tables[0].Rows[0]["ParentID"].ToString() != "")
{
model.ParentID = int.Parse(ds.Tables[0].Rows[0]["ParentID"].ToString());
}
model.hasRead = int.Parse(ds.Tables[0].Rows[0]["hasRead"].ToString());
if (ds.Tables[0].Rows[0]["Seef"].ToString() != "")
{
model.Seef = int.Parse(ds.Tables[0].Rows[0]["Seef"].ToString());
}
model.gtype = int.Parse(ds.Tables[0].Rows[0]["gtype"].ToString());
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获取下一条记录
/// </summary>
public Mtxfw.Model.Article GetMaxModel(int gtype, int id, int ParentID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 * from Article ");
strSql.Append(" where gtype=@gtype and id<@id and ParentID=@ParentID order by id asc");
SqlParameter[] parameters = { new SqlParameter("@gtype", SqlDbType.Int, 4),
new SqlParameter("@id", SqlDbType.Int, 4),
new SqlParameter("@ParentID", SqlDbType.Int, 4) };
parameters[0].Value = gtype;
parameters[1].Value = id;
parameters[2].Value = ParentID;
Mtxfw.Model.Article model = new Mtxfw.Model.Article();
DataSet ds = Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["id"].ToString() != "")
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (ds.Tables[0].Rows[0]["senderid"].ToString() != "")
{
model.senderid = int.Parse(ds.Tables[0].Rows[0]["senderid"].ToString());
}
if (ds.Tables[0].Rows[0]["receiverid"].ToString() != "")
{
model.receiverid = int.Parse(ds.Tables[0].Rows[0]["receiverid"].ToString());
}
model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
if (ds.Tables[0].Rows[0]["AddTime"].ToString() != "")
{
model.AddTime = DateTime.Parse(ds.Tables[0].Rows[0]["AddTime"].ToString());
}
model.Author = ds.Tables[0].Rows[0]["Author"].ToString();
model.Content = ds.Tables[0].Rows[0]["Content"].ToString();
model.CategoryId = ds.Tables[0].Rows[0]["CategoryId"].ToString();
if (ds.Tables[0].Rows[0]["ParentID"].ToString() != "")
{
model.ParentID = int.Parse(ds.Tables[0].Rows[0]["ParentID"].ToString());
}
model.hasRead = int.Parse(ds.Tables[0].Rows[0]["hasRead"].ToString());
if (ds.Tables[0].Rows[0]["Seef"].ToString() != "")
{
model.Seef = int.Parse(ds.Tables[0].Rows[0]["Seef"].ToString());
}
model.gtype = int.Parse(ds.Tables[0].Rows[0]["gtype"].ToString());
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * ");
strSql.Append(" FROM Article ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString());
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append(" * ");
strSql.Append(" FROM Article ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString());
}
}
}