Moved DocPDF from Documents to PDFs table

Moved DocPDF from Documents to new PDFs table
This commit is contained in:
Rich 2011-04-18 21:30:48 +00:00
parent f4a3a969f4
commit 628cfc67de
5 changed files with 203 additions and 66 deletions

View File

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using Csla.Validation;
namespace VEPROMS.CSLA.Library
{
public partial class Pdf
{
public static void DeleteAll(int docID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Pdf");
try
{
DataPortal.Delete(new DocIDCriteria(docID));
}
catch (Exception ex)
{
throw new DbCslaException("Error on Pdf.Delete", ex);
}
}
[Serializable()]
protected class DocIDCriteria
{
private int _DocID;
public int DocID
{ get { return _DocID; } }
public DocIDCriteria(int docID)
{
_DocID = docID;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(DocIDCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.DataPortal_Delete", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "deleteAllPdfs";
cm.Parameters.AddWithValue("@DocID", criteria.DocID);
cm.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.DataPortal_Delete", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Pdf.DataPortal_Delete", ex);
}
}
}
public partial class PdfInfo
{
public static PdfInfo Get(ItemInfo sect)
{
int count = 0;
while (count < 2)
{
DocStyle myDocStyle = sect.ActiveSection.MyDocStyle;
PdfInfo myPdf = Get(sect.MyContent.MyEntry.DocID, MSWordToPDF.DebugStatus, (int)myDocStyle.Layout.TopRow, (int)myDocStyle.Layout.PageLength,
(int)myDocStyle.Layout.LeftMargin, (int)myDocStyle.Layout.PageWidth);
if (myPdf != null) return myPdf;
if (count > 0) return null; // Could not find or create a pdf
MSWordToPDF.SetDocPdf(sect.MyContent.MyEntry.MyDocument, sect);
count++;
}
return null;
}
}
public partial class PdfInfoList
{
}
}

View File

