using Ease.Core.DataAccess; using HRM.BO; using Microsoft.Data.SqlClient; using System; using System.Configuration; using System.Data; namespace HRM.DA { internal class FileAttachmentDA { //internal static void Insert(TransactionContext tc, FileAttachment item) //{ // tc.ExecuteNonQuery("INSERT INTO FileAttachment(ReferenceID, FileData, OriginalFileName,FileType)" + // " VALUES(%n,%s,%s,%n)", item.ReferenceID, item.FileTobase64, item.OriginalFileName,(int)item.FileType); //} public static void Insert(FileAttachment item, string connectionString) { // string ConnString = ConfigurationSettings.AppSettings["default"]; // var ConnString = System.Configuration.ConfigurationManager.GetSection("dbSettings"); // string ConnString=ConfigurationManager.ConnectionStrings[connectionString].ConnectionString; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = connection; string commandText = @"INSERT INTO FileAttachment(ReferenceID, FileData, OriginalFileName,FileType,RefChildId) Values (@ReferenceID,@FileData,@OriginalFileName,@FileType,@RefChildId)"; cmd.CommandText = commandText; cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@ReferenceID", SqlDbType.Int); cmd.Parameters["@ReferenceID"].Value = item.ReferenceID; cmd.Parameters.Add("@OriginalFileName", SqlDbType.VarChar); cmd.Parameters["@OriginalFileName"].Value = item.OriginalFileName; cmd.Parameters.Add("@FileData", SqlDbType.VarBinary); cmd.Parameters["@FileData"].Value = item.FileAsByteArray; cmd.Parameters.Add("@FileType", SqlDbType.Int); cmd.Parameters["@FileType"].Value =(int)item.FileType; cmd.Parameters.Add("@RefChildId", SqlDbType.Int); cmd.Parameters["@RefChildId"].Value = item.RefchildID == null ? 0 : item.RefchildID; cmd.ExecuteNonQuery(); cmd.Dispose(); connection.Close(); } } internal static IDataReader GetByReferenceId(TransactionContext tc, int refId,EnumFileType fileType) { return tc.ExecuteReader("SELECT * FROM FileAttachment where referenceId= %n and fileType=%n ", refId,(int)fileType); } internal static IDataReader GetByRefChildId(TransactionContext tc, int refId, EnumFileType fileType,int refChildId) { return tc.ExecuteReader("SELECT * FROM FileAttachment where referenceId= %n and fileType=%n and RefChildId=%n", refId, (int)fileType, refChildId); } internal static IDataReader GetByReferenceandFileId(TransactionContext tc, int refId, EnumFileType fileType, int id) { return tc.ExecuteReader("SELECT * FROM FileAttachment where referenceId= %n and fileType=%n and FILEATTACHMENTID=%n", refId, (int)fileType,id); } internal static void Delete(TransactionContext tc, int refID, EnumFileType type) { string sql = SQLParser.MakeSQL(@"DELETE FROM FILEATTACHMENT WHERE REFERENCEID = %n AND FILETYPE = %n", refID, type); tc.ExecuteNonQuery(sql); } internal static IDataReader GetCv(TransactionContext tc, int refId) { return tc.ExecuteReader("SELECT * FROM FileAttachment where referenceId= %n and FILETYPE in (%n,%n)", refId, (int)EnumFileType.CV, (int)EnumFileType.CVProfilePhoto); } internal static IDataReader GetErCv(TransactionContext tc, int refId) { return tc.ExecuteReader("SELECT * FROM FileAttachment where referenceId= %n and FILETYPE in (%n,%n)", refId, (int)EnumFileType.ErCV, (int)EnumFileType.ErCVProfilePhoto); } } }