EchoTex_Payroll/HRM.DA/DA/Survey/SurveyDA.cs

134 lines
5.4 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using HRM.BO;
using Ease.Core.DataAccess;
using System;
using System.Collections.Generic;
using System.Data;
namespace HRM.DA
{
internal class SurveyDA
{
#region Constructor
private SurveyDA()
{
}
#endregion
#region Survey
#region Insert function
internal static void Insert(TransactionContext tc, Survey item)
{
tc.ExecuteNonQuery(
"INSERT INTO Survey(SurveyID, CategoryID, Title, Description, FromDate, ToDate,IsForCelyStoped,IsPublished,CreatedBy,CreationDate,PublishDate,SurveyType,EstimatedTime,ActualTime,PASSMARK)" +
" VALUES(%n, %n, %s, %s, %d, %d, %b,%b,%n,%d,%d,%n,%n,%n,%n)", item.ID, item.CategoryID, item.Title,
item.Description, item.FromDate, item.ToDate, item.IsForCelyStoped, item.IsPublished, item.CreatedBy,
item.CreatedDate, DataReader.GetNullValue(item.PublishDate), item.SurveyType,item.EstimatedTime,item.ActualTime,item.PassMark);
}
#endregion
#region Update function
internal static void Update(TransactionContext tc, Survey item)
{
tc.ExecuteNonQuery(
"UPDATE Survey SET CategoryID=%n, Title=%s, Description=%s, FromDate=%d, ToDate=%d,IsForCelyStoped=%b,IsPublished=%b,ModifiedBy=%n,ModifiedDate=%d,PublishDate=%d,SurveyType=%n" +
" WHERE SurveyID=%n", item.CategoryID, item.Title, item.Description, item.FromDate, item.ToDate,
item.IsForCelyStoped, item.IsPublished, item.ModifiedBy, item.ModifiedDate,
DataReader.GetNullValue(item.PublishDate), item.SurveyType, item.ID);
}
#endregion
#region Get Function
public static IDataReader Get(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM Survey");
}
public static IDataReader GetByCategory(TransactionContext tc, int nCategoryId)
{
return tc.ExecuteReader("SELECT * FROM Survey WHERE CategoryId=%n", nCategoryId);
}
public static IDataReader Get(TransactionContext tc, DateTime today)
{
return tc.ExecuteReader(
"SELECT * from Survey WHERE %d BETWEEN FromDate AND ToDate AND IsPublished=1 AND IsForcelyStoped=0",
today);
}
//public static IDataReader Get(TransactionContext tc, Employee oEmp)
//{
// return tc.ExecuteReader("SELECT * from Survey");
//}
public static IDataReader GetByCategory(TransactionContext tc, int nCategoryId, DateTime fromDT, DateTime toDT)
{
return tc.ExecuteReader(
"SELECT * FROM Survey WHERE CategoryId=%n and (FromDate>= %d and FromDate<= %d) OR( ToDate>= %d and ToDate<= %d)",
nCategoryId, fromDT, toDT, fromDT, toDT);
}
public static IDataReader GetByCategory(TransactionContext tc, DateTime fromDT, DateTime toDT)
{
return tc.ExecuteReader(
"SELECT * FROM Survey WHERE (FromDate>= %d and FromDate<= %d) OR( ToDate>= %d and ToDate<= %d)", fromDT,
toDT, fromDT, toDT);
}
public static IDataReader GetQuestionsByCategoryId(TransactionContext tc,int categoryId)
{
return tc.ExecuteReader(
"SELECT s.*,sc.DESCRIPTION SurveyCategory FROM SURVEY s INNER JOIN SURVEYCATEGORY sc ON sc.CATEGORYID = s.CATEGORYID WHERE s.categoryId=%n", categoryId);
}
public static IDataReader GetIncompleteSurveys(TransactionContext tc, int empID, EnumSurveyType type,
DateTime fromDT, DateTime toDT)
{
//if (type == EnumSurveyType.Self || type == EnumSurveyType.Managerial)
// return tc.ExecuteReader("SELECT S.* FROM Survey S,SurveyEmployee SE WHERE SE.EmployeeId=%n and S.SurveyType=%n and S.SurveyId=SE.SurveyId and S.PublishFromDate between %d and %d", empID, (int)type, fromDT, toDT);
//else
return tc.ExecuteReader(
"SELECT S.* FROM Survey S,SurveyEmployee SE WHERE SE.EmployeeId=%n and S.SurveyId=SE.SurveyId and S.PublishDate between %d and %d",
empID, fromDT, toDT);
}
public static IDataReader Get(TransactionContext tc, int nSurveyId)
{
return tc.ExecuteReader("SELECT * FROM Survey WHERE SurveyId=%n", nSurveyId);
}
#endregion
#region Delete function
public static void Delete(TransactionContext tc, int nSurveyId)
{
SurveyQuestionDA.DeleteSurveyQuestion(tc, nSurveyId);
SurveyEmployeeDA.DeleteSurveyEmployee(tc, nSurveyId);
SurveyOrganizationDA.DeleteSurveyOrganization(tc, nSurveyId);
tc.ExecuteNonQuery("DELETE FROM Survey WHERE SurveyId=%n", nSurveyId);
}
public static void Publish(TransactionContext tc, Survey survey)
{
tc.ExecuteNonQuery("UPDATE Survey SET PublishDate=%d,IsPublished=%b WHERE SurveyId=%n",
survey.PublishDate.Value, survey.IsPublished, survey.ID);
}
public static void Stop(TransactionContext tc, Survey survey)
{
tc.ExecuteNonQuery("UPDATE Survey SET PublishDate=%d,IsPublished=%b,IsForCelyStoped=%b WHERE SurveyId=%n",
DataReader.GetNullValue(survey.PublishDate), survey.IsPublished, survey.IsForCelyStoped, survey.ID);
}
#endregion
#endregion
}
}