@ -34,7 +34,8 @@ namespace VEPROMS.CSLA.Library
private List<Document> _RefreshDocuments = new List<Document>();
private List<DocumentDROUsage> _RefreshDocumentDROUsages = new List<DocumentDROUsage>();
private List<DocumentEntry> _RefreshDocumentEntries = new List<DocumentEntry>();
private void AddToRefreshList(List<Document> refreshDocuments, List<DocumentDROUsage> refreshDocumentDROUsages, List<DocumentEntry> refreshDocumentEntries)
private List<DocumentPdf> _RefreshDocumentPdfs = new List<DocumentPdf>();
private void AddToRefreshList(List<Document> refreshDocuments, List<DocumentDROUsage> refreshDocumentDROUsages, List<DocumentEntry> refreshDocumentEntries, List<DocumentPdf> refreshDocumentPdfs)
{
if (IsDirty)
refreshDocuments.Add(this);
@ -52,13 +53,21 @@ namespace VEPROMS.CSLA.Library
if (tmp.IsDirty) refreshDocumentEntries.Add(tmp);
}
}
if (_DocumentPdfs != null && _DocumentPdfs.IsDirty)
{
foreach (DocumentPdf tmp in _DocumentPdfs)
{
if (tmp.IsDirty) refreshDocumentPdfs.Add(tmp);
}
}
}
private void BuildRefreshList()
{
_RefreshDocuments = new List<Document>();
_RefreshDocumentDROUsages = new List<DocumentDROUsage>();
_RefreshDocumentEntries = new List<DocumentEntry>();
AddToRefreshList(_RefreshDocuments, _RefreshDocumentDROUsages, _RefreshDocumentEntries);
_RefreshDocumentPdfs = new List<DocumentPdf>();
AddToRefreshList(_RefreshDocuments, _RefreshDocumentDROUsages, _RefreshDocumentEntries, _RefreshDocumentPdfs);
}
private void ProcessRefreshList()
{
@ -74,6 +83,10 @@ namespace VEPROMS.CSLA.Library
{
EntryInfo.Refresh(tmp);
}
foreach (DocumentPdf tmp in _RefreshDocumentPdfs)
{
PdfInfo.Refresh(this, tmp);
}
}
#endregion
#region Collection
@ -283,26 +296,6 @@ namespace VEPROMS.CSLA.Library
}
}
}
private byte[] _DocPdf;
public byte[] DocPdf
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DocPdf", true);
return _DocPdf;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("DocPdf", true);
if (_DocPdf != value)
{
_DocPdf = value;
PropertyHasChanged();
}
}
}
private int _DocumentDROUsageCount = 0;
/// <summary>
/// Count of DocumentDROUsages for this Document
@ -377,6 +370,43 @@ namespace VEPROMS.CSLA.Library
{
_DocumentEntryCount = -1;
}
private int _DocumentPdfCount = 0;
/// <summary>
/// Count of DocumentPdfs for this Document
/// </summary>
public int DocumentPdfCount
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DocumentPdfCount", true);
return _DocumentPdfCount;
}
}
private DocumentPdfs _DocumentPdfs = null;
/// <summary>
/// Related Field
/// </summary>
[TypeConverter(typeof(DocumentPdfsConverter))]
public DocumentPdfs DocumentPdfs
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DocumentPdfs", true);
if (_DocumentPdfCount < 0 || (_DocumentPdfCount > 0 && _DocumentPdfs == null))
_DocumentPdfs = DocumentPdfs.GetByDocID(DocID);
if (_DocumentPdfCount < 0 )
_DocumentPdfCount = _DocumentPdfs == null ? 0 : _DocumentPdfs.Count;
if (_DocumentPdfs == null)
_DocumentPdfs = DocumentPdfs.New();
return _DocumentPdfs;
}
}
public void Reset_DocumentPdfs()
{
_DocumentPdfCount = -1;
}
public override bool IsDirty
{
get
@ -391,7 +421,7 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_DocumentDROUsages == null ? false : _DocumentDROUsages.IsDirtyList(list)) || (_DocumentEntries == null ? false : _DocumentEntries.IsDirtyList(list));
return base.IsDirty || (_DocumentDROUsages == null ? false : _DocumentDROUsages.IsDirtyList(list)) || (_DocumentEntries == null ? false : _DocumentEntries.IsDirtyList(list)) || (_DocumentPdfs == null ? false : _DocumentPdfs.IsDirtyList(list));
}
public override bool IsValid
{
@ -402,7 +432,7 @@ namespace VEPROMS.CSLA.Library
if(list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_DocumentDROUsages == null ? true : _DocumentDROUsages.IsValidList(list)) && (_DocumentEntries == null ? true : _DocumentEntries.IsValidList(list));
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_DocumentDROUsages == null ? true : _DocumentDROUsages.IsValidList(list)) && (_DocumentEntries == null ? true : _DocumentEntries.IsValidList(list)) && (_DocumentPdfs == null ? true : _DocumentPdfs.IsValidList(list));
}
// CSLATODO: Replace base Document.ToString function as necessary
/// <summary>
@ -438,6 +468,7 @@ namespace VEPROMS.CSLA.Library
IVEHasBrokenRules hasBrokenRules = null;
if (_DocumentEntries != null && (hasBrokenRules = _DocumentEntries.HasBrokenRules) != null) return hasBrokenRules;
if (_DocumentDROUsages != null && (hasBrokenRules = _DocumentDROUsages.HasBrokenRules) != null) return hasBrokenRules;
if (_DocumentPdfs != null && (hasBrokenRules = _DocumentPdfs.HasBrokenRules) != null) return hasBrokenRules;
return hasBrokenRules;
}
finally
@ -509,7 +540,6 @@ namespace VEPROMS.CSLA.Library
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(FileExtension, "<Role(s)>");
//AuthorizationRules.AllowRead(DocPdf, "<Role(s)>");
//AuthorizationRules.AllowWrite(LibTitle, "<Role(s)>");
//AuthorizationRules.AllowWrite(DocContent, "<Role(s)>");
//AuthorizationRules.AllowWrite(DocAscii, "<Role(s)>");
@ -517,7 +547,6 @@ namespace VEPROMS.CSLA.Library
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FileExtension, "<Role(s)>");
//AuthorizationRules.AllowWrite(DocPdf, "<Role(s)>");
_DocumentExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@ -556,6 +585,7 @@ namespace VEPROMS.CSLA.Library
int usedByCount = 0;
usedByCount += _DocumentDROUsageCount;
usedByCount += _DocumentEntryCount;
usedByCount += _DocumentPdfCount;
return (usedByCount == 0);
}
}
@ -607,7 +637,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on Document.New", ex);
}
}
public static Document New(string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf)
public static Document New(string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension)
{
Document tmp = Document.New();
tmp.LibTitle = libTitle;
@ -617,12 +647,11 @@ namespace VEPROMS.CSLA.Library
tmp.DTS = dts;
tmp.UserID = userID;
tmp.FileExtension = fileExtension;
tmp.DocPdf = docPdf;
return tmp;
}
public static Document MakeDocument(string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf)
public static Document MakeDocument(string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension)
{
Document tmp = Document.New(libTitle, docContent, docAscii, config, dts, userID, fileExtension, docPdf);
Document tmp = Document.New(libTitle, docContent, docAscii, config, dts, userID, fileExtension);
if (tmp.IsSavable)
{
Document tmp2 = tmp;
@ -640,19 +669,18 @@ namespace VEPROMS.CSLA.Library
}
return tmp;
}
public static Document New(string libTitle, byte[] docContent, string docAscii, string config, byte[] docPdf)
public static Document New(string libTitle, byte[] docContent, string docAscii, string config)
{
Document tmp = Document.New();
tmp.LibTitle = libTitle;
tmp.DocContent = docContent;
tmp.DocAscii = docAscii;
tmp.Config = config;
tmp.DocPdf = docPdf;
return tmp;
}
public static Document MakeDocument(string libTitle, byte[] docContent, string docAscii, string config, byte[] docPdf)
public static Document MakeDocument(string libTitle, byte[] docContent, string docAscii, string config)
{
Document tmp = Document.New(libTitle, docContent, docAscii, config, docPdf);
Document tmp = Document.New(libTitle, docContent, docAscii, config);
if (tmp.IsSavable)
{
Document tmp2 = tmp;
@ -777,9 +805,9 @@ namespace VEPROMS.CSLA.Library
_UserID = dr.GetString("UserID");
dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8);
_FileExtension = dr.GetString("FileExtension");
_DocPdf = (byte[])dr.GetValue("DocPdf");
_DocumentDROUsageCount = dr.GetInt32("DROUsageCount");
_DocumentEntryCount = dr.GetInt32("EntryCount");
_DocumentPdfCount = dr.GetInt32("PdfCount");
MarkOld();
}
catch (Exception ex)
@ -816,6 +844,9 @@ namespace VEPROMS.CSLA.Library
// load child objects
dr.NextResult();
_DocumentEntries = DocumentEntries.Get(dr);
// load child objects
dr.NextResult();
_DocumentPdfs = DocumentPdfs.Get(dr);
}
}
// removing of item only needed for local data portal
@ -874,7 +905,6 @@ namespace VEPROMS.CSLA.Library
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@FileExtension", _FileExtension);
cm.Parameters.AddWithValue("@DocPdf", _DocPdf);
// Output Calculated Columns
SqlParameter param_DocID = new SqlParameter("@newDocID", SqlDbType.Int);
param_DocID.Direction = ParameterDirection.Output;
@ -892,6 +922,7 @@ namespace VEPROMS.CSLA.Library
// update child objects
if (_DocumentEntries != null) _DocumentEntries.Update(this);
if (_DocumentDROUsages != null) _DocumentDROUsages.Update(this);
if (_DocumentPdfs != null) _DocumentPdfs.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.SQLInsert", GetHashCode());
}
catch (Exception ex)
@ -902,7 +933,7 @@ namespace VEPROMS.CSLA.Library
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf)
public static byte[] Add(SqlConnection cn, ref int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.Add", 0);
try
@ -919,7 +950,6 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@FileExtension", fileExtension);
cm.Parameters.AddWithValue("@DocPdf", docPdf);
// Output Calculated Columns
SqlParameter param_DocID = new SqlParameter("@newDocID", SqlDbType.Int);
param_DocID.Direction = ParameterDirection.Output;
@ -987,7 +1017,6 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
cm.Parameters.AddWithValue("@FileExtension", _FileExtension);
cm.Parameters.AddWithValue("@DocPdf", _DocPdf);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
@ -1002,6 +1031,7 @@ namespace VEPROMS.CSLA.Library
// use the open connection to update child objects
if (_DocumentEntries != null) _DocumentEntries.Update(this);
if (_DocumentDROUsages != null) _DocumentDROUsages.Update(this);
if (_DocumentPdfs != null) _DocumentPdfs.Update(this);
}
catch (Exception ex)
{
@ -1017,16 +1047,17 @@ namespace VEPROMS.CSLA.Library
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Document.Add(cn, ref _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, _FileExtension, _DocPdf);
_LastChanged = Document.Add(cn, ref _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, _FileExtension);
else
_LastChanged = Document.Update(cn, ref _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, ref _LastChanged, _FileExtension, _DocPdf);
_LastChanged = Document.Update(cn, ref _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, ref _LastChanged, _FileExtension);
MarkOld();
}
if (_DocumentEntries != null) _DocumentEntries.Update(this);
if (_DocumentDROUsages != null) _DocumentDROUsages.Update(this);
if (_DocumentPdfs != null) _DocumentPdfs.Update(this);
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, ref byte[] lastChanged, string fileExtension, byte[] docPdf)
public static byte[] Update(SqlConnection cn, ref int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, ref byte[] lastChanged, string fileExtension)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.Update", 0);
try
@ -1045,7 +1076,6 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
cm.Parameters.AddWithValue("@FileExtension", fileExtension);
cm.Parameters.AddWithValue("@DocPdf", docPdf);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;

