public IList <AnswerOptionInfo> GetList() { StringBuilder sb = new StringBuilder(250); sb.Append(@"select Id,QuestionSubjectId,OptionContent,Sort,IsTrue,Remark,IsDisable,LastUpdatedDate from AnswerOption order by LastUpdatedDate desc " ); IList <AnswerOptionInfo> list = new List <AnswerOptionInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString())) { if (reader != null && reader.HasRows) { while (reader.Read()) { AnswerOptionInfo model = new AnswerOptionInfo(); model.Id = reader.GetGuid(0); model.QuestionSubjectId = reader.GetGuid(1); model.OptionContent = reader.GetString(2); model.Sort = reader.GetInt32(3); model.IsTrue = reader.GetBoolean(4); model.Remark = reader.GetString(5); model.IsDisable = reader.GetBoolean(6); model.LastUpdatedDate = reader.GetDateTime(7); list.Add(model); } } } return(list); }
public int Update(AnswerOptionInfo model) { StringBuilder sb = new StringBuilder(250); sb.Append(@"update AnswerOption set QuestionSubjectId = @QuestionSubjectId,OptionContent = @OptionContent,Sort = @Sort,IsTrue = @IsTrue,Remark = @Remark,IsDisable = @IsDisable,LastUpdatedDate = @LastUpdatedDate where Id = @Id " ); SqlParameter[] parms = { new SqlParameter("@Id", SqlDbType.UniqueIdentifier), new SqlParameter("@QuestionSubjectId", SqlDbType.UniqueIdentifier), new SqlParameter("@OptionContent", SqlDbType.NVarChar, 200), new SqlParameter("@Sort", SqlDbType.Int), new SqlParameter("@IsTrue", SqlDbType.Bit), new SqlParameter("@Remark", SqlDbType.NVarChar, 300), new SqlParameter("@IsDisable", SqlDbType.Bit), new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime) }; parms[0].Value = model.Id; parms[1].Value = model.QuestionSubjectId; parms[2].Value = model.OptionContent; parms[3].Value = model.Sort; parms[4].Value = model.IsTrue; parms[5].Value = model.Remark; parms[6].Value = model.IsDisable; parms[7].Value = model.LastUpdatedDate; return(SqlHelper.ExecuteNonQuery(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), parms)); }
public AnswerOptionInfo GetModel(object Id) { AnswerOptionInfo model = null; StringBuilder sb = new StringBuilder(300); sb.Append(@"select top 1 Id,QuestionSubjectId,OptionContent,Sort,IsTrue,Remark,IsDisable,LastUpdatedDate from AnswerOption where Id = @Id " ); SqlParameter parm = new SqlParameter("@Id", SqlDbType.UniqueIdentifier); parm.Value = Guid.Parse(Id.ToString()); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), parm)) { if (reader != null) { while (reader.Read()) { model = new AnswerOptionInfo(); model.Id = reader.GetGuid(0); model.QuestionSubjectId = reader.GetGuid(1); model.OptionContent = reader.GetString(2); model.Sort = reader.GetInt32(3); model.IsTrue = reader.GetBoolean(4); model.Remark = reader.GetString(5); model.IsDisable = reader.GetBoolean(6); model.LastUpdatedDate = reader.GetDateTime(7); } } } return(model); }
public IList <AnswerOptionInfo> GetList(int pageIndex, int pageSize, out int totalRecords, string sqlWhere, params SqlParameter[] cmdParms) { StringBuilder sb = new StringBuilder(250); sb.Append(@"select count(*) from AnswerOption "); if (!string.IsNullOrEmpty(sqlWhere)) { sb.AppendFormat(" where 1=1 {0} ", sqlWhere); } totalRecords = (int)SqlHelper.ExecuteScalar(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), cmdParms); if (totalRecords == 0) { return(new List <AnswerOptionInfo>()); } sb.Clear(); int startIndex = (pageIndex - 1) * pageSize + 1; int endIndex = pageIndex * pageSize; sb.Append(@"select * from(select row_number() over(order by LastUpdatedDate desc) as RowNumber, Id,QuestionSubjectId,OptionContent,Sort,IsTrue,Remark,IsDisable,LastUpdatedDate from AnswerOption " ); if (!string.IsNullOrEmpty(sqlWhere)) { sb.AppendFormat(" where 1=1 {0} ", sqlWhere); } sb.AppendFormat(@")as objTable where RowNumber between {0} and {1} ", startIndex, endIndex); IList <AnswerOptionInfo> list = new List <AnswerOptionInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { AnswerOptionInfo model = new AnswerOptionInfo(); model.Id = reader.GetGuid(1); model.QuestionSubjectId = reader.GetGuid(2); model.OptionContent = reader.GetString(3); model.Sort = reader.GetInt32(4); model.IsTrue = reader.GetBoolean(5); model.Remark = reader.GetString(6); model.IsDisable = reader.GetBoolean(7); model.LastUpdatedDate = reader.GetDateTime(8); list.Add(model); } } } return(list); }
public int InsertOW(AnswerOptionInfo model) { int sort = 0; StringBuilder sb = new StringBuilder(250); sb.Append(@"select max(Sort) as MaxSort from AnswerOption where QuestionSubjectId = @QuestionSubjectId"); SqlParameter[] cmdParms = { new SqlParameter("@QuestionSubjectId", SqlDbType.UniqueIdentifier) }; cmdParms[0].Value = model.QuestionSubjectId; using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), cmdParms)) { if (reader != null) { while (reader.Read()) { sort = reader.IsDBNull(0) ? 0 : reader.GetInt32(0); } } } model.Sort = sort + 1; sb.Clear(); sb.Append(@"insert into AnswerOption (QuestionSubjectId,OptionContent,Sort,IsTrue,Remark,IsDisable,LastUpdatedDate) values (@QuestionSubjectId,@OptionContent,@Sort,@IsTrue,@Remark,@IsDisable,@LastUpdatedDate) " ); SqlParameter[] parms = { new SqlParameter("@QuestionSubjectId", SqlDbType.UniqueIdentifier), new SqlParameter("@OptionContent", SqlDbType.NVarChar, 512), new SqlParameter("@Sort", SqlDbType.Int), new SqlParameter("@IsTrue", SqlDbType.Bit), new SqlParameter("@Remark", SqlDbType.NVarChar, 300), new SqlParameter("@IsDisable", SqlDbType.Bit), new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime) }; parms[0].Value = model.QuestionSubjectId; parms[1].Value = model.OptionContent; parms[2].Value = model.Sort; parms[3].Value = model.IsTrue; parms[4].Value = model.Remark; parms[5].Value = model.IsDisable; parms[6].Value = model.LastUpdatedDate; return(SqlHelper.ExecuteNonQuery(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), parms)); }
public IList <AnswerOptionInfo> GetListOW(int pageIndex, int pageSize, string sqlWhere, params SqlParameter[] cmdParms) { StringBuilder sb = new StringBuilder(250); int startIndex = (pageIndex - 1) * pageSize + 1; int endIndex = pageIndex * pageSize; sb.Append(@"select * from(select row_number() over(order by AO.Sort asc) as RowNumber, AO.Id,AO.QuestionSubjectId,AO.OptionContent,AO.Sort,AO.IsTrue,AO.Remark,AO.IsDisable,AO.LastUpdatedDate,QS.QuestionContent from AnswerOption AO, QuestionSubject QS " ); sb.AppendFormat(" where AO.QuestionSubjectId = QS.Id {0} ", sqlWhere); sb.AppendFormat(@")as objTable where RowNumber between {0} and {1} ", startIndex, endIndex); IList <AnswerOptionInfo> list = new List <AnswerOptionInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { AnswerOptionInfo model = new AnswerOptionInfo(); model.Id = reader.GetGuid(1); model.QuestionSubjectId = reader.GetGuid(2); model.OptionContent = reader.GetString(3); model.Sort = reader.GetInt32(4); model.IsTrue = reader.GetBoolean(5); model.Remark = reader.GetString(6); model.IsDisable = reader.GetBoolean(7); model.LastUpdatedDate = reader.GetDateTime(8); list.Add(model); } } } return(list); }
public IList <AnswerOptionInfo> GetList(string sqlWhere, params SqlParameter[] cmdParms) { StringBuilder sb = new StringBuilder(250); sb.Append(@"select Id,QuestionSubjectId,OptionContent,Sort,IsTrue,Remark,IsDisable,LastUpdatedDate from AnswerOption "); if (!string.IsNullOrEmpty(sqlWhere)) { sb.AppendFormat(" where 1=1 {0} ", sqlWhere); } IList <AnswerOptionInfo> list = new List <AnswerOptionInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { AnswerOptionInfo model = new AnswerOptionInfo(); model.Id = reader.GetGuid(0); model.QuestionSubjectId = reader.GetGuid(1); model.OptionContent = reader.GetString(2); model.Sort = reader.GetInt32(3); model.IsTrue = reader.GetBoolean(4); model.Remark = reader.GetString(5); model.IsDisable = reader.GetBoolean(6); model.LastUpdatedDate = reader.GetDateTime(7); list.Add(model); } } } return(list); }
/// <summary> /// 修改数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Update(AnswerOptionInfo model) { return(dal.Update(model)); }
/// <summary> /// 添加数据到数据库 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Insert(AnswerOptionInfo model) { return(dal.Insert(model)); }