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_Cus_CustomerExpand /// public partial class T_Cus_CustomerExpand { public T_Cus_CustomerExpand() { } #region BasicMethod /// /// 是否存在该记录 /// public bool Exists(Guid F_ExpandId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(1) from T_Cus_CustomerExpand"); strSql.Append(" where F_ExpandId=@F_ExpandId "); SqlParameter[] parameters = { new SqlParameter("@F_ExpandId", SqlDbType.UniqueIdentifier,16) }; parameters[0].Value = F_ExpandId; return DbHelperSQL.Exists(strSql.ToString(), parameters); } /// /// 增加一条数据 /// public bool Add(CallCenterApi.Model.T_Cus_CustomerExpand model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_Cus_CustomerExpand("); strSql.Append("F_ExpandId,F_CustomerId,F_StrExpand1,F_StrExpand2,F_StrExpand3,F_StrExpand4,F_StrExpand5,F_StrExpand6,F_TypeExpand1,F_TypeExpand2,F_IntExpand1,F_IntExpand2,F_TimeExpand1,F_TimeExpand2,F_TextExpand1,F_TextExpand2)"); strSql.Append(" values ("); strSql.Append("@F_ExpandId,@F_CustomerId,@F_StrExpand1,@F_StrExpand2,@F_StrExpand3,@F_StrExpand4,@F_StrExpand5,@F_StrExpand6,@F_TypeExpand1,@F_TypeExpand2,@F_IntExpand1,@F_IntExpand2,@F_TimeExpand1,@F_TimeExpand2,@F_TextExpand1,@F_TextExpand2)"); SqlParameter[] parameters = { new SqlParameter("@F_ExpandId", SqlDbType.UniqueIdentifier,16), new SqlParameter("@F_CustomerId", SqlDbType.UniqueIdentifier,16), new SqlParameter("@F_StrExpand1", SqlDbType.NVarChar,200), new SqlParameter("@F_StrExpand2", SqlDbType.NVarChar,200), new SqlParameter("@F_StrExpand3", SqlDbType.NVarChar,200), new SqlParameter("@F_StrExpand4", SqlDbType.NVarChar,200), new SqlParameter("@F_StrExpand5", SqlDbType.NVarChar,200), new SqlParameter("@F_StrExpand6", SqlDbType.NVarChar,200), new SqlParameter("@F_TypeExpand1", SqlDbType.NVarChar,50), new SqlParameter("@F_TypeExpand2", SqlDbType.NVarChar,50), new SqlParameter("@F_IntExpand1", SqlDbType.Int,4), new SqlParameter("@F_IntExpand2", SqlDbType.Int,4), new SqlParameter("@F_TimeExpand1", SqlDbType.DateTime), new SqlParameter("@F_TimeExpand2", SqlDbType.DateTime), new SqlParameter("@F_TextExpand1", SqlDbType.Text), new SqlParameter("@F_TextExpand2", SqlDbType.Text)}; parameters[0].Value = Guid.NewGuid(); parameters[1].Value = Guid.NewGuid(); parameters[2].Value = model.F_StrExpand1; parameters[3].Value = model.F_StrExpand2; parameters[4].Value = model.F_StrExpand3; parameters[5].Value = model.F_StrExpand4; parameters[6].Value = model.F_StrExpand5; parameters[7].Value = model.F_StrExpand6; parameters[8].Value = model.F_TypeExpand1; parameters[9].Value = model.F_TypeExpand2; parameters[10].Value = model.F_IntExpand1; parameters[11].Value = model.F_IntExpand2; parameters[12].Value = model.F_TimeExpand1; parameters[13].Value = model.F_TimeExpand2; parameters[14].Value = model.F_TextExpand1; parameters[15].Value = model.F_TextExpand2; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 更新一条数据 /// public bool Update(CallCenterApi.Model.T_Cus_CustomerExpand model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_Cus_CustomerExpand set "); strSql.Append("F_CustomerId=@F_CustomerId,"); strSql.Append("F_StrExpand1=@F_StrExpand1,"); strSql.Append("F_StrExpand2=@F_StrExpand2,"); strSql.Append("F_StrExpand3=@F_StrExpand3,"); strSql.Append("F_StrExpand4=@F_StrExpand4,"); strSql.Append("F_StrExpand5=@F_StrExpand5,"); strSql.Append("F_StrExpand6=@F_StrExpand6,"); strSql.Append("F_TypeExpand1=@F_TypeExpand1,"); strSql.Append("F_TypeExpand2=@F_TypeExpand2,"); strSql.Append("F_IntExpand1=@F_IntExpand1,"); strSql.Append("F_IntExpand2=@F_IntExpand2,"); strSql.Append("F_TimeExpand1=@F_TimeExpand1,"); strSql.Append("F_TimeExpand2=@F_TimeExpand2,"); strSql.Append("F_TextExpand1=@F_TextExpand1,"); strSql.Append("F_TextExpand2=@F_TextExpand2"); strSql.Append(" where F_ExpandId=@F_ExpandId "); SqlParameter[] parameters = { new SqlParameter("@F_CustomerId", SqlDbType.UniqueIdentifier,16), new SqlParameter("@F_StrExpand1", SqlDbType.NVarChar,200), new SqlParameter("@F_StrExpand2", SqlDbType.NVarChar,200), new SqlParameter("@F_StrExpand3", SqlDbType.NVarChar,200), new SqlParameter("@F_StrExpand4", SqlDbType.NVarChar,200), new SqlParameter("@F_StrExpand5", SqlDbType.NVarChar,200), new SqlParameter("@F_StrExpand6", SqlDbType.NVarChar,200), new SqlParameter("@F_TypeExpand1", SqlDbType.NVarChar,50), new SqlParameter("@F_TypeExpand2", SqlDbType.NVarChar,50), new SqlParameter("@F_IntExpand1", SqlDbType.Int,4), new SqlParameter("@F_IntExpand2", SqlDbType.Int,4), new SqlParameter("@F_TimeExpand1", SqlDbType.DateTime), new SqlParameter("@F_TimeExpand2", SqlDbType.DateTime), new SqlParameter("@F_TextExpand1", SqlDbType.Text), new SqlParameter("@F_TextExpand2", SqlDbType.Text), new SqlParameter("@F_ExpandId", SqlDbType.UniqueIdentifier,16)}; parameters[0].Value = model.F_CustomerId; parameters[1].Value = model.F_StrExpand1; parameters[2].Value = model.F_StrExpand2; parameters[3].Value = model.F_StrExpand3; parameters[4].Value = model.F_StrExpand4; parameters[5].Value = model.F_StrExpand5; parameters[6].Value = model.F_StrExpand6; parameters[7].Value = model.F_TypeExpand1; parameters[8].Value = model.F_TypeExpand2; parameters[9].Value = model.F_IntExpand1; parameters[10].Value = model.F_IntExpand2; parameters[11].Value = model.F_TimeExpand1; parameters[12].Value = model.F_TimeExpand2; parameters[13].Value = model.F_TextExpand1; parameters[14].Value = model.F_TextExpand2; parameters[15].Value = model.F_ExpandId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 删除一条数据 /// public bool Delete(Guid F_ExpandId) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from T_Cus_CustomerExpand "); strSql.Append(" where F_ExpandId=@F_ExpandId "); SqlParameter[] parameters = { new SqlParameter("@F_ExpandId", SqlDbType.UniqueIdentifier,16) }; parameters[0].Value = F_ExpandId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 批量删除数据 /// public bool DeleteList(string F_ExpandIdlist) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from T_Cus_CustomerExpand "); strSql.Append(" where F_ExpandId in (" + F_ExpandIdlist + ") "); int rows = DbHelperSQL.ExecuteSql(strSql.ToString()); if (rows > 0) { return true; } else { return false; } } /// /// 得到一个对象实体 /// public CallCenterApi.Model.T_Cus_CustomerExpand GetModel(Guid F_ExpandId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 F_ExpandId,F_CustomerId,F_StrExpand1,F_StrExpand2,F_StrExpand3,F_StrExpand4,F_StrExpand5,F_StrExpand6,F_TypeExpand1,F_TypeExpand2,F_IntExpand1,F_IntExpand2,F_TimeExpand1,F_TimeExpand2,F_TextExpand1,F_TextExpand2 from T_Cus_CustomerExpand "); strSql.Append(" where F_ExpandId=@F_ExpandId "); SqlParameter[] parameters = { new SqlParameter("@F_ExpandId", SqlDbType.UniqueIdentifier,16) }; parameters[0].Value = F_ExpandId; CallCenterApi.Model.T_Cus_CustomerExpand model = new CallCenterApi.Model.T_Cus_CustomerExpand(); 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_Cus_CustomerExpand DataRowToModel(DataRow row) { CallCenterApi.Model.T_Cus_CustomerExpand model = new CallCenterApi.Model.T_Cus_CustomerExpand(); if (row != null) { if (row["F_ExpandId"] != null && row["F_ExpandId"].ToString() != "") { model.F_ExpandId = new Guid(row["F_ExpandId"].ToString()); } if (row["F_CustomerId"] != null && row["F_CustomerId"].ToString() != "") { model.F_CustomerId = new Guid(row["F_CustomerId"].ToString()); } if (row["F_StrExpand1"] != null) { model.F_StrExpand1 = row["F_StrExpand1"].ToString(); } if (row["F_StrExpand2"] != null) { model.F_StrExpand2 = row["F_StrExpand2"].ToString(); } if (row["F_StrExpand3"] != null) { model.F_StrExpand3 = row["F_StrExpand3"].ToString(); } if (row["F_StrExpand4"] != null) { model.F_StrExpand4 = row["F_StrExpand4"].ToString(); } if (row["F_StrExpand5"] != null) { model.F_StrExpand5 = row["F_StrExpand5"].ToString(); } if (row["F_StrExpand6"] != null) { model.F_StrExpand6 = row["F_StrExpand6"].ToString(); } if (row["F_TypeExpand1"] != null) { model.F_TypeExpand1 = row["F_TypeExpand1"].ToString(); } if (row["F_TypeExpand2"] != null) { model.F_TypeExpand2 = row["F_TypeExpand2"].ToString(); } if (row["F_IntExpand1"] != null && row["F_IntExpand1"].ToString() != "") { model.F_IntExpand1 = int.Parse(row["F_IntExpand1"].ToString()); } if (row["F_IntExpand2"] != null && row["F_IntExpand2"].ToString() != "") { model.F_IntExpand2 = int.Parse(row["F_IntExpand2"].ToString()); } if (row["F_TimeExpand1"] != null && row["F_TimeExpand1"].ToString() != "") { model.F_TimeExpand1 = DateTime.Parse(row["F_TimeExpand1"].ToString()); } if (row["F_TimeExpand2"] != null && row["F_TimeExpand2"].ToString() != "") { model.F_TimeExpand2 = DateTime.Parse(row["F_TimeExpand2"].ToString()); } if (row["F_TextExpand1"] != null) { model.F_TextExpand1 = row["F_TextExpand1"].ToString(); } if (row["F_TextExpand2"] != null) { model.F_TextExpand2 = row["F_TextExpand2"].ToString(); } } return model; } /// /// 获得数据列表 /// public DataSet GetList(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select F_ExpandId,F_CustomerId,F_StrExpand1,F_StrExpand2,F_StrExpand3,F_StrExpand4,F_StrExpand5,F_StrExpand6,F_TypeExpand1,F_TypeExpand2,F_IntExpand1,F_IntExpand2,F_TimeExpand1,F_TimeExpand2,F_TextExpand1,F_TextExpand2 "); strSql.Append(" FROM T_Cus_CustomerExpand "); 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(" F_ExpandId,F_CustomerId,F_StrExpand1,F_StrExpand2,F_StrExpand3,F_StrExpand4,F_StrExpand5,F_StrExpand6,F_TypeExpand1,F_TypeExpand2,F_IntExpand1,F_IntExpand2,F_TimeExpand1,F_TimeExpand2,F_TextExpand1,F_TextExpand2 "); strSql.Append(" FROM T_Cus_CustomerExpand "); 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_Cus_CustomerExpand "); 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_ExpandId desc"); } strSql.Append(")AS Row, T.* from T_Cus_CustomerExpand 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()); } /* /// /// 分页获取数据列表 /// public DataSet GetList(int PageSize,int PageIndex,string strWhere) { SqlParameter[] parameters = { new SqlParameter("@tblName", SqlDbType.VarChar, 255), new SqlParameter("@fldName", SqlDbType.VarChar, 255), new SqlParameter("@PageSize", SqlDbType.Int), new SqlParameter("@PageIndex", SqlDbType.Int), new SqlParameter("@IsReCount", SqlDbType.Bit), new SqlParameter("@OrderType", SqlDbType.Bit), new SqlParameter("@strWhere", SqlDbType.VarChar,1000), }; parameters[0].Value = "T_Cus_CustomerExpand"; parameters[1].Value = "F_ExpandId"; parameters[2].Value = PageSize; parameters[3].Value = PageIndex; parameters[4].Value = 0; parameters[5].Value = 0; parameters[6].Value = strWhere; return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds"); }*/ #endregion BasicMethod #region ExtensionMethod #endregion ExtensionMethod } }