using System; using System.Data; using System.Text; using System.Data.SqlClient; using CallCenterApi.DB; namespace CallCenterApi.DAL { /// /// 数据访问类:T_RepositoryInformation /// public partial class T_RepositoryInformation { public T_RepositoryInformation() { } #region BasicMethod /// /// 是否存在该记录 /// public bool Exists(int F_RepositoryId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(1) from T_RepositoryInformation"); strSql.Append(" where F_RepositoryId=@F_RepositoryId"); SqlParameter[] parameters = { new SqlParameter("@F_RepositoryId", SqlDbType.Int,4) }; parameters[0].Value = F_RepositoryId; return DbHelperSQL.Exists(strSql.ToString(), parameters); } /// /// 增加一条数据 /// public int Add(CallCenterApi.Model.T_RepositoryInformation model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_RepositoryInformation("); strSql.Append("F_CategoryId,F_Title,F_Content,F_Description,F_Url,F_KeyWords,F_ClickCount,F_ISPass,F_ISSubmitAudit,F_Expand1,F_Expand2,F_IntExpand1,F_CreateOn,F_CreateBy,F_AuditID,F_UseNum,F_CollectionNum)"); strSql.Append(" values ("); strSql.Append("@F_CategoryId,@F_Title,@F_Content,@F_Description,@F_Url,@F_KeyWords,@F_ClickCount,@F_ISPass,@F_ISSubmitAudit,@F_Expand1,@F_Expand2,@F_IntExpand1,@F_CreateOn,@F_CreateBy,@F_AuditID,@F_UseNum,@F_CollectionNum)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@F_CategoryId", SqlDbType.Int,4), new SqlParameter("@F_Title", SqlDbType.NVarChar,200), new SqlParameter("@F_Content", SqlDbType.NText), new SqlParameter("@F_Description", SqlDbType.NText), new SqlParameter("@F_Url", SqlDbType.NText), new SqlParameter("@F_KeyWords", SqlDbType.NVarChar,500), new SqlParameter("@F_ClickCount", SqlDbType.Int,4), new SqlParameter("@F_ISPass", SqlDbType.Int,4), new SqlParameter("@F_ISSubmitAudit", SqlDbType.Int,4), new SqlParameter("@F_Expand1", SqlDbType.NVarChar,100), new SqlParameter("@F_Expand2", SqlDbType.NVarChar,200), new SqlParameter("@F_IntExpand1", SqlDbType.SmallInt,2), new SqlParameter("@F_CreateOn", SqlDbType.DateTime), new SqlParameter("@F_CreateBy", SqlDbType.Int,4), new SqlParameter("@F_AuditID", SqlDbType.Int,4), new SqlParameter("@F_UseNum", SqlDbType.Int,4), new SqlParameter("@F_CollectionNum", SqlDbType.Int,4)}; parameters[0].Value = model.F_CategoryId; parameters[1].Value = model.F_Title; parameters[2].Value = model.F_Content; parameters[3].Value = model.F_Description; parameters[4].Value = model.F_Url; parameters[5].Value = model.F_KeyWords; parameters[6].Value = model.F_ClickCount; parameters[7].Value = model.F_ISPass; parameters[8].Value = model.F_ISSubmitAudit; parameters[9].Value = model.F_Expand1; parameters[10].Value = model.F_Expand2; parameters[11].Value = model.F_IntExpand1; parameters[12].Value = model.F_CreateOn; parameters[13].Value = model.F_CreateBy; parameters[14].Value = model.F_AuditID; parameters[15].Value = model.F_UseNum; parameters[16].Value = model.F_CollectionNum; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return 0; } else { return Convert.ToInt32(obj); } } /// /// 更新一条数据 /// public bool Update(CallCenterApi.Model.T_RepositoryInformation model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_RepositoryInformation set "); strSql.Append("F_CategoryId=@F_CategoryId,"); strSql.Append("F_Title=@F_Title,"); strSql.Append("F_Content=@F_Content,"); strSql.Append("F_Description=@F_Description,"); strSql.Append("F_Url=@F_Url,"); strSql.Append("F_KeyWords=@F_KeyWords,"); strSql.Append("F_ClickCount=@F_ClickCount,"); strSql.Append("F_ISPass=@F_ISPass,"); strSql.Append("F_ISSubmitAudit=@F_ISSubmitAudit,"); strSql.Append("F_Expand1=@F_Expand1,"); strSql.Append("F_Expand2=@F_Expand2,"); strSql.Append("F_IntExpand1=@F_IntExpand1,"); strSql.Append("F_CreateOn=@F_CreateOn,"); strSql.Append("F_CreateBy=@F_CreateBy,"); strSql.Append("F_AuditID=@F_AuditID,"); strSql.Append("F_UseNum=@F_UseNum,"); strSql.Append("F_CollectionNum=@F_CollectionNum"); strSql.Append(" where F_RepositoryId=@F_RepositoryId"); SqlParameter[] parameters = { new SqlParameter("@F_CategoryId", SqlDbType.Int,4), new SqlParameter("@F_Title", SqlDbType.NVarChar,200), new SqlParameter("@F_Content", SqlDbType.NText), new SqlParameter("@F_Description", SqlDbType.NText), new SqlParameter("@F_Url", SqlDbType.NText), new SqlParameter("@F_KeyWords", SqlDbType.NVarChar,500), new SqlParameter("@F_ClickCount", SqlDbType.Int,4), new SqlParameter("@F_ISPass", SqlDbType.Int,4), new SqlParameter("@F_ISSubmitAudit", SqlDbType.Int,4), new SqlParameter("@F_Expand1", SqlDbType.NVarChar,100), new SqlParameter("@F_Expand2", SqlDbType.NVarChar,200), new SqlParameter("@F_IntExpand1", SqlDbType.SmallInt,2), new SqlParameter("@F_CreateOn", SqlDbType.DateTime), new SqlParameter("@F_CreateBy", SqlDbType.Int,4), new SqlParameter("@F_AuditID", SqlDbType.Int,4), new SqlParameter("@F_UseNum", SqlDbType.Int,4), new SqlParameter("@F_CollectionNum", SqlDbType.Int,4), new SqlParameter("@F_RepositoryId", SqlDbType.Int,4)}; parameters[0].Value = model.F_CategoryId; parameters[1].Value = model.F_Title; parameters[2].Value = model.F_Content; parameters[3].Value = model.F_Description; parameters[4].Value = model.F_Url; parameters[5].Value = model.F_KeyWords; parameters[6].Value = model.F_ClickCount; parameters[7].Value = model.F_ISPass; parameters[8].Value = model.F_ISSubmitAudit; parameters[9].Value = model.F_Expand1; parameters[10].Value = model.F_Expand2; parameters[11].Value = model.F_IntExpand1; parameters[12].Value = model.F_CreateOn; parameters[13].Value = model.F_CreateBy; parameters[14].Value = model.F_AuditID; parameters[15].Value = model.F_UseNum; parameters[16].Value = model.F_CollectionNum; parameters[17].Value = model.F_RepositoryId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 删除一条数据 /// public bool Delete(int F_RepositoryId) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from T_RepositoryInformation "); strSql.Append(" where F_RepositoryId=@F_RepositoryId"); SqlParameter[] parameters = { new SqlParameter("@F_RepositoryId", SqlDbType.Int,4) }; parameters[0].Value = F_RepositoryId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 批量删除数据 /// public bool DeleteList(string F_RepositoryIdlist) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from T_RepositoryInformation "); strSql.Append(" where F_RepositoryId in (" + F_RepositoryIdlist + ") "); int rows = DbHelperSQL.ExecuteSql(strSql.ToString()); if (rows > 0) { return true; } else { return false; } } /// /// 得到一个对象实体 /// public CallCenterApi.Model.T_RepositoryInformation GetModel(int F_RepositoryId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 F_RepositoryId,F_CategoryId,F_Title,F_Content,F_Description,F_Url,F_KeyWords,F_ClickCount,F_ISPass,F_ISSubmitAudit,F_Expand1,F_Expand2,F_IntExpand1,F_CreateOn,F_CreateBy,F_AuditID,F_UseNum,F_CollectionNum from T_RepositoryInformation "); strSql.Append(" where F_RepositoryId=@F_RepositoryId"); SqlParameter[] parameters = { new SqlParameter("@F_RepositoryId", SqlDbType.Int,4) }; parameters[0].Value = F_RepositoryId; CallCenterApi.Model.T_RepositoryInformation model = new CallCenterApi.Model.T_RepositoryInformation(); 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_RepositoryInformation DataRowToModel(DataRow row) { CallCenterApi.Model.T_RepositoryInformation model = new CallCenterApi.Model.T_RepositoryInformation(); if (row != null) { if (row["F_RepositoryId"] != null && row["F_RepositoryId"].ToString() != "") { model.F_RepositoryId = int.Parse(row["F_RepositoryId"].ToString()); } if (row["F_CategoryId"] != null && row["F_CategoryId"].ToString() != "") { model.F_CategoryId = int.Parse(row["F_CategoryId"].ToString()); } if (row["F_Title"] != null) { model.F_Title = row["F_Title"].ToString(); } if (row["F_Content"] != null) { model.F_Content = row["F_Content"].ToString(); } if (row["F_Description"] != null) { model.F_Description = row["F_Description"].ToString(); } if (row["F_Url"] != null) { model.F_Url = row["F_Url"].ToString(); } if (row["F_KeyWords"] != null) { model.F_KeyWords = row["F_KeyWords"].ToString(); } if (row["F_ClickCount"] != null && row["F_ClickCount"].ToString() != "") { model.F_ClickCount = int.Parse(row["F_ClickCount"].ToString()); } if (row["F_ISPass"] != null && row["F_ISPass"].ToString() != "") { model.F_ISPass = int.Parse(row["F_ISPass"].ToString()); } if (row["F_ISSubmitAudit"] != null && row["F_ISSubmitAudit"].ToString() != "") { model.F_ISSubmitAudit = int.Parse(row["F_ISSubmitAudit"].ToString()); } if (row["F_Expand1"] != null) { model.F_Expand1 = row["F_Expand1"].ToString(); } if (row["F_Expand2"] != null) { model.F_Expand2 = row["F_Expand2"].ToString(); } if (row["F_IntExpand1"] != null && row["F_IntExpand1"].ToString() != "") { model.F_IntExpand1 = int.Parse(row["F_IntExpand1"].ToString()); } if (row["F_CreateOn"] != null && row["F_CreateOn"].ToString() != "") { model.F_CreateOn = DateTime.Parse(row["F_CreateOn"].ToString()); } if (row["F_CreateBy"] != null && row["F_CreateBy"].ToString() != "") { model.F_CreateBy = int.Parse(row["F_CreateBy"].ToString()); } if (row["F_AuditID"] != null && row["F_AuditID"].ToString() != "") { model.F_AuditID = int.Parse(row["F_AuditID"].ToString()); } if (row["F_UseNum"] != null && row["F_UseNum"].ToString() != "") { model.F_UseNum = int.Parse(row["F_UseNum"].ToString()); } if (row["F_CollectionNum"] != null && row["F_CollectionNum"].ToString() != "") { model.F_CollectionNum = int.Parse(row["F_CollectionNum"].ToString()); } } return model; } /// /// 获得数据列表 /// public DataSet GetList(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select F_RepositoryId,F_CategoryId,F_Title,F_Content,F_Description,F_Url,F_KeyWords,F_ClickCount,F_ISPass,F_ISSubmitAudit,F_Expand1,F_Expand2,F_IntExpand1,F_CreateOn,F_CreateBy,F_AuditID,F_UseNum,F_CollectionNum "); strSql.Append(" FROM T_RepositoryInformation "); 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_RepositoryId,F_CategoryId,F_Title,F_Content,F_Description,F_Url,F_KeyWords,F_ClickCount,F_ISPass,F_ISSubmitAudit,F_Expand1,F_Expand2,F_IntExpand1,F_CreateOn,F_CreateBy,F_AuditID,F_UseNum,F_CollectionNum "); strSql.Append(" FROM T_RepositoryInformation "); 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_RepositoryInformation "); 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_RepositoryId desc"); } strSql.Append(")AS Row, T.* from T_RepositoryInformation 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 BasicMethod #region ExtensionMethod /// /// 更新点击量 /// public bool UpdateClick(int rid) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_RepositoryInformation set "); strSql.Append(" F_ClickCount=F_ClickCount+1 "); strSql.Append(" where F_RepositoryId=@F_RepositoryId"); SqlParameter[] parameters = { new SqlParameter("@F_RepositoryId", SqlDbType.Int,4)}; parameters[0].Value = rid; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 更新审核ID /// public bool UpdateAuditID(int rid,int auditid) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_RepositoryInformation set "); strSql.Append(" F_AuditID=@F_AuditID "); strSql.Append(" where F_RepositoryId=@F_RepositoryId"); SqlParameter[] parameters = { new SqlParameter("@F_AuditID", SqlDbType.Int,4), new SqlParameter("@F_RepositoryId", SqlDbType.Int,4)}; parameters[0].Value = auditid; parameters[1].Value = rid; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 更新提交审核 /// public bool UpdateSubAudit(int rid, int issub) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_RepositoryInformation set "); strSql.Append(" F_ISSubmitAudit=@F_ISSubmitAudit "); strSql.Append(" where F_RepositoryId=@F_RepositoryId"); SqlParameter[] parameters = { new SqlParameter("@F_ISSubmitAudit", SqlDbType.Int,4), new SqlParameter("@F_RepositoryId", SqlDbType.Int,4)}; parameters[0].Value = issub; parameters[1].Value = rid; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } /// /// 更新审核 /// public bool UpdateAudit(int rid, int pass) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_RepositoryInformation set "); strSql.Append(" F_ISPass=@F_ISPass "); strSql.Append(" where F_RepositoryId=@F_RepositoryId"); SqlParameter[] parameters = { new SqlParameter("@F_ISPass", SqlDbType.Int,4), new SqlParameter("@F_RepositoryId", SqlDbType.Int,4)}; parameters[0].Value = pass; parameters[1].Value = rid; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } } #endregion ExtensionMethod } }