CEL_Payroll/Payroll.Service/Survey/DA/SurveyAnswerCountDA.cs
2024-09-17 14:30:13 +06:00

92 lines
3.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Payroll.BO;
using System.Data;
using Ease.CoreV35.Model;
using System.Data.SqlClient;
using Ease.CoreV35.DataAccess;
using Ease.CoreV35.DataAccess.SQL;
namespace Payroll.Service
{
internal class SurveyAnswerCountDA
{
#region Constructor
private SurveyAnswerCountDA() { }
#endregion
#region Insert function
internal static void Insert(TransactionContext tc, SurveyAnswerCount item)
{
tc.ExecuteNonQuery("INSERT INTO SurveyAnswerCount(SurveyID, QuestionID, AnswerID, HitCount)" +
" VALUES(%n, %n, %n, %n)", item.SurveyID.Integer, item.QuestionID, item.AnswerID, item.HitCount);
}
public static void InsertSurveyAnswerCount(TransactionContext tc, int nSurveyId, int nQuestionId, int nAnswerId)
{
tc.ExecuteNonQuery("INSERT INTO SurveyAnswerCount(SurveyId, QuestionId, AnswerId, HitCount)" +
" VALUES(%n, %n, %n, %n)", nSurveyId, nQuestionId, nAnswerId, 1);
}
#endregion
#region Update function
internal static void Update(TransactionContext tc, SurveyAnswerCount item)
{
tc.ExecuteNonQuery("UPDATE SurveyAnswerCount SET QuestionID=%n, AnswerID=%n, HitCount=%n" +
" WHERE SurveyID=%n", item.QuestionID, item.AnswerID, item.HitCount, item.SurveyID.Integer);
}
public static void UpdateSurveyAnswerCount(TransactionContext tc, int nSurveyId, int nQuestionId, int nAnswerId)
{
tc.ExecuteNonQuery("UPDATE SurveyAnswerCount SET HitCount=HitCount+1" +
" WHERE SurveyId=%n AND QuestionId=%n AND AnswerId=%n", nSurveyId, nQuestionId, nAnswerId);
}
#endregion
#region Get Function
public static IDataReader GetSurveyAnswerCount(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM SurveyAnswerCount");
}
public static IDataReader GetSurveyAnswerCount(TransactionContext tc, int nSurveyId)
{
return tc.ExecuteReader("SELECT * FROM SurveyAnswerCount WHERE SurveyId=%n", nSurveyId);
}
public static int GetSurveyAnswerHitCount(TransactionContext tc, int nSurveyId, int nQuestionId, int nAnswerId)
{
string str = "SELECT * FROM SurveyAnswerCount WHERE SurveyId=%n AND QuestionId=%n AND AnswerId=%n";
object obj;
obj = tc.ExecuteScalar(str, nSurveyId, nQuestionId, nAnswerId);
if (obj == null || obj == DBNull.Value)
return 0;
else
return Convert.ToInt32(obj);
}
public static IDataReader GetSurveyAnswerCount(TransactionContext tc, int nSurveyId, int nQuestionId, int nAnswerId)
{
return tc.ExecuteReader("SELECT * FROM SurveyAnswerCount WHERE SurveyId=%n AND QuestionId=%n AND AnswerId=%n", nSurveyId, nQuestionId, nAnswerId);
}
#endregion
#region Delete function
internal static void Delete(TransactionContext tc, ID nID)
{
tc.ExecuteNonQuery("DELETE FROM [SurveyAnswerCount] WHERE SurveyID=%n", nID.Integer);
}
#endregion
}
}