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
{
///
/// 数据访问类:T_Rec_RegRecords
///
public partial class T_Rec_RegRecords
{
public T_Rec_RegRecords()
{ }
#region Method
///
/// 是否存在该记录
///
public bool Exists(int F_ID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from T_Rec_RegRecords");
strSql.Append(" where F_ID=@F_ID");
SqlParameter[] parameters = {
new SqlParameter("@F_ID", SqlDbType.Int,4)
};
parameters[0].Value = F_ID;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
///
/// 增加一条数据
///
public int Add(CallCenterApi.Model.T_Rec_RegRecords model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into T_Rec_RegRecords(");
strSql.Append("F_RecCode,F_CusID,F_Type,F_Direction,F_Complained,F_Content,F_Remark,F_CreateBy,F_CreateOn,F_IsDelete,F_DeleteOn,F_DeleteBy,F_Tel,F_CallId)");
strSql.Append(" values (");
strSql.Append("@F_RecCode,@F_CusID,@F_Type,@F_Direction,@F_Complained,@F_Content,@F_Remark,@F_CreateBy,@F_CreateOn,@F_IsDelete,@F_DeleteOn,@F_DeleteBy,@F_Tel,@F_CallId)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@F_RecCode", SqlDbType.NVarChar,50),
new SqlParameter("@F_CusID", SqlDbType.Int,4),
new SqlParameter("@F_Type", SqlDbType.Int,4),
new SqlParameter("@F_Direction", SqlDbType.Int,4),
new SqlParameter("@F_Complained", SqlDbType.VarChar,2000),
new SqlParameter("@F_Content", SqlDbType.VarChar),
new SqlParameter("@F_Remark", SqlDbType.VarChar),
new SqlParameter("@F_CreateBy", SqlDbType.VarChar,50),
new SqlParameter("@F_CreateOn", SqlDbType.DateTime),
new SqlParameter("@F_IsDelete", SqlDbType.Int,4),
new SqlParameter("@F_DeleteOn", SqlDbType.VarChar,50),
new SqlParameter("@F_DeleteBy", SqlDbType.DateTime),
new SqlParameter("@F_Tel", SqlDbType.VarChar,200),
new SqlParameter("@F_CallId", SqlDbType.VarChar,50)
};
parameters[0].Value = model.F_RecCode;
parameters[1].Value = model.F_CusID;
parameters[2].Value = model.F_Type;
parameters[3].Value = model.F_Direction;
parameters[4].Value = model.F_Complained;
parameters[5].Value = model.F_Content;
parameters[6].Value = model.F_Remark;
parameters[7].Value = model.F_CreateBy;
parameters[8].Value = model.F_CreateOn;
parameters[9].Value = model.F_IsDelete;
parameters[10].Value = model.F_DeleteOn;
parameters[11].Value = model.F_DeleteBy;
parameters[12].Value = model.F_Tel;
parameters[13].Value = model.F_CallId;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
///
/// 更新一条数据
///
public bool Update(CallCenterApi.Model.T_Rec_RegRecords model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update T_Rec_RegRecords set ");
strSql.Append("F_RecCode=@F_RecCode,");
strSql.Append("F_CusID=@F_CusID,");
strSql.Append("F_Type=@F_Type,");
strSql.Append("F_Direction=@F_Direction,");
strSql.Append("F_Complained=@F_Complained,");
strSql.Append("F_Content=@F_Content,");
strSql.Append("F_Remark=@F_Remark,");
strSql.Append("F_CreateBy=@F_CreateBy,");
strSql.Append("F_CreateOn=@F_CreateOn,");
strSql.Append("F_IsDelete=@F_IsDelete,");
strSql.Append("F_DeleteOn=@F_DeleteOn,");
strSql.Append("F_DeleteBy=@F_DeleteBy,");
strSql.Append("F_Tel=@F_Tel,");
strSql.Append("F_CallId=@F_CallId");
strSql.Append(" where F_ID=@F_ID");
SqlParameter[] parameters = {
new SqlParameter("@F_RecCode", SqlDbType.NVarChar,50),
new SqlParameter("@F_CusID", SqlDbType.Int,4),
new SqlParameter("@F_Type", SqlDbType.Int,4),
new SqlParameter("@F_Direction", SqlDbType.Int,4),
new SqlParameter("@F_Complained", SqlDbType.VarChar,2000),
new SqlParameter("@F_Content", SqlDbType.VarChar),
new SqlParameter("@F_Remark", SqlDbType.VarChar),
new SqlParameter("@F_CreateBy", SqlDbType.VarChar,50),
new SqlParameter("@F_CreateOn", SqlDbType.DateTime),
new SqlParameter("@F_IsDelete", SqlDbType.Int,4),
new SqlParameter("@F_DeleteOn", SqlDbType.VarChar,50),
new SqlParameter("@F_DeleteBy", SqlDbType.DateTime),
new SqlParameter("@F_Tel", SqlDbType.VarChar,200),
new SqlParameter("@F_CallId", SqlDbType.VarChar,50),
new SqlParameter("@F_ID", SqlDbType.Int,4)};
parameters[0].Value = model.F_RecCode;
parameters[1].Value = model.F_CusID;
parameters[2].Value = model.F_Type;
parameters[3].Value = model.F_Direction;
parameters[4].Value = model.F_Complained;
parameters[5].Value = model.F_Content;
parameters[6].Value = model.F_Remark;
parameters[7].Value = model.F_CreateBy;
parameters[8].Value = model.F_CreateOn;
parameters[9].Value = model.F_IsDelete;
parameters[10].Value = model.F_DeleteOn;
parameters[11].Value = model.F_DeleteBy;
parameters[12].Value = model.F_Tel;
parameters[13].Value = model.F_CallId;
parameters[14].Value = model.F_ID;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
///
/// 删除一条数据
///
public bool Delete(int F_ID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from T_Rec_RegRecords ");
strSql.Append(" where F_ID=@F_ID");
SqlParameter[] parameters = {
new SqlParameter("@F_ID", SqlDbType.Int,4)
};
parameters[0].Value = F_ID;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
///
/// 批量删除数据
///
public bool DeleteList(string F_IDlist)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from T_Rec_RegRecords ");
strSql.Append(" where F_ID in (" + F_IDlist + ") ");
int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
///
/// 得到一个对象实体
///
public CallCenterApi.Model.T_Rec_RegRecords GetModel(int F_ID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 * from T_Rec_RegRecords ");
strSql.Append(" where F_ID=@F_ID");
SqlParameter[] parameters = {
new SqlParameter("@F_ID", SqlDbType.Int,4)
};
parameters[0].Value = F_ID;
CallCenterApi.Model.T_Rec_RegRecords model = new CallCenterApi.Model.T_Rec_RegRecords();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
return DataRowToModel(ds.Tables[0].Rows[0]);
}
else
{
return null;
}
}
///
/// 得到一个对象实体
///
public CallCenterApi.Model.T_Rec_RegRecords DataRowToModel(DataRow row)
{
CallCenterApi.Model.T_Rec_RegRecords model = new CallCenterApi.Model.T_Rec_RegRecords();
if (row != null)
{
if (row["F_ID"] != null && row["F_ID"].ToString() != "")
{
model.F_ID = int.Parse(row["F_ID"].ToString());
}
if (row["F_RecCode"] != null && row["F_RecCode"].ToString() != "")
{
model.F_RecCode = row["F_RecCode"].ToString();
}
if (row["F_CusID"] != null && row["F_CusID"].ToString() != "")
{
model.F_CusID = int.Parse(row["F_CusID"].ToString());
}
if (row["F_Type"] != null && row["F_Type"].ToString() != "")
{
model.F_Type = int.Parse(row["F_Type"].ToString());
}
if (row["F_Direction"] != null && row["F_Direction"].ToString() != "")
{
model.F_Direction = int.Parse(row["F_Direction"].ToString());
}
if (row["F_Complained"] != null && row["F_Complained"].ToString() != "")
{
model.F_Complained = row["F_Complained"].ToString();
}
if (row["F_Content"] != null && row["F_Content"].ToString() != "")
{
model.F_Content = row["F_Content"].ToString();
}
if (row["F_Remark"] != null && row["F_Remark"].ToString() != "")
{
model.F_Remark = row["F_Remark"].ToString();
}
if (row["F_CreateBy"] != null && row["F_CreateBy"].ToString() != "")
{
model.F_CreateBy = row["F_CreateBy"].ToString();
}
if (row["F_CreateOn"] != null && row["F_CreateOn"].ToString() != "")
{
model.F_CreateOn = DateTime.Parse(row["F_CreateOn"].ToString());
}
if (row["F_IsDelete"] != null && row["F_IsDelete"].ToString() != "")
{
model.F_IsDelete = int.Parse(row["F_IsDelete"].ToString());
}
if (row["F_DeleteOn"] != null && row["F_DeleteOn"].ToString() != "")
{
model.F_DeleteOn = row["F_DeleteOn"].ToString();
}
if (row["F_DeleteBy"] != null && row["F_DeleteBy"].ToString() != "")
{
model.F_DeleteBy = DateTime.Parse(row["F_DeleteBy"].ToString());
}
if (row["F_Tel"] != null && row["F_Tel"].ToString() != "")
{
model.F_Tel = row["F_Tel"].ToString();
}
if (row["F_CallId"] != null && row["F_CallId"].ToString() != "")
{
model.F_CallId = row["F_CallId"].ToString();
}
}
return model;
}
///
/// 获得数据列表
///
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * ");
strSql.Append(" FROM T_Rec_RegRecords ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
return DbHelperSQL.Query(strSql.ToString());
}
///
/// 获得前几行数据
///
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 T_Rec_RegRecords ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
///
/// 获取记录总数
///
public int GetRecordCount(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) FROM T_Rec_RegRecords ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
object obj = DbHelperSQL.GetSingle(strSql.ToString());
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
///
/// 分页获取数据列表
///
public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("SELECT * FROM ( ");
strSql.Append(" SELECT ROW_NUMBER() OVER (");
if (!string.IsNullOrEmpty(orderby.Trim()))
{
strSql.Append("order by T." + orderby);
}
else
{
strSql.Append("order by T.F_ID desc");
}
strSql.Append(")AS Row, T.* from T_Rec_RegRecords T ");
if (!string.IsNullOrEmpty(strWhere.Trim()))
{
strSql.Append(" WHERE " + strWhere);
}
strSql.Append(" ) TT");
strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
return DbHelperSQL.Query(strSql.ToString());
}
#endregion Method
}
}