EchoTex_Payroll/HRM.DA/DA/Common/AitAttachmentDA.cs

87 lines
3.3 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using Ease.Core.DataAccess;
using HRM.BO;
using Microsoft.Data.SqlClient;
using System;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
namespace HRM.DA
{
internal class AitAttachmentDA
{
public static void Insert(AitAttachment item, string connectionString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
//connection.Open();
//SqlCommand command = new SqlCommand();
//command.Connection = connection;
//string commandText = @"INSERT INTO TaxAttachment(ReferenceID,FileData,OriginalFileName,FileType) values (@ReferenceID,@FileData,@OriginalFileName,@FileType)";
//command.CommandText = commandText;
//command.CommandType = CommandType.Text;
//command.Parameters.Add("@ReferenceID", SqlDbType.Int);
//command.Parameters["@ReferenceID"].Value = item.ReferenceID;
//command.Parameters.Add("@FileData", SqlDbType.VarBinary);
//command.Parameters["@FileData"].Value = item.FileAsByteArray;
//command.Parameters.Add("@OriginalFileName", SqlDbType.VarChar);
//command.Parameters["@OriginalFileName"].Value = item.OriginalFileName;
//command.Parameters.Add("@FileType", SqlDbType.Int);
//command.Parameters["@FileType"].Value = item.FileType;
//command.ExecuteNonQuery();
//command.Dispose();
//connection.Close();
connection.Open();
SqlCommand command = new SqlCommand();
command.Connection = connection;
string commandText = @"INSERT INTO TaxAttachment(EmployeeID,ID,ReferenceID,FileData,OriginalFileName,FileType) values (@EmployeeID,@InvestmentID,@ReferenceID,@FileData,@OriginalFileName,@FileType)";
command.CommandText = commandText;
command.CommandType = CommandType.Text;
command.Parameters.Add("@EmployeeID", SqlDbType.Int);
command.Parameters["@EmployeeID"].Value = item.EmployeeID;
command.Parameters.Add("@InvestmentID", SqlDbType.Int);
command.Parameters["@InvestmentID"].Value = item.AitID;
command.Parameters.Add("@ReferenceID", SqlDbType.Int);
command.Parameters["@ReferenceID"].Value = item.ReferenceID;
command.Parameters.Add("@FileData", SqlDbType.VarBinary);
command.Parameters["@FileData"].Value = item.FileAsByteArray;
command.Parameters.Add("@OriginalFileName", SqlDbType.VarChar);
command.Parameters["@OriginalFileName"].Value = item.OriginalFileName;
command.Parameters.Add("@FileType", SqlDbType.Int);
command.Parameters["@FileType"].Value = item.FileType;
command.ExecuteNonQuery();
command.Dispose();
connection.Close();
}
}
internal static IDataReader GetByReferenceId(TransactionContext tc, int refId, EnumFileType fileType)
{
return tc.ExecuteReader("SELECT * FROM TaxAttachment where ReferenceID= %n and FileType=%n ", refId, (int)fileType);
}
internal static IDataReader GetByReferenceandFileId(TransactionContext tc, int refId, EnumFileType fileType, int id)
{
return tc.ExecuteReader("SELECT * FROM TaxAttachment where ReferenceID= %n and FileType=%n and TAXATTACHMENTID=%n", refId, (int)fileType, id);
}
internal static void Delete(TransactionContext tc, int refID, EnumFileType type)
{
string sql = SQLParser.MakeSQL(@"DELETE FROM TaxAttachment WHERE ReferenceID = %n AND FileType = %n", refID, type);
tc.ExecuteNonQuery(sql);
}
}
}