Esempio n. 1
0
 public bool Delete(AttachmentObject attachment)
 {
     try
     {
         Config.Conn.Execute("DELETE FROM dat_AttachmentFile WHERE AttachmentId = @AttachmentId", attachment);
         Config.Conn.Execute("DELETE FROM dat_Attachment WHERE AttachmentId = @AttachmentId", attachment);
     }
     catch
     {
         return(false);
     }
     return(true);
 }
Esempio n. 2
0
 public AttachmentObject SaveAttachment(AttachmentObject attachment)
 {
     if (attachment.AttachmentId > 0) // Update
     {
         string sql = @"
             UPDATE  dat_Attachment
             SET     IsDeleted = @IsDeleted,
                     DeletedByEmployeeId = @DeletedByEmployeeId,
                     DeletedDate = @DeletedDate                            
             WHERE   AttachmentId = @AttachmentId";
         Config.Conn.Execute(sql, attachment);
     }
     else
     {
         string sql = @"
             INSERT INTO dat_Attachment (
                 MainId,
                 UploadDate,
                 UploadEmployeeId,
                 FileName,
                 Note,
                 IsDeleted,
                 DeletedByEmployeeId,
                 DeletedDate,
                 Size,
                 NumberPages,
                 AdminOnly
             )
             VALUES (
                 @MainId,
                 @UploadDate,
                 @UploadEmployeeId,
                 @FileName,
                 @Note,
                 @IsDeleted,
                 @DeletedByEmployeeId,
                 @DeletedDate,
                 @Size,
                 @NumberPages,
                 @AdminOnly
             )
             SELECT CAST(SCOPE_IDENTITY() AS INT)";
         attachment.AttachmentId = Config.Conn.Query <int>(sql, attachment).Single();
     }
     return(attachment);
 }
Esempio n. 3
0
        public static AttachmentObject AddAttachment(int mainId, string fileName, string description, int?size, int?numberPages, bool adminOnly = false, string employeeId = null)
        {
            string sizeStr = string.Empty;

            if (size.HasValue)
            {
                double num = (double)size.Value / 1024.0;
                if (num > 999999.99) //GigaBytes
                {
                    sizeStr = $"{(num / 1000000.0):F3} GB";
                }
                else if (num > 999.99) //MegaBytes
                {
                    sizeStr = $"{(num / 1000.0):F2} MB";
                }
                else //KiloBytes
                {
                    sizeStr = $"{num:F2} KB";
                }
            }

            var sao = new AttachmentObject()
            {
                MainId           = mainId,
                FileName         = fileName,
                Note             = description,
                IsDeleted        = false,
                Size             = sizeStr,
                NumberPages      = numberPages,
                UploadEmployeeId = employeeId,
                AdminOnly        = adminOnly
            };

            sao.Save();
            MainObject.UpdateActivityDateToNow(mainId);

            return(sao);
        }