View File

@ -176,16 +176,6 @@ namespace VEPROMS.CSLA.Library
return _FileExtension;
}
}
private byte[] _DocPdf;
public byte[] DocPdf
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DocPdf", true);
return _DocPdf;
}
}
private int _DocumentDROUsageCount = 0;
/// <summary>
/// Count of DocumentDROUsages for this Document
@ -262,6 +252,44 @@ namespace VEPROMS.CSLA.Library
foreach (DocumentInfo tmp in _CacheByPrimaryKey[_DocID.ToString()])
tmp._DocumentEntryCount = -1; // This will cause the data to be requeried
}
private int _DocumentPdfCount = 0;
/// <summary>
/// Count of DocumentPdfs for this Document
/// </summary>
public int DocumentPdfCount
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DocumentPdfCount", true);
if (_DocumentPdfCount < 0)
_DocumentPdfCount = DocumentPdfs.Count;
return _DocumentPdfCount;
}
}
private PdfInfoList _DocumentPdfs = null;
[TypeConverter(typeof(PdfInfoListConverter))]
public PdfInfoList DocumentPdfs
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DocumentPdfs", true);
if (_DocumentPdfCount < 0 || (_DocumentPdfCount > 0 && _DocumentPdfs == null))
_DocumentPdfs = PdfInfoList.GetByDocID(_DocID);
if (_DocumentPdfCount < 0)
_DocumentPdfCount = _DocumentPdfs.Count;
return _DocumentPdfs;
}
}
public void RefreshDocumentPdfs()
{
_DocumentPdfCount = -1;
ConvertListToDictionary();
if (_CacheByPrimaryKey.ContainsKey(_DocID.ToString()))
foreach (DocumentInfo tmp in _CacheByPrimaryKey[_DocID.ToString()])
tmp._DocumentPdfCount = -1; // This will cause the data to be requeried
}
// CSLATODO: Replace base DocumentInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
@ -322,7 +350,6 @@ namespace VEPROMS.CSLA.Library
_DTS = tmp.DTS;
_UserID = tmp.UserID;
_FileExtension = tmp.FileExtension;
_DocPdf = tmp.DocPdf;
_DocumentInfoExtension.Refresh(this);
OnChange();// raise an event
}
@ -389,9 +416,9 @@ namespace VEPROMS.CSLA.Library
_DTS = dr.GetDateTime("DTS");
_UserID = dr.GetString("UserID");
_FileExtension = dr.GetString("FileExtension");
_DocPdf = (byte[])dr.GetValue("DocPdf");
_DocumentDROUsageCount = dr.GetInt32("DROUsageCount");
_DocumentEntryCount = dr.GetInt32("EntryCount");
_DocumentPdfCount = dr.GetInt32("PdfCount");
}
catch (Exception ex)
{

View File

@ -109,6 +109,8 @@ namespace VEPROMS.CSLA.Library
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class DocumentEntry
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class DocumentPdf
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class DocumentInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class DocVersion
@ -185,6 +187,10 @@ namespace VEPROMS.CSLA.Library
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class PartInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Pdf
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class PdfInfo
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class Permission
// { public override string ToString() { return string.Format("{0}", _Name); } }
// public partial class PermissionInfo

View File

@ -253,16 +253,6 @@ namespace VEPROMS.CSLA.Library
return _Document_FileExtension;
}
}
private byte[] _Document_DocPdf;
public byte[] Document_DocPdf
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("Document_DocPdf", true);
return _Document_DocPdf;
}
}
// CSLATODO: Check RODbDROUsage.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
@ -485,7 +475,6 @@ namespace VEPROMS.CSLA.Library
_Document_DTS = dr.GetDateTime("Document_DTS");
_Document_UserID = dr.GetString("Document_UserID");
_Document_FileExtension = dr.GetString("Document_FileExtension");
_Document_DocPdf = (byte[])dr.GetValue("Document_DocPdf");
}
catch (Exception ex) // FKItem Fetch
{