using CallCenterApi.DB;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CallCenterApi.DAL
{
public partial class NewsMassge
{
public NewsMassge()
{ }
///
/// 增加一条数据
///
public int Add(CallCenterApi.Model.NewsMassge model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into NewsMassge(");
strSql.Append("Title,Contents,FabuCode,FabuName,FabuDate");
strSql.Append(") values (");
strSql.Append("@Title,@Contents,@FabuCode,@FabuName,@FabuDate");
strSql.Append(") ");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@Title", SqlDbType.VarChar,100) ,
new SqlParameter("@Contents", SqlDbType.VarChar,100) ,
new SqlParameter("@FabuCode", SqlDbType.VarChar,50 ) ,
new SqlParameter("@FabuName", SqlDbType.VarChar,50) ,
new SqlParameter("@FabuDate", SqlDbType.DateTime)
};
parameters[0].Value = model.Title;
parameters[1].Value = model.Contents;
parameters[2].Value = model.FabuCode;
parameters[3].Value = model.FabuName;
parameters[4].Value = model.FabuDate;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
///
/// 得到一个对象实体
///
public CallCenterApi.Model.NewsMassge GetModel(int ID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * ");
strSql.Append(" from NewsMassge ");
strSql.Append(" where Id=@ID");
SqlParameter[] parameters = {
new SqlParameter("@ID", SqlDbType.Int,4)
};
parameters[0].Value = ID;
CallCenterApi.Model.NewsMassge model = new CallCenterApi.Model.NewsMassge();
DataSet ds = DbHelperSQL.Query(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());
}
model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
model.Contents = ds.Tables[0].Rows[0]["Contents"].ToString();
model.FabuCode = ds.Tables[0].Rows[0]["FabuCode"].ToString();
model.FabuName = ds.Tables[0].Rows[0]["FabuName"].ToString();
if (ds.Tables[0].Rows[0]["FabuDate"].ToString() != "")
{
model.FabuDate = DateTime.Parse(ds.Tables[0].Rows[0]["FabuDate"].ToString());
}
if (ds.Tables[0].Rows[0]["UpdateTime"].ToString() != "")
{
model.FabuDate = DateTime.Parse(ds.Tables[0].Rows[0]["UpdateTime"].ToString());
}
return model;
}
else
{
return null;
}
}
///
/// 删除一条数据
///
public bool Delete(int ID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from NewsMassge ");
strSql.Append(" where Id=@ID");
SqlParameter[] parameters = {
new SqlParameter("@ID", SqlDbType.Int,4)
};
parameters[0].Value = ID;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
///
/// 批量删除数据
///
public bool DeleteList(string IDlist)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from NewsMassge ");
strSql.Append(" where ID in (" + IDlist + ") ");
int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
///
/// 更新一条数据
///
public bool Update(CallCenterApi.Model.NewsMassge model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update NewsMassge set ");
strSql.Append("Title=@Title,");
strSql.Append("Contents=@Contents,");
strSql.Append("UpdateTime=@UpdateTime");
strSql.Append(" where Id=@ID");
SqlParameter[] parameters = {
new SqlParameter("@Title", SqlDbType.VarChar,100),
new SqlParameter("@Contents", SqlDbType.VarChar,1000),
new SqlParameter("@UpdateTime", SqlDbType.DateTime),
new SqlParameter("@ID", SqlDbType.Int,4)};
parameters[0].Value = model.Title;
parameters[1].Value = model.Contents;
parameters[2].Value = model.UpdateTime;
parameters[3].Value = model.Id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
}
}