Compare commits

..
Author SHA1 Message Date
mschill 49a3e647a2 Merge branch 'Development' into C2026-043-Tech-Debt_v1 2026-10-01 10:12:01 -04:00
jjenko 95a3039c96 Merge pull request 'C2026-060 Export with slash in folder name' (#824) from C2026-060 into Development
good for testing
2026-10-01 10:10:29 -04:00
jjenko ae2f765119 Merge pull request 'B2026-084 Spell Check crashing' (#823) from B2026-084 into Development
good for testing
2026-10-01 10:09:38 -04:00
mschill 9e85b43f64 Sleep when closing tabs 2026-10-01 09:00:59 -04:00
mschill 14fd0d34e2 C2026-060 Export with slash in folder name 2026-10-01 08:00:13 -04:00
mschill d045205d16 B2026-084 Spell Check crashing 2026-10-01 07:32:44 -04:00
mschill b2741d341c Bring up to date with Dev -- clearing merge conflicts 2026-09-30 10:23:57 -04:00
mschill abe0444275 Merge pull request 'F2026-023 Code fix to so that single Notes do not get a bullet and format tweaks in the EOP and SAMG formats' (#822) from F2026-023_Farley_Arial_Tweaks into Development
Looks Good. Ready for QA.
2026-09-30 10:08:11 -04:00
jjenko 576b967f57 F2026-023 Code fix to so that single Notes do not get a bullet and format tweaks in the EOP and SAMG formats 2026-09-30 10:04:20 -04:00
jjenko 6481e6cbba Merge pull request 'B2026-080 – Remove unicode from the Document Already Checked Out message box' (#821) from B2026-080 into Development
good for testing
2026-09-30 08:20:44 -04:00
mschill c151a9676f Merge branch 'Development' into B2026-080 2026-09-30 08:10:06 -04:00
mschill dddc464bad B2026-080 – Remove unicode from the Document Already Checked Out message box 2026-09-30 08:12:40 -04:00
jjenko b1bc954105 Merge pull request 'Remove Debug items from Source control that never should have been checked in for W2PGrid' (#820) from Clean_Debug_W2PGrid into Development
just moved un-used stuff out of project
No testing needed.
2026-09-29 09:25:20 -04:00
mschill 1ad5331ba9 Remove Debug items from Source control that never should have been checked in for W2PGrid 2026-09-29 07:51:33 -04:00
mschill 8c8c876309 Remove SCLA Scoping 2026-09-23 11:04:30 -04:00
mschill 874f9241b8 Clean up in frmVEPROMS.cs --- hard coded based on RICH's PC name 2026-09-22 09:03:42 -04:00
mschill a680e8800d Add back in removed side effect code for printing grids with merged cells / checking boundaries 2026-09-15 13:30:48 -04:00
mschill 17e9a88a16 Merge branch 'Development' into C2026-043-Tech-Debt_v1 2026-09-15 13:13:13 -04:00
mschill 8df20f32ce Merge pull request 'B2026-076 - Update Base format to move new type to bottom' (#818) from B2026-076 into Development
Ready for QA
2026-09-15 11:59:46 -04:00
mschill 6ca427a7c6 B2026-076 - Update Base format to move new 2026-09-15 12:01:22 -04:00
mschill fe95afcf8f avoid Local Context 2026-09-15 08:29:29 -04:00
mschill 7c95b115e4 Check if connection state is closed before opening 2026-09-15 08:21:18 -04:00
mschill 5d4e5d9a1f Make Sure Connection is open when working with Local Context 2026-09-15 08:06:53 -04:00
mschill ac773b8ada Remove commented out code 2026-09-14 15:48:34 -04:00
mschill 42f1c1735d Merge branch 'Development' into C2026-043-Tech-Debt_v1 2026-09-14 15:31:58 -04:00
mschill 1c6f3e3e3c CSLA - R to Z 2026-09-14 15:30:10 -04:00
mschill 14a8922976 Merge pull request 'C2026-054 Text change for Open Tabs from Previous Session dialog box' (#815) from C2026-054-Text-change-for-Open-Tabs-from-Previous-Session into Development
Looks Good. Ready for QA.
2026-09-14 05:36:50 -04:00
plarsen 2f5affabbe C2026-054-Text-change-for-Open-Tabs-from-Previous-Session 2026-09-12 07:47:56 -04:00
mschill d238d6aed2 CSLA - R - Group 1 2026-09-11 16:03:51 -04:00
plarsen 44c86e5d80 C2026-054-Text-change-for-Open-Tabs-from-Previous-Session 2026-09-11 12:13:16 -04:00
mschill d9f8f6cb37 CSLA - M through P 2026-09-11 09:50:40 -04:00
plarsen d5859f2a01 C2026-054-Text-change-for-Open-Tabs-from-Previous-Session 2026-09-10 16:10:08 -04:00
mschill e41a4ea65d CSLA - Is 2026-09-10 16:02:04 -04:00
jjenko 506c826eb3 Merge pull request 'C2026 048 tool tip update' (#814) from C2026-048-Tool-Tip-Update into Development
good for testing phase
2026-09-10 14:00:18 -04:00
plarsen 96839f8379 Merge branch 'Development' into C2026-048-Tool-Tip-Update 2026-09-10 13:53:21 -04:00
plarsen f6e42d933e C2026-048-Tool-Tip-Update 2026-09-10 11:11:06 -04:00
mschill 8674b93723 Merge branch 'Development' into C2026-043-Tech-Debt_v1 2026-09-09 15:54:32 -04:00
mschill da8d25082f CSLA - G 2026-09-09 15:52:32 -04:00
mschill 28b79bf81b Merge pull request 'C2026-053' (#813) from C2026-053_restore_only_Proc_section_tabs into Development
Looks Good - Ready For QA
2026-09-09 14:54:21 -04:00
jjenko a87e23af7e C2026-053
When restoring the open procedure tabs while starting up PROMS, don’t restore any of the Word section tabs.
2026-09-09 14:51:51 -04:00
mschill f2b064f459 CSLA - E & F 2026-09-09 14:08:28 -04:00
mschill a69a2270a6 CLSA - Ds 2026-09-08 08:55:36 -04:00
210 changed files with 11165 additions and 36916 deletions

No files matched your search

Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -50,7 +50,7 @@ namespace RODBInterface
SqlConnection cn = new SqlConnection(SqlConnectionStr);
try
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (OnlyConnectOnce && ROAPP_SqlConnectionOnce == null) ROAPP_SqlConnectionOnce = cn;
return cn;
}
+10 -9
View File
@@ -1,4 +1,5 @@
namespace VEPROMS
{
partial class dlgCheckOpenTabs
@@ -42,12 +43,12 @@ namespace VEPROMS
//
this.labelX1.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
this.labelX1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.labelX1.Location = new System.Drawing.Point(23, 2);
this.labelX1.Location = new System.Drawing.Point(23, 5);
this.labelX1.Name = "labelX1";
this.labelX1.Size = new System.Drawing.Size(363, 78);
this.labelX1.Size = new System.Drawing.Size(363, 90);
this.labelX1.TabIndex = 0;
this.labelX1.Text = "Would you like for PROMS to reopen the tabs that you had open during your last se" +
"ssion?";
"ssion?" + System.Environment.NewLine + System.Environment.NewLine + "NOTE: This will not apply to Word section tabs that were previously open.";
this.labelX1.WordWrap = true;
//
// cbRemember
@@ -56,20 +57,20 @@ namespace VEPROMS
//
//
this.cbRemember.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
this.cbRemember.Location = new System.Drawing.Point(23, 75);
this.cbRemember.Location = new System.Drawing.Point(23, 100);
this.cbRemember.Name = "cbRemember";
this.cbRemember.Size = new System.Drawing.Size(376, 47);
this.cbRemember.Size = new System.Drawing.Size(376, 55);
this.cbRemember.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
this.cbRemember.TabIndex = 1;
this.cbRemember.Text = "Check this box to not be prompted in the future when opening PROMS. \nNote that th" +
"ese settings can be adjusted at any time from the \nOPTIONS menu for PROMS.";
"ese settings can be adjusted at any time from the \nOPTIONS menu for PROMS.";
//
// btnOpenTabs
//
this.btnOpenTabs.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
this.btnOpenTabs.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
this.btnOpenTabs.DialogResult = System.Windows.Forms.DialogResult.Yes;
this.btnOpenTabs.Location = new System.Drawing.Point(23, 139);
this.btnOpenTabs.Location = new System.Drawing.Point(23, 165);
this.btnOpenTabs.Name = "btnOpenTabs";
this.btnOpenTabs.Size = new System.Drawing.Size(150, 42);
this.btnOpenTabs.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
@@ -82,7 +83,7 @@ namespace VEPROMS
this.btnNoTabs.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
this.btnNoTabs.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
this.btnNoTabs.DialogResult = System.Windows.Forms.DialogResult.No;
this.btnNoTabs.Location = new System.Drawing.Point(216, 139);
this.btnNoTabs.Location = new System.Drawing.Point(216, 165);
this.btnNoTabs.Name = "btnNoTabs";
this.btnNoTabs.Size = new System.Drawing.Size(150, 42);
this.btnNoTabs.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
@@ -94,7 +95,7 @@ namespace VEPROMS
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(411, 193);
this.ClientSize = new System.Drawing.Size(411, 220);
this.ControlBox = false;
this.Controls.Add(this.btnNoTabs);
this.Controls.Add(this.btnOpenTabs);
@@ -163,7 +163,7 @@ namespace VEPROMS
}
if (MyFolder != null)
{
sfd.FileName = string.Format("{0}-{1}.expx", Database.ActiveDatabase, MyFolder.Name);
sfd.FileName = string.Format("{0}-{1}.expx", Database.ActiveDatabase, MyFolder.Name.Replace("/", "_").Replace("\\", "_"));
if (sfd.ShowDialog(this) == DialogResult.OK && sfd.FileName != string.Empty)
{
txtExport.Text = sfd.FileName;
+9 -33
View File
@@ -66,10 +66,6 @@ namespace VEPROMS
}
else // Step Tab Panel
{
// The following line was broken into separate lines because a NullReferenceError was occurring.
// Now we should be able to tell what is wrong by which line causes the Null Reference Error
// RHM 20101217
//SelectedDVI = value.MyStepPanel.MyProcedureItemInfo.MyProcedure.ActiveParent as DocVersionInfo;
StepPanel stepPanel = value.MyStepPanel;
ItemInfo itemInfo = stepPanel.MyProcedureItemInfo;
ProcedureInfo procedureInfo = itemInfo.MyProcedure;
@@ -293,31 +289,7 @@ namespace VEPROMS
// cleanup from previous run:
TmpFile.RemoveAllTmps();
if (VlnSettings.DebugMode)
{
//use local data (for development/debug mode)
if (Environment.MachineName == "RMARK-PC")
Database.ConnectionName = "VEPROMS_RMARK_DEBUG";
else if (Environment.MachineName == "WINDOWS7-RHM")
Database.ConnectionName = "VEPROMS_RMARK_DEBUG";
else if (Environment.UserName.ToUpper() == "BODINE")
Database.ConnectionName = "VEPROMS_BODINE_DEBUG";
else
Database.ConnectionName = "VEPROMS_LOCAL";
}
else
{
// use server data (default)
// - except for the volian laptop and Rich's Demo version where we need to use local data
if (Environment.MachineName == "RMARK-PC")
Database.ConnectionName = "VEPROMS_RMARK_DEMO";
else if (Environment.MachineName == "WINDOWS7-RHM")
Database.ConnectionName = "VEPROMS_RMARK_DEMO";
else if (Environment.UserName.ToUpper() == "BODINE")
Database.ConnectionName = "VEPROMS_BODINE_DEMO";
else
Database.ConnectionName = "VEPROMS_LOCAL";
}
Database.ConnectionName = "VEPROMS_LOCAL";
InitializeComponent();
@@ -2452,13 +2424,16 @@ namespace VEPROMS
// B2026-074 added flag (LoadingSavedProcTabs) to supress unnecessary event calls
// this will help prevent PROMS from getting stuck continuously looping through the same events
// when Word procedure tabs are restored.
tc.LoadingSavedProcTabs = true;
// C2026-053 leaving this flag in her for now should we decide to trouble-shoot reopening of Word tabs later on.
tc.LoadingSavedProcTabs = true; // we check for this flag in DSOTabPanel.cs when opening Word sections
foreach (DataRow TabState in DisPlayTabState.Rows)
{
int _ItemID = (int)TabState["ItemID"];
ItemInfo _Procedure = ItemInfo.Get(_ItemID);
// Open procedure in the editor.
if (_Procedure == null) continue; //skip and continue with foreach
// C2026-053 Open procedure tab but only if it's NOT a Word section
// Needed to disable opening saved Word sections - at least for now.
// We were running into performace and random hanging issues with the Word tabs - maybe windows event related.
if (_Procedure == null || _Procedure.HasWordContent) continue; //skip and continue with foreach
OpenItem(_Procedure);
if (tc.MyEditItem == null) continue; // skip and continue with foreach
// SelectedStepTabPanel needs to be set so the print buttons on the ribbon will work.
@@ -3135,7 +3110,8 @@ namespace VEPROMS
_MyLog.WarnFormat("===============Override Close====================");
}
tc.CloseTabItem(dti);
System.Threading.Thread.Sleep(500); //wait 1/2 a second to see if it closes on it's own
tc.CloseTabItem(dti);
}
_TimeActivity1.Close();
@@ -283,7 +283,7 @@ namespace VEPROMS.CSLA.Library
_UserID = userID;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(DeleteCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Delete", GetHashCode());
@@ -324,7 +324,7 @@ namespace VEPROMS.CSLA.Library
_procList = procList;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(DeleteAnnotationProcByTypeCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Delete", GetHashCode());
@@ -365,7 +365,7 @@ namespace VEPROMS.CSLA.Library
_versionID = versionID;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(DeleteAnnotationDocvByTypeCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Delete Annotations by Type Docv", GetHashCode());
@@ -420,7 +420,7 @@ namespace VEPROMS.CSLA.Library
}
}
[Transactional(TransactionalTypes.TransactionScope)]
private getAnnotationCountProcCriteria DataPortal_Fetch(getAnnotationCountProcCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Fetch", GetHashCode());
@@ -477,7 +477,7 @@ namespace VEPROMS.CSLA.Library
}
}
[Transactional(TransactionalTypes.TransactionScope)]
private getAnnotationCountDocvCriteria DataPortal_Fetch(getAnnotationCountDocvCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Fetch", GetHashCode());
@@ -2388,7 +2388,7 @@ namespace VEPROMS.CSLA.Library
_UserID = userID;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(DeleteCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Delete", GetHashCode());
@@ -178,7 +178,7 @@ namespace VEPROMS.CSLA.Library
}
else if (si.ProcessID != ProcessID && objectType == CheckOutType.Document)
{
message = string.Format("The document {0} is already checked out to {1}", DocumentInfo.Get(objectID).DocumentEntries[0].MyContent.Text, si.UserID);
message = string.Format("The document {0} is already checked out to {1}", ItemInfo.ConvertToDisplayText(DocumentInfo.Get(objectID).DocumentEntries[0].MyContent.Text), si.UserID);
rv = rv && false;
}
else if (si.ProcessID != ProcessID && objectType == CheckOutType.DocVersion)
@@ -198,7 +198,7 @@ namespace VEPROMS.CSLA.Library
message = message + string.Format("The procedure {0} is already checked out to {1}", name, si.UserID) + Environment.NewLine;
}
else if (oi.OwnerType == 1)
message = message + string.Format("The document {0} is already checked out to {1}", DocumentInfo.Get(oi.OwnerItemID).DocumentEntries[0].MyContent.Text, si.UserID) + Environment.NewLine;
message = message + string.Format("The document {0} is already checked out to {1}", ItemInfo.ConvertToDisplayText(DocumentInfo.Get(oi.OwnerItemID).DocumentEntries[0].MyContent.Text), si.UserID) + Environment.NewLine;
else if (oi.OwnerType == 2)
message += string.Format("The working draft is already checked out to {0}", si.UserID);
rv = rv && false;
@@ -221,7 +221,7 @@ namespace VEPROMS.CSLA.Library
message = message + string.Format("The procedure {0} is already checked out to {1}", name, si.UserID) + Environment.NewLine;
}
else if (oi.OwnerType == 1)
message = message + string.Format("The document {0} is already checked out to {1}", DocumentInfo.Get(oi.OwnerItemID).DocumentEntries[0].MyContent.Text, si.UserID) + Environment.NewLine;
message = message + string.Format("The document {0} is already checked out to {1}", ItemInfo.ConvertToDisplayText(DocumentInfo.Get(oi.OwnerItemID).DocumentEntries[0].MyContent.Text), si.UserID) + Environment.NewLine;
else if (oi.OwnerType == 2)
message += string.Format("The working draft is already checked out to {0}", si.UserID);
else if (oi.OwnerType == 3)
@@ -25,7 +25,7 @@ namespace VEPROMS.CSLA.Library
public int DocID => _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());
@@ -610,7 +610,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Annotation.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -635,7 +635,7 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!IsDirty) return;
@@ -643,8 +643,9 @@ namespace VEPROMS.CSLA.Library
{
_MyAnnotationType?.Update();
_MyItem?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -688,7 +689,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Annotation.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int annotationID, Item myItem, AnnotationType myAnnotationType, string rtfText, string searchText, string config, DateTime dts, string userID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.Add", 0);
@@ -731,7 +732,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Annotation.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -754,7 +755,7 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -763,8 +764,9 @@ namespace VEPROMS.CSLA.Library
{
_MyAnnotationType?.Update();
_MyItem?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
@@ -811,8 +813,9 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return;
if (base.IsDirty)
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = Annotation.Add(cn, ref _AnnotationID, _MyItem, _MyAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID);
else
@@ -822,7 +825,7 @@ namespace VEPROMS.CSLA.Library
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int annotationID, int itemID, int typeID, string rtfText, string searchText, string config, DateTime dts, string userID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.Update", 0);
@@ -861,12 +864,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Annotation.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_AnnotationID));
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Delete", GetHashCode());
@@ -891,7 +894,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Annotation.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int annotationID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.Remove", 0);
@@ -943,7 +946,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -555,7 +555,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("AnnotationAudit.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -580,14 +580,15 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!IsDirty) return;
try
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -627,7 +628,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("AnnotationAudit.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Add(SqlConnection cn, ref long auditID, int annotationID, int itemID, int typeID, string rtfText, string searchText, string config, DateTime dts, string userID, int deleteStatus)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.Add", 0);
@@ -667,7 +668,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("AnnotationAudit.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -690,15 +691,16 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.SQLUpdate", GetHashCode());
try
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
@@ -740,8 +742,9 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return;
if (base.IsDirty)
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
AnnotationAudit.Add(cn, ref _AuditID, _AnnotationID, _ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, _DeleteStatus);
else
@@ -751,7 +754,7 @@ namespace VEPROMS.CSLA.Library
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Update(SqlConnection cn, ref long auditID, int annotationID, int itemID, int typeID, string rtfText, string searchText, string config, DateTime dts, string userID, int deleteStatus)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.Update", 0);
@@ -786,12 +789,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("AnnotationAudit.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_AuditID));
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.DataPortal_Delete", GetHashCode());
@@ -816,7 +819,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("AnnotationAudit.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, long auditID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.Remove", 0);
@@ -868,7 +871,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -691,7 +691,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("AnnotationType.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -716,14 +716,15 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!IsDirty) return;
try
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -765,7 +766,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("AnnotationType.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int typeID, string name, string config, DateTime dts, string userID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.Add", 0);
@@ -805,7 +806,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("AnnotationType.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -828,15 +829,16 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.SQLUpdate", GetHashCode());
try
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
@@ -881,8 +883,9 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return;
if (base.IsDirty)
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = AnnotationType.Add(cn, ref _TypeID, _Name, _Config, _DTS, _UserID);
else
@@ -893,7 +896,7 @@ namespace VEPROMS.CSLA.Library
}
_AnnotationTypeAnnotations?.Update(this);
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int typeID, string name, string config, DateTime dts, string userID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.Update", 0);
@@ -929,9 +932,9 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("AnnotationType.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_TypeID));
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.DataPortal_Delete", GetHashCode());
@@ -956,7 +959,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("AnnotationType.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int typeID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.Remove", 0);
@@ -1008,7 +1011,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -395,8 +395,9 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Annotation.Add(cn, ref _AnnotationID, _MyItem, myAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID);
}
@@ -406,8 +407,9 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Annotation.Update(cn, ref _AnnotationID, _ItemID, myAnnotationType.TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, ref _LastChanged);
}
@@ -420,8 +422,9 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return;
// if we're new then don't update the database
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Annotation.Remove(cn, _AnnotationID);
}
@@ -667,7 +667,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Assignment.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -692,7 +692,7 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!IsDirty) return;
@@ -701,8 +701,9 @@ namespace VEPROMS.CSLA.Library
_MyFolder?.Update();
_MyGroup?.Update();
_MyRole?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -746,7 +747,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Assignment.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int aid, Group myGroup, Role myRole, Folder myFolder, SmartDate startDate, SmartDate endDate, DateTime dts, string usrID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.Add", 0);
@@ -789,7 +790,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Assignment.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -812,7 +813,7 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -822,8 +823,9 @@ namespace VEPROMS.CSLA.Library
_MyFolder?.Update();
_MyGroup?.Update();
_MyRole?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
@@ -870,8 +872,9 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return;
if (base.IsDirty)
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = Assignment.Add(cn, ref _AID, _MyGroup, _MyRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID);
else
@@ -881,7 +884,7 @@ namespace VEPROMS.CSLA.Library
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int aid, int gid, int rid, int folderID, SmartDate startDate, SmartDate endDate, DateTime dts, string usrID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.Update", 0);
@@ -920,9 +923,9 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Assignment.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_AID));
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.DataPortal_Delete", GetHashCode());
@@ -947,7 +950,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Assignment.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int aid)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.Remove", 0);
@@ -999,7 +1002,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -648,7 +648,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Association.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -673,7 +673,7 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!IsDirty) return;
@@ -681,8 +681,9 @@ namespace VEPROMS.CSLA.Library
{
_MyDocVersion?.Update();
_MyROFst?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -724,7 +725,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Association.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int associationID, DocVersion myDocVersion, ROFst myROFst, string config, DateTime dts, string userID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.Add", 0);
@@ -765,7 +766,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Association.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -788,7 +789,7 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -797,8 +798,9 @@ namespace VEPROMS.CSLA.Library
{
_MyDocVersion?.Update();
_MyROFst?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
@@ -843,8 +845,9 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return;
if (base.IsDirty)
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = Association.Add(cn, ref _AssociationID, _MyDocVersion, _MyROFst, _Config, _DTS, _UserID);
else
@@ -854,7 +857,7 @@ namespace VEPROMS.CSLA.Library
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int associationID, int versionID, int rOFstID, string config, DateTime dts, string userID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.Update", 0);
@@ -891,9 +894,9 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Association.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_AssociationID));
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.DataPortal_Delete", GetHashCode());
@@ -918,7 +921,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Association.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int associationID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.Remove", 0);
@@ -970,7 +973,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
+16 -13
View File
@@ -567,7 +567,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Check.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -592,7 +592,7 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!IsDirty) return;
@@ -600,8 +600,9 @@ namespace VEPROMS.CSLA.Library
{
_MyRevision?.Update();
_MyStage?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -643,7 +644,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Check.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int checkID, Revision myRevision, Stage myStage, string consistencyChecks, DateTime dts, string userID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.Add", 0);
@@ -684,7 +685,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Check.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -707,7 +708,7 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -716,8 +717,9 @@ namespace VEPROMS.CSLA.Library
{
_MyRevision?.Update();
_MyStage?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
@@ -762,8 +764,9 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return;
if (base.IsDirty)
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = Check.Add(cn, ref _CheckID, _MyRevision, _MyStage, _ConsistencyChecks, _DTS, _UserID);
else
@@ -773,7 +776,7 @@ namespace VEPROMS.CSLA.Library
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int checkID, int revisionID, int stageID, string consistencyChecks, DateTime dts, string userID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.Update", 0);
@@ -810,9 +813,9 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Check.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_CheckID));
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.DataPortal_Delete", GetHashCode());
@@ -837,7 +840,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Check.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int checkID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.Remove", 0);
@@ -889,7 +892,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -705,7 +705,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Connection.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -730,14 +730,15 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!IsDirty) return;
try
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -782,7 +783,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Connection.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int dbid, string name, string title, string connectionString, int serverType, string config, DateTime dts, string usrID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.Add", 0);
@@ -825,7 +826,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Connection.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -848,15 +849,16 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.SQLUpdate", GetHashCode());
try
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
@@ -904,8 +906,9 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return;
if (base.IsDirty)
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = Connection.Add(cn, ref _DBID, _Name, _Title, _ConnectionString, _ServerType, _Config, _DTS, _UsrID);
else
@@ -916,7 +919,7 @@ namespace VEPROMS.CSLA.Library
}
_ConnectionFolders?.Update(this);
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int dbid, string name, string title, string connectionString, int serverType, string config, DateTime dts, string usrID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.Update", 0);
@@ -955,12 +958,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Connection.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_DBID));
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Delete", GetHashCode());
@@ -985,7 +988,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Connection.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int dbid)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.Remove", 0);
@@ -1037,7 +1040,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -429,8 +429,9 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Folder.Add(cn, ref _FolderID, Folder.Get(_ParentID), myConnection, _Name, _Title, _ShortName, _MyFormat, _ManualOrder, _Config, _DTS, _UsrID);
}
@@ -440,8 +441,9 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Folder.Update(cn, ref _FolderID, _ParentID, myConnection.DBID, _Name, _Title, _ShortName, _FormatID, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged);
}
@@ -454,8 +456,9 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return;
// if we're new then don't update the database
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Folder.Remove(cn, _FolderID);
}
+16 -13
View File
@@ -1037,7 +1037,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Content.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -1062,15 +1062,16 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!IsDirty) return;
try
{
_MyFormat?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -1123,7 +1124,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Content.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int contentID, string number, string text, int? type, Format myFormat, string config, DateTime dts, string userID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.Add", 0);
@@ -1166,7 +1167,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Content.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -1189,7 +1190,7 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -1197,8 +1198,9 @@ namespace VEPROMS.CSLA.Library
try
{
_MyFormat?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
@@ -1255,8 +1257,9 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return;
if (base.IsDirty)
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = Content.Add(cn, ref _ContentID, _Number, _Text, _Type, _MyFormat, _Config, _DTS, _UserID);
else
@@ -1275,7 +1278,7 @@ namespace VEPROMS.CSLA.Library
_ContentTransitions?.Update(this);
_MyZContent?.Update(this);
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.Update", 0);
@@ -1314,9 +1317,9 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Content.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_ContentID));
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Delete", GetHashCode());
@@ -1341,7 +1344,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Content.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int contentID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.Remove", 0);
@@ -1393,7 +1396,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -569,7 +569,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ContentAudit.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -594,14 +594,15 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!IsDirty) return;
try
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -641,7 +642,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ContentAudit.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Add(SqlConnection cn, ref long auditID, int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, int deleteStatus)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.Add", 0);
@@ -681,7 +682,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ContentAudit.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -704,15 +705,16 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.SQLUpdate", GetHashCode());
try
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
using (SqlCommand cm = cn.CreateCommand())
@@ -754,8 +756,9 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return;
if (base.IsDirty)
{
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
ContentAudit.Add(cn, ref _AuditID, _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, _DeleteStatus);
else
@@ -765,7 +768,7 @@ namespace VEPROMS.CSLA.Library
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Update(SqlConnection cn, ref long auditID, int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, int deleteStatus)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.Update", 0);
@@ -800,12 +803,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ContentAudit.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_AuditID));
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.DataPortal_Delete", GetHashCode());
@@ -830,7 +833,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ContentAudit.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, long auditID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.Remove", 0);
@@ -375,8 +375,9 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Detail.Add(cn, ref _DetailID, myContent, _ItemType, _Text, _Config, _DTS, _UserID);
}
@@ -386,8 +387,9 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Detail.Update(cn, ref _DetailID, myContent.ContentID, _ItemType, _Text, _Config, _DTS, _UserID, ref _LastChanged);
}
@@ -400,8 +402,9 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return;
// if we're new then don't update the database
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Detail.Remove(cn, _DetailID);
}
@@ -254,8 +254,9 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Item.Add(cn, ref _ItemID, Item.Get((int)_PreviousID), myContent, _DTS, _UserID);
}
@@ -265,8 +266,9 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Item.Update(cn, ref _ItemID, _PreviousID, myContent.ContentID, _DTS, _UserID, ref _LastChanged);
}
@@ -279,8 +281,9 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return;
// if we're new then don't update the database
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Item.Remove(cn, _ItemID);
}
@@ -324,8 +324,9 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Part.Add(cn, myContent, _FromType, _MyItem, _DTS, _UserID);
}
@@ -335,8 +336,9 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Part.Update(cn, myContent.ContentID, _FromType, _ItemID, _DTS, _UserID, ref _LastChanged);
}
@@ -348,8 +350,9 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return;
// if we're new then don't update the database
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Part.Remove(cn, myContent.ContentID, _FromType);
}
@@ -402,8 +402,9 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = RoUsage.Add(cn, ref _ROUsageID, myContent, _ROID, _Config, _DTS, _UserID, _MyRODb);
}
@@ -413,8 +414,9 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = RoUsage.Update(cn, ref _ROUsageID, myContent.ContentID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _RODbID);
}
@@ -427,8 +429,9 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return;
// if we're new then don't update the database
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
RoUsage.Remove(cn, _ROUsageID);
}
@@ -478,8 +478,9 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
string pattern = string.Format(@"<START\]\\v0([^#]*)\\v #Link:Transition(|Range):[0-9]* <CTID={0}>( [0-9]*){{1,2}}\[END>", _TransitionID);
Match m = Regex.Match(myContent.Text, pattern);
if (m.Groups.Count > 1 && m.Groups[1].Value.ToUpper().Contains("(PAGE ~)")) // B2020-089, check for upper case Page ~ in case step was upper cased
@@ -495,8 +496,9 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!IsDirty) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Transition.Update(cn, ref _TransitionID, myContent.ContentID, _ToID, _RangeID, _IsRange, _TranType, _Config, _DTS, _UserID, ref _LastChanged);
}
@@ -509,8 +511,9 @@ namespace VEPROMS.CSLA.Library
if (!IsDirty) return;
// if we're new then don't update the database
if (IsNew) return;
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Transition.Remove(cn, _TransitionID);
}
+132 -267
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -58,6 +56,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<DROUsage> _CacheList = new List<DROUsage>();
protected static void AddToCache(DROUsage dROUsage)
{
@@ -67,6 +66,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(dROUsage)) _CacheList.Remove(dROUsage); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<DROUsage>> _CacheByPrimaryKey = new Dictionary<string, List<DROUsage>>();
private static void ConvertListToDictionary()
{
@@ -92,15 +92,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextDROUsageID = -1;
public static int NextDROUsageID
{
get { return _nextDROUsageID--; }
}
public static int NextDROUsageID => _nextDROUsageID--;
private int _DROUsageID;
[System.ComponentModel.DataObjectField(true, true)]
public int DROUsageID
@@ -261,7 +255,7 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyDocument == null ? false : _MyDocument.IsDirtyList(list)) || (_MyRODb == null ? false : _MyRODb.IsDirtyList(list));
return base.IsDirty || (_MyDocument != null && _MyDocument.IsDirtyList(list)) || (_MyRODb != null && _MyRODb.IsDirtyList(list));
}
public override bool IsValid
{
@@ -270,28 +264,16 @@ namespace VEPROMS.CSLA.Library
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocument == null ? true : _MyDocument.IsValidList(list)) && (_MyRODb == null ? true : _MyRODb.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyDocument == null || _MyDocument.IsValidList(list)) && (_MyRODb == null || _MyRODb.IsValidList(list));
}
// CSLATODO: Replace base DROUsage.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current DROUsage</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check DROUsage.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current DROUsage</returns>
protected override object GetIdValue()
{
return MyDROUsageUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyDROUsageUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -321,8 +303,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules?.BrokenRules);
}
}
protected override void AddBusinessRules()
@@ -369,35 +351,11 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(DROUsageID, "<Role(s)>");
//AuthorizationRules.AllowRead(DocID, "<Role(s)>");
//AuthorizationRules.AllowRead(ROID, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(RODbID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DocID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ROID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(RODbID, "<Role(s)>");
_DROUsageExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -405,42 +363,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_DROUsageExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _DROUsageUnique = 0;
protected static int DROUsageUnique
{ get { return ++_DROUsageUnique; } }
private int _MyDROUsageUnique = DROUsageUnique;
public int MyDROUsageUnique // Absolutely Unique ID - Editable
{ get { return _MyDROUsageUnique; } }
protected static int DROUsageUnique => ++_DROUsageUnique;
private readonly int _MyDROUsageUnique = DROUsageUnique;
// Absolutely Unique ID - Editable
public int MyDROUsageUnique => _MyDROUsageUnique;
protected DROUsage()
{/* require use of factory methods */
AddToCache(this);
@@ -449,15 +379,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DROUsage()
{
_CountFinalized++;
@@ -482,8 +408,6 @@ namespace VEPROMS.CSLA.Library
}
public static DROUsage New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a DROUsage");
try
{
return DataPortal.Create<DROUsage>();
@@ -554,8 +478,6 @@ namespace VEPROMS.CSLA.Library
}
public static DROUsage Get(int dROUsageID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a DROUsage");
try
{
DROUsage tmp = GetCachedByPrimaryKey(dROUsageID);
@@ -581,14 +503,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new DROUsage(dr);
return null;
}
internal DROUsage(SafeDataReader dr)
{
ReadData(dr);
}
internal DROUsage(SafeDataReader dr) => ReadData(dr);
public static void Delete(int dROUsageID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a DROUsage");
try
{
DataPortal.Delete(new PKCriteria(dROUsageID));
@@ -600,12 +517,6 @@ namespace VEPROMS.CSLA.Library
}
public override DROUsage Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a DROUsage");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a DROUsage");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a DROUsage");
try
{
BuildRefreshList();
@@ -625,13 +536,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _DROUsageID;
public int DROUsageID
{ get { return _DROUsageID; } }
public PKCriteria(int dROUsageID)
{
_DROUsageID = dROUsageID;
}
private readonly int _DROUsageID;
public int DROUsageID => _DROUsageID;
public PKCriteria(int dROUsageID) => _DROUsageID = dROUsageID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -703,7 +610,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("DROUsage.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -728,40 +635,48 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyDocument != null) _MyDocument.Update();
if (_MyRODb != null) _MyRODb.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyDocument?.Update();
_MyRODb?.Update();
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addDROUsage";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@DocID", DocID);
cm.Parameters.AddWithValue("@ROID", _ROID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@RODbID", RODbID);
// Output Calculated Columns
SqlParameter param_DROUsageID = new SqlParameter("@newDROUsageID", SqlDbType.Int);
param_DROUsageID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_DROUsageID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_DROUsageID = (int)cm.Parameters["@newDROUsageID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addDROUsage";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@DocID", DocID);
cm.Parameters.AddWithValue("@ROID", _ROID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@RODbID", RODbID);
// Output Calculated Columns
SqlParameter param_DROUsageID = new SqlParameter("@newDROUsageID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_DROUsageID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_DROUsageID = (int)cm.Parameters["@newDROUsageID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.SQLInsert", GetHashCode());
@@ -773,7 +688,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("DROUsage.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int dROUsageID, Document myDocument, string roid, string config, DateTime dts, string userID, RODb myRODb)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.Add", 0);
@@ -792,11 +707,15 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID);
// Output Calculated Columns
SqlParameter param_DROUsageID = new SqlParameter("@newDROUsageID", SqlDbType.Int);
param_DROUsageID.Direction = ParameterDirection.Output;
SqlParameter param_DROUsageID = new SqlParameter("@newDROUsageID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_DROUsageID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -811,7 +730,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("DROUsage.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -834,42 +753,48 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.SQLUpdate", GetHashCode());
try
{
if (_MyDocument != null) _MyDocument.Update();
if (_MyRODb != null) _MyRODb.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyDocument?.Update();
_MyRODb?.Update();
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateDROUsage";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@DROUsageID", _DROUsageID);
cm.Parameters.AddWithValue("@DocID", DocID);
cm.Parameters.AddWithValue("@ROID", _ROID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
cm.Parameters.AddWithValue("@RODbID", RODbID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateDROUsage";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@DROUsageID", _DROUsageID);
cm.Parameters.AddWithValue("@DocID", DocID);
cm.Parameters.AddWithValue("@ROID", _ROID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
cm.Parameters.AddWithValue("@RODbID", RODbID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -882,18 +807,22 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = DROUsage.Add(cn, ref _DROUsageID, _MyDocument, _ROID, _Config, _DTS, _UserID, _MyRODb);
else
_LastChanged = DROUsage.Update(cn, ref _DROUsageID, _DocID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _RODbID);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = DROUsage.Add(cn, ref _DROUsageID, _MyDocument, _ROID, _Config, _DTS, _UserID, _MyRODb);
else
_LastChanged = DROUsage.Update(cn, ref _DROUsageID, _DocID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _RODbID);
}
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int dROUsageID, int docID, string roid, string config, DateTime dts, string userID, ref byte[] lastChanged, int rODbID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.Update", 0);
@@ -914,8 +843,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
cm.Parameters.AddWithValue("@RODbID", rODbID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -929,12 +860,9 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("DROUsage.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_DROUsageID));
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_DROUsageID));
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.DataPortal_Delete", GetHashCode());
@@ -959,7 +887,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("DROUsage.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int dROUsageID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.Remove", 0);
@@ -1000,16 +928,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _DROUsageID;
private readonly int _DROUsageID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int dROUsageID)
{
_DROUsageID = dROUsageID;
}
public bool Exists => _exists;
public ExistsCommand(int dROUsageID) => _DROUsageID = dROUsageID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.DataPortal_Execute", GetHashCode());
@@ -1017,7 +939,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -1039,7 +961,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
DROUsageExtension _DROUsageExtension = new DROUsageExtension();
readonly DROUsageExtension _DROUsageExtension = new DROUsageExtension();
[Serializable()]
partial class DROUsageExtension : extensionBase
{
@@ -1048,18 +970,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultDocID
{
get { return 0; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultDocID => 0;
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1088,61 +1001,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DROUsage)
if (destType == typeof(string) && value is DROUsage usage)
{
// Return the ToString value
return ((DROUsage)value).ToString();
return usage.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create DROUsageExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class DROUsage
// {
// partial class DROUsageExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultDocID
// {
// get { return 0; }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class DROUsageInfo : ReadOnlyBase<DROUsageInfo>, IDisposable
{
public event DROUsageInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<DROUsageInfo> _CacheList = new List<DROUsageInfo>();
protected static void AddToCache(DROUsageInfo dROUsageInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(dROUsageInfo)) _CacheList.Remove(dROUsageInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<DROUsageInfo>> _CacheByPrimaryKey = new Dictionary<string, List<DROUsageInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected DROUsage _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _DROUsageID;
[System.ComponentModel.DataObjectField(true, true)]
public int DROUsageID
@@ -175,32 +159,19 @@ namespace VEPROMS.CSLA.Library
return _MyRODb;
}
}
// CSLATODO: Replace base DROUsageInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current DROUsageInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check DROUsageInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current DROUsageInfo</returns>
protected override object GetIdValue()
{
return MyDROUsageInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyDROUsageInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _DROUsageInfoUnique = 0;
private static int DROUsageInfoUnique
{ get { return ++_DROUsageInfoUnique; } }
private int _MyDROUsageInfoUnique = DROUsageInfoUnique;
public int MyDROUsageInfoUnique // Absolutely Unique ID - Info
{ get { return _MyDROUsageInfoUnique; } }
private static int DROUsageInfoUnique => ++_DROUsageInfoUnique;
private readonly int _MyDROUsageInfoUnique = DROUsageInfoUnique;
// Absolutely Unique ID - Info
public int MyDROUsageInfoUnique => _MyDROUsageInfoUnique;
protected DROUsageInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -209,15 +180,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DROUsageInfo()
{
_CountFinalized++;
@@ -234,10 +201,7 @@ namespace VEPROMS.CSLA.Library
if (listDROUsageInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(DROUsageID.ToString()); // remove the list
}
public virtual DROUsage Get()
{
return _Editable = DROUsage.Get(_DROUsageID);
}
public virtual DROUsage Get() => _Editable = DROUsage.Get(_DROUsageID);
public static void Refresh(DROUsage tmp)
{
string key = tmp.DROUsageID.ToString();
@@ -250,22 +214,22 @@ namespace VEPROMS.CSLA.Library
{
if (_DocID != tmp.DocID)
{
if (MyDocument != null) MyDocument.RefreshDocumentDROUsages(); // Update List for old value
MyDocument?.RefreshDocumentDROUsages(); // Update List for old value
_DocID = tmp.DocID; // Update the value
}
_MyDocument = null; // Reset list so that the next line gets a new list
if (MyDocument != null) MyDocument.RefreshDocumentDROUsages(); // Update List for new value
MyDocument?.RefreshDocumentDROUsages(); // Update List for new value
_ROID = tmp.ROID;
_Config = tmp.Config;
_DTS = tmp.DTS;
_UserID = tmp.UserID;
if (_RODbID != tmp.RODbID)
{
if (MyRODb != null) MyRODb.RefreshRODbDROUsages(); // Update List for old value
MyRODb?.RefreshRODbDROUsages(); // Update List for old value
_RODbID = tmp.RODbID; // Update the value
}
_MyRODb = null; // Reset list so that the next line gets a new list
if (MyRODb != null) MyRODb.RefreshRODbDROUsages(); // Update List for new value
MyRODb?.RefreshRODbDROUsages(); // Update List for new value
_DROUsageInfoExtension.Refresh(this);
OnChange();// raise an event
}
@@ -285,11 +249,11 @@ namespace VEPROMS.CSLA.Library
_UserID = tmp.UserID;
if (_RODbID != tmp.RODbID)
{
if (MyRODb != null) MyRODb.RefreshRODbDROUsages(); // Update List for old value
MyRODb?.RefreshRODbDROUsages(); // Update List for old value
_RODbID = tmp.RODbID; // Update the value
}
_MyRODb = null; // Reset list so that the next line gets a new list
if (MyRODb != null) MyRODb.RefreshRODbDROUsages(); // Update List for new value
MyRODb?.RefreshRODbDROUsages(); // Update List for new value
_DROUsageInfoExtension.Refresh(this);
OnChange();// raise an event
}
@@ -305,11 +269,11 @@ namespace VEPROMS.CSLA.Library
{
if (_DocID != tmp.DocID)
{
if (MyDocument != null) MyDocument.RefreshDocumentDROUsages(); // Update List for old value
MyDocument?.RefreshDocumentDROUsages(); // Update List for old value
_DocID = tmp.DocID; // Update the value
}
_MyDocument = null; // Reset list so that the next line gets a new list
if (MyDocument != null) MyDocument.RefreshDocumentDROUsages(); // Update List for new value
MyDocument?.RefreshDocumentDROUsages(); // Update List for new value
_ROID = tmp.ROID;
_Config = tmp.Config;
_DTS = tmp.DTS;
@@ -319,8 +283,6 @@ namespace VEPROMS.CSLA.Library
}
public static DROUsageInfo Get(int dROUsageID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a DROUsage");
try
{
DROUsageInfo tmp = GetCachedByPrimaryKey(dROUsageID);
@@ -359,13 +321,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _DROUsageID;
public int DROUsageID
{ get { return _DROUsageID; } }
public PKCriteria(int dROUsageID)
{
_DROUsageID = dROUsageID;
}
private readonly int _DROUsageID;
public int DROUsageID => _DROUsageID;
public PKCriteria(int dROUsageID) => _DROUsageID = dROUsageID;
}
private void ReadData(SafeDataReader dr)
{
@@ -426,7 +384,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
DROUsageInfoExtension _DROUsageInfoExtension = new DROUsageInfoExtension();
readonly DROUsageInfoExtension _DROUsageInfoExtension = new DROUsageInfoExtension();
[Serializable()]
partial class DROUsageInfoExtension : extensionBase { }
[Serializable()]
@@ -442,10 +400,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DROUsageInfo)
if (destType == typeof(string) && value is DROUsageInfo info)
{
// Return the ToString value
return ((DROUsageInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<DROUsageInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<DROUsageInfo> Items => base.Items;
public void AddEvents()
{
foreach (DROUsageInfo tmp in this)
{
@@ -44,23 +41,19 @@ namespace VEPROMS.CSLA.Library
for (int i = 0; i < Count; i++)
{
if (base[i] == sender)
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
}
}
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~DROUsageInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DROUsageInfoList()
{
_CountFinalized++;
}
@@ -97,26 +90,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on DROUsageInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all DROUsageInfo.
/// </summary>
public static void Reset()
{
_DROUsageInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static DROUsageInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<DROUsageInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on DROUsageInfoList.Get", ex);
// }
//}
public static DROUsageInfoList GetByDocID(int docID)
/// <summary>
/// Reset the list of all DROUsageInfo.
/// </summary>
public static void Reset() => _DROUsageInfoList = null;
public static DROUsageInfoList GetByDocID(int docID)
{
try
{
@@ -150,7 +129,7 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
private void DataPortal_Fetch()
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsageInfoList.DataPortal_Fetch", GetHashCode());
try
{
@@ -164,7 +143,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new DROUsageInfo(dr));
while (dr.Read()) Add(new DROUsageInfo(dr));
IsReadOnly = true;
}
}
@@ -175,16 +154,13 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsageInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("DROUsageInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
[Serializable()]
private class DocIDCriteria
{
public DocIDCriteria(int docID)
{
_DocID = docID;
}
private int _DocID;
public DocIDCriteria(int docID) => _DocID = docID;
private int _DocID;
public int DocID
{
get { return _DocID; }
@@ -193,7 +169,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(DocIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsageInfoList.DataPortal_FetchDocID", GetHashCode());
try
{
@@ -208,7 +184,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new DROUsageInfo(dr));
while (dr.Read()) Add(new DROUsageInfo(dr));
IsReadOnly = true;
}
}
@@ -219,16 +195,13 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsageInfoList.DataPortal_FetchDocID", ex);
throw new DbCslaException("DROUsageInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
[Serializable()]
private class RODbIDCriteria
{
public RODbIDCriteria(int rODbID)
{
_RODbID = rODbID;
}
private int _RODbID;
public RODbIDCriteria(int rODbID) => _RODbID = rODbID;
private int _RODbID;
public int RODbID
{
get { return _RODbID; }
@@ -237,7 +210,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(RODbIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsageInfoList.DataPortal_FetchRODbID", GetHashCode());
try
{
@@ -252,7 +225,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new DROUsageInfo(dr));
while (dr.Read()) Add(new DROUsageInfo(dr));
IsReadOnly = true;
}
}
@@ -263,48 +236,37 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsageInfoList.DataPortal_FetchRODbID", ex);
throw new DbCslaException("DROUsageInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
DROUsageInfoListPropertyDescriptor pd = new DROUsageInfoListPropertyDescriptor(this, i);
@@ -321,7 +283,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class DROUsageInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private DROUsageInfo Item { get { return (DROUsageInfo)_Item; } }
public DROUsageInfoListPropertyDescriptor(DROUsageInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -330,10 +291,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DROUsageInfoList)
if (destType == typeof(string) && value is DROUsageInfoList list)
{
// Return department and department role separated by comma.
return ((DROUsageInfoList)value).Items.Count.ToString() + " DROUsages";
return $"{list.Items.Count} DROUsages";
}
return base.ConvertTo(context, culture, value, destType);
}
+169 -193
View File
@@ -15,7 +15,6 @@ using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text.RegularExpressions;
@@ -35,79 +34,76 @@ namespace VEPROMS.CSLA.Library
private static string _DBServer = null;
private static DateTime _RevDate=DateTime.MinValue;
public static DateTime RevDate
{
get { return Database._RevDate; }
set { Database._RevDate = value; }
}
public static DateTime RevDate
{
get { return _RevDate; }
set { _RevDate = value; }
}
private static string _RevDescription= "Unknown";
public static string RevDescription
{
get { return Database._RevDescription; }
set { Database._RevDescription = value; }
}
public static string DBServer
{
get
{
if (_DBServer == null)
public static string RevDescription
{
string cnstr = null;
try
get { return _RevDescription; }
set { _RevDescription = value; }
}
public static string DBServer
{
get
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
if (_DBServer == null)
{
cnstr = cn.ConnectionString;
string cnstr = null;
try
{
using (SqlCommand cmd = new SqlCommand("vesp_GetSQLCodeRevision", cn))
using (SqlConnection cn = VEPROMS_SqlConnection)
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
cnstr = cn.ConnectionString;
try
{
_RevDate = dr.GetDateTime(0);
_RevDescription = dr.GetString(1);
using (SqlCommand cmd = new SqlCommand("vesp_GetSQLCodeRevision", cn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
_RevDate = dr.GetDateTime(0);
_RevDescription = dr.GetString(1);
}
}
}
catch (Exception)
{
_RevDate = DateTime.MinValue;
_RevDescription = "Unknown";
}
string server = "";
string db = "";
Match m = Regex.Match(cnstr, "Data Source=([^;]+)(;[^;]+)*;*Initial Catalog=([^;]+)(;[^;]+)*");
if (m.Success && m.Groups.Count > 4)
{
server = m.Groups[1].Value;
db = m.Groups[3].Value;
}
_DBServer = string.Format("{0} - {1} [SQL:{2:yyMM.ddHH}]", server, db, RevDate);
}
}
catch (Exception ex)
catch (Exception)
{
_RevDate = DateTime.MinValue;
_RevDescription = "Unknown";
_DBServer = cnstr;
}
string server = "";
string db = "";
Match m = Regex.Match(cnstr, "Data Source=([^;]+)(;[^;]+)*;*Initial Catalog=([^;]+)(;[^;]+)*");
if (m.Success && m.Groups.Count > 4)
{
server = m.Groups[1].Value;
db = m.Groups[3].Value;
}
_DBServer = string.Format("{0} - {1} [SQL:{2:yyMM.ddHH}]", server, db, RevDate);
}
}
catch (Exception)
{
_DBServer = cnstr;
return _DBServer;
}
}
return _DBServer;
}
}
private static int _DefaultTimeout = 600; // 600 seconds, i.e. 10 minutes
public static int DefaultTimeout
{
get { return _DefaultTimeout; }
set { _DefaultTimeout = value; }
}
public static int SQLTimeout
{
get { return _DefaultTimeout/20; }
}
public static void LogException(string s, Exception ex)
public static int SQLTimeout => _DefaultTimeout / 20;
public static void LogException(string s, Exception ex)
{
int i = 0;
Console.WriteLine("Error - {0}", s);
@@ -122,7 +118,7 @@ public static string DBServer
get { return _LoggingInfo; }
set { _LoggingInfo = value; }
}
static System.Diagnostics.Process _CurrentProcess = System.Diagnostics.Process.GetCurrentProcess();
static readonly System.Diagnostics.Process _CurrentProcess = Process.GetCurrentProcess();
public static void LogInfo(string s, int hashCode)
{
if (_LoggingInfo)
@@ -136,8 +132,8 @@ public static string DBServer
private static string _ConnectionName = "VEPROMS";
public static string ConnectionName
{
get { return Database._ConnectionName; }
set { Database._ConnectionName = value; _VEPROMS_Connection = null; /* Reset Connection */ }
get { return _ConnectionName; }
set { _ConnectionName = value; _VEPROMS_Connection = null; /* Reset Connection */ }
}
private static bool _TrackDBUsage = false;
public static bool TrackDBUsage
@@ -145,7 +141,8 @@ public static string DBServer
get { return _TrackDBUsage; }
set { _TrackDBUsage = value; }
}
private static Dictionary<string, int> _Methods = new Dictionary<string, int>();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, int> _Methods = new Dictionary<string, int>();
public static void ShowDBTracking(string fileName)
{
DebugDBTrack.Open(VlnSettings.TemporaryFolder + "\\" + fileName);
@@ -159,12 +156,7 @@ public static string DBServer
{
if (TrackDBUsage)
{
string str = Volian.Base.Library.vlnStackTrace.CalledFromCSLA;
//if (str.Contains("ItemAndChildren"))
//{
// ShowDictionary(Methods);
// Methods = new Dictionary<string, int>();
//}
string str = vlnStackTrace.CalledFromCSLA;
if (!_Methods.ContainsKey(str))
_Methods.Add(str, 1);
else
@@ -177,7 +169,7 @@ public static string DBServer
DateTime.Today.ToLongDateString();
// If DBConnection.XML exists, use the connection string from DBConnection.XML
string cnOverride = System.Windows.Forms.Application.StartupPath + @"\DBConnection.XML";
if (System.IO.File.Exists(cnOverride))
if (File.Exists(cnOverride))
{
System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
xd.Load(cnOverride);
@@ -209,12 +201,8 @@ public static string DBServer
}
}
// Otherwise get the value from the ConfigurationManager
ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings[ConnectionName];
if (cs == null)
{
throw new ApplicationException("Database.cs Could not find connection " + ConnectionName);
}
string constr = FixServer(cs.ConnectionString);
ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings[ConnectionName] ?? throw new ApplicationException("Database.cs Could not find connection " + ConnectionName);
string constr = FixServer(cs.ConnectionString);
if (constr.Contains("{MENU}"))
{
constr = ChooseDatabase(constr);
@@ -240,10 +228,10 @@ public static string DBServer
}
private static string FixServer(string connectionString)
{
string serverName = Volian.Base.Library.VlnSettings.GetServer();
string serverName = VlnSettings.GetServer();
if (serverName != null && serverName != "")
{
System.Text.RegularExpressions.Match mServer = System.Text.RegularExpressions.Regex.Match(connectionString, ".*Data Source=([^;]*).*");
System.Text.RegularExpressions.Match mServer = Regex.Match(connectionString, ".*Data Source=([^;]*).*");
if (mServer.Success)
{
connectionString = connectionString.Substring(0, mServer.Groups[1].Index) + serverName + connectionString.Substring(mServer.Groups[1].Index + mServer.Groups[1].Length);
@@ -254,24 +242,22 @@ public static string DBServer
private static string _SelectedDatabase;
public static string SelectedDatabase
{
get { return Database._SelectedDatabase; }
set { Database._SelectedDatabase = value; }
get { return _SelectedDatabase; }
set { _SelectedDatabase = value; }
}
public static string ActiveDatabase
{
get
{
string activeDatabase = SelectedDatabase;
if(activeDatabase == null)
activeDatabase = Regex.Replace(VEPROMS_Connection, "^.*Initial Catalog=([^;]*);.*$", "$1", RegexOptions.IgnoreCase);
return activeDatabase;
string activeDatabase = SelectedDatabase ?? Regex.Replace(VEPROMS_Connection, "^.*Initial Catalog=([^;]*);.*$", "$1", RegexOptions.IgnoreCase);
return activeDatabase;
}
}
private static string _LastDatabase="NoDefault";
public static string LastDatabase
{
get { return Database._LastDatabase; }
set { Database._LastDatabase = value; }
get { return _LastDatabase; }
set { _LastDatabase = value; }
}
private static string ChooseDatabase(string constr)
{
@@ -300,95 +286,98 @@ public static string DBServer
return constr.Replace("{MENU}", _SelectedDatabase);
}
private static System.Windows.Forms.ContextMenuStrip BuildDatabaseMenu(string constr)
{
string tmp = constr.Replace("{MENU}", "master");
SqlConnection cn = new SqlConnection(tmp);
cn.Open();
// SqlDataAdapter da = new SqlDataAdapter("select name from sysdatabases where name like 'VEP%' order by name", cn);
//SqlDataAdapter da = new SqlDataAdapter("select name, case when object_id('[' + name + ']..Items') is null then 'Not PROMS' when object_id('[' + name + ']..Revisions') is not null then 'Approval' when object_id('[' + name + ']..ContentAudits') is not null then 'Change Manager' else 'Original' end functionality from sysdatabases where name not in ('master','model','msdb','tempdb') order by name", cn);
SqlDataAdapter da = new SqlDataAdapter("select name, 'Approval' functionality from sysdatabases where name not in ('master','model','msdb','tempdb') order by name", cn);
da.SelectCommand.CommandTimeout = 300; // 300 sec timeout
DataSet ds = new DataSet();
try
{
da.Fill(ds);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.GetType().Name, ex.Message);
throw(new Exception("Cannot Load Data List",ex));
}
cn.Close();
System.Windows.Forms.ContextMenuStrip cms = new System.Windows.Forms.ContextMenuStrip();
cms.Items.Add("Choose Database");
System.Windows.Forms.ToolStripMenuItem tsmi = cms.Items[0] as System.Windows.Forms.ToolStripMenuItem;
tsmi.BackColor = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.ActiveCaption);// System.Drawing.Color.Pink;
tsmi.ForeColor = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.ActiveCaptionText);
tsmi.Font = new System.Drawing.Font(tsmi.Font, System.Drawing.FontStyle.Bold);
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (dr["functionality"].ToString() == "Approval" && !dr["name"].ToString().EndsWith("_RO")) // don't display sql ro databases in list
cms.Items.Add(dr["name"].ToString(), null, new EventHandler(Database_Click));
}
return cms;
}
{
string tmp = constr.Replace("{MENU}", "master");
using (SqlConnection cn = new SqlConnection(tmp))
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlDataAdapter da = new SqlDataAdapter("select name, 'Approval' functionality from sysdatabases where name not in ('master','model','msdb','tempdb') order by name", cn))
{
da.SelectCommand.CommandTimeout = 300; // 300 sec timeout
DataSet ds = new DataSet();
try
{
da.Fill(ds);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.GetType().Name, ex.Message);
throw (new Exception("Cannot Load Data List", ex));
}
cn.Close();
System.Windows.Forms.ContextMenuStrip cms = new System.Windows.Forms.ContextMenuStrip();
cms.Items.Add("Choose Database");
System.Windows.Forms.ToolStripMenuItem tsmi = cms.Items[0] as System.Windows.Forms.ToolStripMenuItem;
tsmi.BackColor = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.ActiveCaption);// System.Drawing.Color.Pink;
tsmi.ForeColor = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.ActiveCaptionText);
tsmi.Font = new System.Drawing.Font(tsmi.Font, System.Drawing.FontStyle.Bold);
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (dr["functionality"].ToString() == "Approval" && !dr["name"].ToString().EndsWith("_RO")) // don't display sql ro databases in list
cms.Items.Add(dr["name"].ToString(), null, new EventHandler(Database_Click));
}
return cms;
}
}
}
static void Database_Click(object sender, EventArgs e)
static void Database_Click(object sender, EventArgs e)
{
System.Windows.Forms.ToolStripMenuItem tsmi = sender as System.Windows.Forms.ToolStripMenuItem;
if (tsmi != null)
{
_SelectedDatabase = tsmi.Text;
}
}
if (sender is System.Windows.Forms.ToolStripMenuItem tsmi)
{
_SelectedDatabase = tsmi.Text;
}
}
public static SqlConnection VEPROMS_SqlConnection
{
get
{
string strConn = VEPROMS_Connection; // If failure - Fail (Don't try to catch)
// Attempt to make a connection
{
string strConn = VEPROMS_Connection; // If failure - Fail (Don't try to catch)
// Attempt to make a connection
//note - cannot use using here as it will close the connection and it needs to return it as open
SqlConnection cn = new SqlConnection(strConn);
try
{
cn.Open();
return cn;
}
catch (SqlException exsql)
{
const string strAttachError = "An attempt to attach an auto-named database for file ";
if (exsql.Message.StartsWith(strAttachError))
{// Check to see if the file is missing
string sFile = exsql.Message.Substring(strAttachError.Length);
sFile = sFile.Substring(0, sFile.IndexOf(" failed"));
// "An attempt to attach an auto-named database for file <mdf file> failed"
if (strConn.ToLower().IndexOf("user instance=true") < 0)
{
throw new ApplicationException("Connection String missing attribute: User Instance=True");
}
if (System.IO.File.Exists(sFile))
{
throw new ApplicationException("Database file " + sFile + " Cannot be opened\r\n", exsql);
}
else
{
throw new FileNotFoundException("Database file " + sFile + " Not Found", exsql);
}
}
else
{
//Open a MesageBox so the user is given some feedback that the connection has failed.
ReportInnermostException(exsql,strConn);
throw new ApplicationException("Failure on Connect", exsql);
}
}
catch (Exception ex)// Throw Application Exception on Failure
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection Error", ex);
throw new ApplicationException("Failure on Connect", ex);
}
}
}
try
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
return cn;
}
catch (SqlException exsql)
{
const string strAttachError = "An attempt to attach an auto-named database for file ";
if (exsql.Message.StartsWith(strAttachError))
{// Check to see if the file is missing
string sFile = exsql.Message.Substring(strAttachError.Length);
sFile = sFile.Substring(0, sFile.IndexOf(" failed"));
// "An attempt to attach an auto-named database for file <mdf file> failed"
if (strConn.ToLower().IndexOf("user instance=true") < 0)
{
throw new ApplicationException("Connection String missing attribute: User Instance=True");
}
if (File.Exists(sFile))
{
throw new ApplicationException("Database file " + sFile + " Cannot be opened\r\n", exsql);
}
else
{
throw new FileNotFoundException("Database file " + sFile + " Not Found", exsql);
}
}
else
{
//Open a MesageBox so the user is given some feedback that the connection has failed.
ReportInnermostException(exsql, strConn);
throw new ApplicationException("Failure on Connect", exsql);
}
}
catch (Exception ex)// Throw Application Exception on Failure
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection Error", ex);
throw new ApplicationException("Failure on Connect", ex);
}
}
}
/// <summary>
/// Open a MessageBox with the exception type, the connection string and the exception message
/// </summary>
@@ -400,15 +389,13 @@ public static string DBServer
while (ex.InnerException != null)
ex = ex.InnerException;
System.Windows.Forms.MessageBox.Show(string.Format("{0}\r\n\r\nConnection String ={1}", ex.Message,conn)
,"PROMS - " + ex.GetType().FullName, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
System.Diagnostics.Process.GetCurrentProcess().Kill();
, $"PROMS - {ex.GetType().FullName}", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
Process.GetCurrentProcess().Kill();
}
public static void PurgeData()
{
try
{
//SqlConnection cn = VEPROMS_SqlConnection;
//SqlCommand cmd = new SqlCommand("purgedata", cn);
using (SqlConnection cn = VEPROMS_SqlConnection)
{
using (SqlCommand cmd = new SqlCommand("purgedata", cn))
@@ -458,8 +445,6 @@ public static string DBServer
{
try
{
//SqlConnection cn = VEPROMS_SqlConnection;
//SqlCommand cmd = new SqlCommand("purgedata", cn);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cmd = new SqlCommand("purgedata", cn))
@@ -483,11 +468,8 @@ public static string DBServer
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private ProposedTransition _ProposedTransition;
public string ErrorMessage => _ErrorMessage;
private ProposedTransition _ProposedTransition;
public ProposedTransition ProposedTransition
{
get { return _ProposedTransition; }
@@ -508,10 +490,12 @@ public static string DBServer
#region Factory Methods
public static ProposedTransition Execute(int fromID, int toID)
{
CanTransitionBeCreatedCommand cmd = new CanTransitionBeCreatedCommand();
cmd.FromID = fromID;
cmd.ToID = toID;
cmd = DataPortal.Execute<CanTransitionBeCreatedCommand>(cmd);
CanTransitionBeCreatedCommand cmd = new CanTransitionBeCreatedCommand
{
FromID = fromID,
ToID = toID
};
cmd = DataPortal.Execute<CanTransitionBeCreatedCommand>(cmd);
return cmd.ProposedTransition;
}
private CanTransitionBeCreatedCommand()
@@ -536,8 +520,6 @@ public static string DBServer
{
try
{
//SqlConnection cn = VEPROMS_SqlConnection;
//SqlCommand cmd = new SqlCommand("purgedata", cn);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cmd = new SqlCommand("vesp_CanTransitionBeCreated", cn))
@@ -571,16 +553,10 @@ public static string DBServer
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private List<InvalidTransition> _InvalidTransitions;
public List<InvalidTransition> InvalidTransitions
{
get { return _InvalidTransitions; }
}
private int _ItemID;
public string ErrorMessage => _ErrorMessage;
private List<InvalidTransition> _InvalidTransitions;
public List<InvalidTransition> InvalidTransitions => _InvalidTransitions;
private int _ItemID;
public int ItemID
{
get { return _ItemID; }
@@ -595,10 +571,12 @@ public static string DBServer
#region Factory Methods
public static List<InvalidTransition> Execute(int itemID, string newAppl)
{
WillTransitionsBeValidCommand cmd = new WillTransitionsBeValidCommand();
cmd.ItemID = itemID;
cmd.NewAppl = newAppl;
cmd = DataPortal.Execute<WillTransitionsBeValidCommand>(cmd);
WillTransitionsBeValidCommand cmd = new WillTransitionsBeValidCommand
{
ItemID = itemID,
NewAppl = newAppl
};
cmd = DataPortal.Execute<WillTransitionsBeValidCommand>(cmd);
return cmd.InvalidTransitions;
}
private WillTransitionsBeValidCommand()
@@ -626,8 +604,6 @@ public static string DBServer
{
try
{
//SqlConnection cn = VEPROMS_SqlConnection;
//SqlCommand cmd = new SqlCommand("purgedata", cn);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cmd = new SqlCommand("vesp_WillTransitionsBeValid", cn))
+130 -261
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty)
refreshDetails.Add(this);
}
private void ClearRefreshList()
{
_RefreshDetails = new List<Detail>();
}
private void ClearRefreshList() => _RefreshDetails = new List<Detail>();
private void BuildRefreshList()
{
ClearRefreshList();
@@ -57,6 +52,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Detail> _CacheList = new List<Detail>();
protected static void AddToCache(Detail detail)
{
@@ -66,6 +62,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(detail)) _CacheList.Remove(detail); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Detail>> _CacheByPrimaryKey = new Dictionary<string, List<Detail>>();
private static void ConvertListToDictionary()
{
@@ -91,15 +88,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextDetailID = -1;
public static int NextDetailID
{
get { return _nextDetailID--; }
}
public static int NextDetailID => _nextDetailID--;
private int _DetailID;
[System.ComponentModel.DataObjectField(true, true)]
public int DetailID
@@ -248,37 +239,22 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyContent != null && _MyContent.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyContent == null || _MyContent.IsValidList(list));
}
// CSLATODO: Replace base Detail.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Detail</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Detail.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Detail</returns>
protected override object GetIdValue()
{
return MyDetailUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyDetailUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -307,8 +283,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -345,35 +321,11 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(DetailID, "<Role(s)>");
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(ItemType, "<Role(s)>");
//AuthorizationRules.AllowRead(Text, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ContentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ItemType, "<Role(s)>");
//AuthorizationRules.AllowWrite(Text, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_DetailExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -381,42 +333,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_DetailExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _DetailUnique = 0;
protected static int DetailUnique
{ get { return ++_DetailUnique; } }
private int _MyDetailUnique = DetailUnique;
public int MyDetailUnique // Absolutely Unique ID - Editable
{ get { return _MyDetailUnique; } }
protected static int DetailUnique => ++_DetailUnique;
private readonly int _MyDetailUnique = DetailUnique;
// Absolutely Unique ID - Editable
public int MyDetailUnique => _MyDetailUnique;
protected Detail()
{/* require use of factory methods */
AddToCache(this);
@@ -425,15 +349,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Detail()
{
_CountFinalized++;
@@ -458,8 +378,6 @@ namespace VEPROMS.CSLA.Library
}
public static Detail New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Detail");
try
{
return DataPortal.Create<Detail>();
@@ -531,8 +449,6 @@ namespace VEPROMS.CSLA.Library
}
public static Detail Get(int detailID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Detail");
try
{
Detail tmp = GetCachedByPrimaryKey(detailID);
@@ -558,14 +474,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Detail(dr);
return null;
}
internal Detail(SafeDataReader dr)
{
ReadData(dr);
}
internal Detail(SafeDataReader dr) => ReadData(dr);
public static void Delete(int detailID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Detail");
try
{
DataPortal.Delete(new PKCriteria(detailID));
@@ -577,12 +488,6 @@ namespace VEPROMS.CSLA.Library
}
public override Detail Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Detail");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Detail");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Detail");
try
{
BuildRefreshList();
@@ -602,13 +507,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _DetailID;
public int DetailID
{ get { return _DetailID; } }
public PKCriteria(int detailID)
{
_DetailID = detailID;
}
private readonly int _DetailID;
public int DetailID => _DetailID;
public PKCriteria(int detailID) => _DetailID = detailID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -679,7 +580,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Detail.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -704,39 +605,47 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyContent != null) _MyContent.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyContent?.Update();
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addDetail";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@ItemType", _ItemType);
cm.Parameters.AddWithValue("@Text", _Text);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_DetailID = new SqlParameter("@newDetailID", SqlDbType.Int);
param_DetailID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_DetailID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_DetailID = (int)cm.Parameters["@newDetailID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addDetail";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@ItemType", _ItemType);
cm.Parameters.AddWithValue("@Text", _Text);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_DetailID = new SqlParameter("@newDetailID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_DetailID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_DetailID = (int)cm.Parameters["@newDetailID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.SQLInsert", GetHashCode());
@@ -748,7 +657,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Detail.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int detailID, Content myContent, int itemType, string text, string config, DateTime dts, string userID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.Add", 0);
@@ -767,11 +676,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns
SqlParameter param_DetailID = new SqlParameter("@newDetailID", SqlDbType.Int);
param_DetailID.Direction = ParameterDirection.Output;
SqlParameter param_DetailID = new SqlParameter("@newDetailID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_DetailID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -786,7 +699,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Detail.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -809,41 +722,47 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.SQLUpdate", GetHashCode());
try
{
if (_MyContent != null) _MyContent.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyContent?.Update();
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateDetail";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@DetailID", _DetailID);
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@ItemType", _ItemType);
cm.Parameters.AddWithValue("@Text", _Text);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateDetail";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@DetailID", _DetailID);
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@ItemType", _ItemType);
cm.Parameters.AddWithValue("@Text", _Text);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -856,18 +775,22 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Detail.Add(cn, ref _DetailID, _MyContent, _ItemType, _Text, _Config, _DTS, _UserID);
else
_LastChanged = Detail.Update(cn, ref _DetailID, _ContentID, _ItemType, _Text, _Config, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = Detail.Add(cn, ref _DetailID, _MyContent, _ItemType, _Text, _Config, _DTS, _UserID);
else
_LastChanged = Detail.Update(cn, ref _DetailID, _ContentID, _ItemType, _Text, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int detailID, int contentID, int itemType, string text, string config, DateTime dts, string userID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.Update", 0);
@@ -888,8 +811,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -903,12 +828,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Detail.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_DetailID));
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Delete", GetHashCode());
@@ -933,7 +858,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Detail.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int detailID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.Remove", 0);
@@ -974,16 +899,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _DetailID;
private readonly int _DetailID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int detailID)
{
_DetailID = detailID;
}
public bool Exists => _exists;
public ExistsCommand(int detailID) => _DetailID = detailID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Execute", GetHashCode());
@@ -991,7 +910,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -1013,7 +932,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
DetailExtension _DetailExtension = new DetailExtension();
readonly DetailExtension _DetailExtension = new DetailExtension();
[Serializable()]
partial class DetailExtension : extensionBase
{
@@ -1022,14 +941,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1058,57 +971,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Detail)
if (destType == typeof(string) && value is Detail detail)
{
// Return the ToString value
return ((Detail)value).ToString();
return detail.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create DetailExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Detail
// {
// partial class DetailExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class DetailInfo : ReadOnlyBase<DetailInfo>, IDisposable
{
public event DetailInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<DetailInfo> _CacheList = new List<DetailInfo>();
protected static void AddToCache(DetailInfo detailInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(detailInfo)) _CacheList.Remove(detailInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<DetailInfo>> _CacheByPrimaryKey = new Dictionary<string, List<DetailInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Detail _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _DetailID;
[System.ComponentModel.DataObjectField(true, true)]
public int DetailID
@@ -164,32 +148,19 @@ namespace VEPROMS.CSLA.Library
return _UserID;
}
}
// CSLATODO: Replace base DetailInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current DetailInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check DetailInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current DetailInfo</returns>
protected override object GetIdValue()
{
return MyDetailInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyDetailInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _DetailInfoUnique = 0;
private static int DetailInfoUnique
{ get { return ++_DetailInfoUnique; } }
private int _MyDetailInfoUnique = DetailInfoUnique;
public int MyDetailInfoUnique // Absolutely Unique ID - Info
{ get { return _MyDetailInfoUnique; } }
private static int DetailInfoUnique => ++_DetailInfoUnique;
private readonly int _MyDetailInfoUnique = DetailInfoUnique;
// Absolutely Unique ID - Info
public int MyDetailInfoUnique => _MyDetailInfoUnique;
protected DetailInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -198,15 +169,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DetailInfo()
{
_CountFinalized++;
@@ -223,10 +190,7 @@ namespace VEPROMS.CSLA.Library
if (listDetailInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(DetailID.ToString()); // remove the list
}
public virtual Detail Get()
{
return _Editable = Detail.Get(_DetailID);
}
public virtual Detail Get() => _Editable = Detail.Get(_DetailID);
public static void Refresh(Detail tmp)
{
string key = tmp.DetailID.ToString();
@@ -239,11 +203,11 @@ namespace VEPROMS.CSLA.Library
{
if (_ContentID != tmp.ContentID)
{
if (MyContent != null) MyContent.RefreshContentDetails(); // Update List for old value
MyContent?.RefreshContentDetails(); // Update List for old value
_ContentID = tmp.ContentID; // Update the value
}
_MyContent = null; // Reset list so that the next line gets a new list
if (MyContent != null) MyContent.RefreshContentDetails(); // Update List for new value
MyContent?.RefreshContentDetails(); // Update List for new value
_ItemType = tmp.ItemType;
_Text = tmp.Text;
_Config = tmp.Config;
@@ -272,8 +236,6 @@ namespace VEPROMS.CSLA.Library
}
public static DetailInfo Get(int detailID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Detail");
try
{
DetailInfo tmp = GetCachedByPrimaryKey(detailID);
@@ -312,13 +274,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _DetailID;
public int DetailID
{ get { return _DetailID; } }
public PKCriteria(int detailID)
{
_DetailID = detailID;
}
private readonly int _DetailID;
public int DetailID => _DetailID;
public PKCriteria(int detailID) => _DetailID = detailID;
}
private void ReadData(SafeDataReader dr)
{
@@ -379,7 +337,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
DetailInfoExtension _DetailInfoExtension = new DetailInfoExtension();
readonly DetailInfoExtension _DetailInfoExtension = new DetailInfoExtension();
[Serializable()]
partial class DetailInfoExtension : extensionBase { }
[Serializable()]
@@ -395,10 +353,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DetailInfo)
if (destType == typeof(string) && value is DetailInfo info)
{
// Return the ToString value
return ((DetailInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<DetailInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<DetailInfo> Items => base.Items;
public void AddEvents()
{
foreach (DetailInfo tmp in this)
{
@@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~DetailInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DetailInfoList()
{
_CountFinalized++;
}
@@ -97,26 +90,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on DetailInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all DetailInfo.
/// </summary>
public static void Reset()
{
_DetailInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static DetailInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<DetailInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on DetailInfoList.Get", ex);
// }
//}
public static DetailInfoList GetByContentID(int contentID)
/// <summary>
/// Reset the list of all DetailInfo.
/// </summary>
public static void Reset() => _DetailInfoList = null;
public static DetailInfoList GetByContentID(int contentID)
{
try
{
@@ -166,11 +145,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ContentIDCriteria
{
public ContentIDCriteria(int contentID)
{
_ContentID = contentID;
}
private int _ContentID;
public ContentIDCriteria(int contentID) => _ContentID = contentID;
private int _ContentID;
public int ContentID
{
get { return _ContentID; }
@@ -207,41 +183,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -263,7 +228,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class DetailInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private DetailInfo Item { get { return (DetailInfo)_Item; } }
public DetailInfoListPropertyDescriptor(DetailInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -272,10 +236,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DetailInfoList)
if (destType == typeof(string) && value is DetailInfoList list)
{
// Return department and department role separated by comma.
return ((DetailInfoList)value).Items.Count.ToString() + " Details";
return $"{list.Items.Count} Details";
}
return base.ConvertTo(context, culture, value, destType);
}
+143 -298
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -72,6 +70,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<DocVersion> _CacheList = new List<DocVersion>();
protected static void AddToCache(DocVersion docVersion)
{
@@ -81,6 +80,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(docVersion)) _CacheList.Remove(docVersion); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<DocVersion>> _CacheByPrimaryKey = new Dictionary<string, List<DocVersion>>();
private static void ConvertListToDictionary()
{
@@ -106,15 +106,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextVersionID = -1;
public static int NextVersionID
{
get { return _nextVersionID--; }
}
public static int NextVersionID => _nextVersionID--;
private int _VersionID;
[System.ComponentModel.DataObjectField(true, true)]
public int VersionID
@@ -362,10 +356,7 @@ namespace VEPROMS.CSLA.Library
return _DocVersionAssociations;
}
}
public void Reset_DocVersionAssociations()
{
_DocVersionAssociationCount = -1;
}
public void Reset_DocVersionAssociations() => _DocVersionAssociationCount = -1;
public override bool IsDirty
{
get
@@ -380,37 +371,22 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_DocVersionAssociations == null ? false : _DocVersionAssociations.IsDirtyList(list)) || (_MyFolder == null ? false : _MyFolder.IsDirtyList(list)) || (_MyFormat == null ? false : _MyFormat.IsDirtyList(list)) || (_MyItem == null ? false : _MyItem.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_DocVersionAssociations != null && _DocVersionAssociations.IsDirtyList(list)) || (_MyFolder != null && _MyFolder.IsDirtyList(list)) || (_MyFormat != null && _MyFormat.IsDirtyList(list)) || (_MyItem != null && _MyItem.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_DocVersionAssociations == null ? true : _DocVersionAssociations.IsValidList(list)) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)) && (_MyFormat == null ? true : _MyFormat.IsValidList(list)) && (_MyItem == null ? true : _MyItem.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_DocVersionAssociations == null || _DocVersionAssociations.IsValidList(list)) && (_MyFolder == null || _MyFolder.IsValidList(list)) && (_MyFormat == null || _MyFormat.IsValidList(list)) && (_MyItem == null || _MyItem.IsValidList(list));
}
// CSLATODO: Replace base DocVersion.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current DocVersion</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check DocVersion.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current DocVersion</returns>
protected override object GetIdValue()
{
return MyDocVersionUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyDocVersionUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -442,8 +418,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -483,41 +459,10 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(VersionID, "<Role(s)>");
//AuthorizationRules.AllowRead(FolderID, "<Role(s)>");
//AuthorizationRules.AllowRead(VersionType, "<Role(s)>");
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
//AuthorizationRules.AllowRead(Title, "<Role(s)>");
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(FormatID, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FolderID, "<Role(s)>");
//AuthorizationRules.AllowWrite(VersionType, "<Role(s)>");
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
//AuthorizationRules.AllowWrite(Title, "<Role(s)>");
//AuthorizationRules.AllowWrite(ItemID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FormatID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_DocVersionExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -525,55 +470,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_DocVersionExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
/// <summary>
/// determines if related records (Foreign Keys) will keep this Item from being deleted
/// </summary>
public bool CanDelete
{
get
{
// Check to make sure that there are not any related records
int usedByCount = 0;
usedByCount += _DocVersionAssociationCount;
return (usedByCount == 0);
}
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _DocVersionUnique = 0;
protected static int DocVersionUnique
{ get { return ++_DocVersionUnique; } }
private int _MyDocVersionUnique = DocVersionUnique;
public int MyDocVersionUnique // Absolutely Unique ID - Editable
{ get { return _MyDocVersionUnique; } }
protected static int DocVersionUnique => ++_DocVersionUnique;
private readonly int _MyDocVersionUnique = DocVersionUnique;
// Absolutely Unique ID - Editable
public int MyDocVersionUnique => _MyDocVersionUnique;
protected DocVersion()
{/* require use of factory methods */
AddToCache(this);
@@ -582,15 +486,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DocVersion()
{
_CountFinalized++;
@@ -615,8 +515,6 @@ namespace VEPROMS.CSLA.Library
}
public static DocVersion New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a DocVersion");
try
{
return DataPortal.Create<DocVersion>();
@@ -692,8 +590,6 @@ namespace VEPROMS.CSLA.Library
}
public static DocVersion Get(int versionID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a DocVersion");
try
{
DocVersion tmp = GetCachedByPrimaryKey(versionID);
@@ -725,8 +621,6 @@ namespace VEPROMS.CSLA.Library
}
public static void Delete(int versionID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a DocVersion");
try
{
DataPortal.Delete(new PKCriteria(versionID));
@@ -738,12 +632,6 @@ namespace VEPROMS.CSLA.Library
}
public override DocVersion Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a DocVersion");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a DocVersion");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a DocVersion");
try
{
BuildRefreshList();
@@ -763,13 +651,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _VersionID;
public int VersionID
{ get { return _VersionID; } }
public PKCriteria(int versionID)
{
_VersionID = versionID;
}
private readonly int _VersionID;
public int VersionID => _VersionID;
public PKCriteria(int versionID) => _VersionID = versionID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -848,7 +732,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("DocVersion.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -873,47 +757,55 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyFolder != null) _MyFolder.Update();
if (_MyFormat != null) _MyFormat.Update();
if (_MyItem != null) _MyItem.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyFolder?.Update();
_MyFormat?.Update();
_MyItem?.Update();
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addDocVersion";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@FolderID", FolderID);
cm.Parameters.AddWithValue("@VersionType", _VersionType);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Title", _Title);
cm.Parameters.AddWithValue("@ItemID", ItemID);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_VersionID = new SqlParameter("@newVersionID", SqlDbType.Int);
param_VersionID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_VersionID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_VersionID = (int)cm.Parameters["@newVersionID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addDocVersion";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@FolderID", FolderID);
cm.Parameters.AddWithValue("@VersionType", _VersionType);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Title", _Title);
cm.Parameters.AddWithValue("@ItemID", ItemID);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_VersionID = new SqlParameter("@newVersionID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_VersionID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_VersionID = (int)cm.Parameters["@newVersionID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_DocVersionAssociations != null) _DocVersionAssociations.Update(this);
_DocVersionAssociations?.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.SQLInsert", GetHashCode());
}
catch (Exception ex)
@@ -923,7 +815,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("DocVersion.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int versionID, Folder myFolder, int versionType, string name, string title, Item myItem, Format myFormat, string config, DateTime dts, string userID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.Add", 0);
@@ -945,11 +837,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns
SqlParameter param_VersionID = new SqlParameter("@newVersionID", SqlDbType.Int);
param_VersionID.Direction = ParameterDirection.Output;
SqlParameter param_VersionID = new SqlParameter("@newVersionID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_VersionID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -964,7 +860,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("DocVersion.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -987,49 +883,55 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.SQLUpdate", GetHashCode());
try
{
if (_MyFolder != null) _MyFolder.Update();
if (_MyFormat != null) _MyFormat.Update();
if (_MyItem != null) _MyItem.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyFolder?.Update();
_MyFormat?.Update();
_MyItem?.Update();
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateDocVersion";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@VersionID", _VersionID);
cm.Parameters.AddWithValue("@FolderID", FolderID);
cm.Parameters.AddWithValue("@VersionType", _VersionType);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Title", _Title);
cm.Parameters.AddWithValue("@ItemID", ItemID);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateDocVersion";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@VersionID", _VersionID);
cm.Parameters.AddWithValue("@FolderID", FolderID);
cm.Parameters.AddWithValue("@VersionType", _VersionType);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Title", _Title);
cm.Parameters.AddWithValue("@ItemID", ItemID);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
if (_DocVersionAssociations != null) _DocVersionAssociations.Update(this);
_DocVersionAssociations?.Update(this);
}
catch (Exception ex)
{
@@ -1040,19 +942,23 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = DocVersion.Add(cn, ref _VersionID, _MyFolder, _VersionType, _Name, _Title, _MyItem, _MyFormat, _Config, _DTS, _UserID);
else
_LastChanged = DocVersion.Update(cn, ref _VersionID, _FolderID, _VersionType, _Name, _Title, _ItemID, _FormatID, _Config, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = DocVersion.Add(cn, ref _VersionID, _MyFolder, _VersionType, _Name, _Title, _MyItem, _MyFormat, _Config, _DTS, _UserID);
else
_LastChanged = DocVersion.Update(cn, ref _VersionID, _FolderID, _VersionType, _Name, _Title, _ItemID, _FormatID, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
if (_DocVersionAssociations != null) _DocVersionAssociations.Update(this);
_DocVersionAssociations?.Update(this);
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int versionID, int folderID, int versionType, string name, string title, int? itemID, int? formatID, string config, DateTime dts, string userID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.Update", 0);
@@ -1076,8 +982,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -1091,12 +999,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("DocVersion.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_VersionID));
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Delete", GetHashCode());
@@ -1121,7 +1029,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("DocVersion.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int versionID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.Remove", 0);
@@ -1162,16 +1070,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _VersionID;
private readonly int _VersionID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int versionID)
{
_VersionID = versionID;
}
public bool Exists => _exists;
public ExistsCommand(int versionID) => _VersionID = versionID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Execute", GetHashCode());
@@ -1179,7 +1081,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -1201,7 +1103,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
DocVersionExtension _DocVersionExtension = new DocVersionExtension();
readonly DocVersionExtension _DocVersionExtension = new DocVersionExtension();
[Serializable()]
partial class DocVersionExtension : extensionBase
{
@@ -1210,18 +1112,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultVersionType
{
get { return 0; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultVersionType => 0;
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1250,61 +1143,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DocVersion)
if (destType == typeof(string) && value is DocVersion version)
{
// Return the ToString value
return ((DocVersion)value).ToString();
return version.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create DocVersionExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class DocVersion
// {
// partial class DocVersionExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultVersionType
// {
// get { return 0; }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _AssociationID;
[System.ComponentModel.DataObjectField(true, true)]
public int AssociationID
@@ -145,15 +139,6 @@ namespace VEPROMS.CSLA.Library
}
}
private byte[] _LastChanged = new byte[8];//timestamp
private int _ROFst_RODbID;
public int ROFst_RODbID
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _ROFst_RODbID;
}
}
private byte[] _ROFst_ROLookup;
public byte[] ROFst_ROLookup
{
@@ -163,7 +148,7 @@ namespace VEPROMS.CSLA.Library
return _ROFst_ROLookup;
}
}
private string _ROFst_Config = string.Empty;
private readonly string _ROFst_Config = string.Empty;
public string ROFst_Config
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
@@ -172,7 +157,7 @@ namespace VEPROMS.CSLA.Library
return _ROFst_Config;
}
}
private DateTime _ROFst_DTS = new DateTime();
private readonly DateTime _ROFst_DTS = new DateTime();
public DateTime ROFst_DTS
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
@@ -181,7 +166,7 @@ namespace VEPROMS.CSLA.Library
return _ROFst_DTS;
}
}
private string _ROFst_UserID = string.Empty;
private readonly string _ROFst_UserID = string.Empty;
public string ROFst_UserID
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
@@ -195,10 +180,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current DocVersionAssociation</returns>
protected override object GetIdValue()
{
return MyDocVersionAssociationUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyDocVersionAssociationUnique; // Absolutely Unique ID
// CSLATODO: Replace base DocVersionAssociation.ToString function as necessary
/// <summary>
/// Overrides Base ToString
@@ -222,18 +204,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyROFst == null ? false : _MyROFst.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyROFst != null && _MyROFst.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyROFst == null ? true : _MyROFst.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyROFst == null || _MyROFst.IsValidList(list));
}
#endregion
#region ValidationRules
@@ -264,7 +243,7 @@ namespace VEPROMS.CSLA.Library
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -289,76 +268,21 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AssociationID, "<Role(s)>");
//AuthorizationRules.AllowRead(ROFstID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ROFstID, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _DocVersionAssociationUnique = 0;
private static int DocVersionAssociationUnique
{ get { return ++_DocVersionAssociationUnique; } }
private int _MyDocVersionAssociationUnique = DocVersionAssociationUnique;
public int MyDocVersionAssociationUnique // Absolutely Unique ID - Editable FK
{ get { return _MyDocVersionAssociationUnique; } }
internal static DocVersionAssociation New(ROFst myROFst)
{
return new DocVersionAssociation(myROFst);
}
internal static DocVersionAssociation Get(SafeDataReader dr)
{
return new DocVersionAssociation(dr);
}
private static int DocVersionAssociationUnique => ++_DocVersionAssociationUnique;
private readonly int _MyDocVersionAssociationUnique = DocVersionAssociationUnique;
// Absolutely Unique ID - Editable FK
public int MyDocVersionAssociationUnique => _MyDocVersionAssociationUnique;
internal static DocVersionAssociation New(ROFst myROFst) => new DocVersionAssociation(myROFst);
internal static DocVersionAssociation Get(SafeDataReader dr) => new DocVersionAssociation(dr);
public DocVersionAssociation()
{
MarkAsChild();
@@ -386,15 +310,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DocVersionAssociation()
{
_CountFinalized++;
@@ -420,12 +340,7 @@ namespace VEPROMS.CSLA.Library
dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8);
// B2023-020: setting RO Database on new working draft crashes. Query 'getAssociationsByVersionID' had been modified
// for memory improvements to not return the ROFst values, so don't Get the values. Comment out for now.
//_ROFst_RODbID = dr.GetInt32("ROFst_RODbID");
//_ROFst_ROLookup = (byte[])dr.GetValue("ROFst_ROLookup");
_ROFst_ROLookup = null; // B2022-026 RO Memory reduction - use ROlookup of null to know if we loaded the RO.FST file
//_ROFst_Config = dr.GetString("ROFst_Config");
//_ROFst_DTS = dr.GetDateTime("ROFst_DTS");
//_ROFst_UserID = dr.GetString("ROFst_UserID");
}
catch (Exception ex) // FKItem Fetch
{
@@ -438,32 +353,45 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Association.Add(cn, ref _AssociationID, myDocVersion, _MyROFst, _Config, _DTS, _UserID);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Association.Add(cn, ref _AssociationID, myDocVersion, _MyROFst, _Config, _DTS, _UserID);
}
MarkOld();
}
internal void Update(DocVersion myDocVersion)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Association.Update(cn, ref _AssociationID, myDocVersion.VersionID, _ROFstID, _Config, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Association.Update(cn, ref _AssociationID, myDocVersion.VersionID, _ROFstID, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(DocVersion myDocVersion)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Association.Remove(cn, _AssociationID);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Association.Remove(cn, _AssociationID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
DocVersionAssociationExtension _DocVersionAssociationExtension = new DocVersionAssociationExtension();
readonly DocVersionAssociationExtension _DocVersionAssociationExtension = new DocVersionAssociationExtension();
[Serializable()]
partial class DocVersionAssociationExtension : extensionBase
{
@@ -472,14 +400,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -508,57 +430,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DocVersionAssociation)
if (destType == typeof(string) && value is DocVersionAssociation association)
{
// Return the ToString value
return ((DocVersionAssociation)value).ToString();
return association.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create DocVersionAssociationExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class DocVersionAssociation
// {
// partial class DocVersionAssociationExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public DocVersionAssociation this[Association myAssociation]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public DocVersionAssociation this[Association myAssociation]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<DocVersionAssociation> Items
{
get { return base.Items; }
}
public DocVersionAssociation GetItem(Association myAssociation)
public new System.Collections.Generic.IList<DocVersionAssociation> Items => base.Items;
public DocVersionAssociation GetItem(Association myAssociation)
{
foreach (DocVersionAssociation association in this)
if (association.AssociationID == myAssociation.AssociationID)
@@ -63,7 +55,7 @@ namespace VEPROMS.CSLA.Library
if (!Contains(myROFst))
{
DocVersionAssociation association = DocVersionAssociation.New(myROFst);
this.Add(association);
Add(association);
return association;
}
else
@@ -113,18 +105,18 @@ namespace VEPROMS.CSLA.Library
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (DocVersionAssociation child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (DocVersionAssociation child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
public bool Contains(ROFst myROFst)
{
foreach (DocVersionAssociation association in this)
@@ -156,20 +148,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static DocVersionAssociations New()
{
return new DocVersionAssociations();
}
internal static DocVersionAssociations Get(SafeDataReader dr)
{
return new DocVersionAssociations(dr);
}
public static DocVersionAssociations GetByVersionID(int versionID)
#endregion
#region Factory Methods
internal static DocVersionAssociations New() => new DocVersionAssociations();
internal static DocVersionAssociations Get(SafeDataReader dr) => new DocVersionAssociations(dr);
public static DocVersionAssociations GetByVersionID(int versionID)
{
try
{
@@ -180,11 +166,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on DocVersionAssociations.GetByVersionID", ex);
}
}
private DocVersionAssociations()
{
MarkAsChild();
}
internal DocVersionAssociations(SafeDataReader dr)
private DocVersionAssociations() => MarkAsChild();
internal DocVersionAssociations(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -193,16 +176,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~DocVersionAssociations()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DocVersionAssociations()
{
_CountFinalized++;
}
@@ -217,19 +196,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(DocVersionAssociation.Get(dr));
this.RaiseListChangedEvents = true;
Add(DocVersionAssociation.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class VersionIDCriteria
{
public VersionIDCriteria(int versionID)
{
_VersionID = versionID;
}
private int _VersionID;
public VersionIDCriteria(int versionID) => _VersionID = versionID;
private int _VersionID;
public int VersionID
{
get { return _VersionID; }
@@ -238,7 +214,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(VersionIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionAssociations.DataPortal_FetchVersionID", GetHashCode());
try
{
@@ -252,7 +228,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new DocVersionAssociation(dr));
while (dr.Read()) Add(new DocVersionAssociation(dr));
}
}
}
@@ -262,11 +238,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionAssociations.DataPortal_FetchVersionID", ex);
throw new DbCslaException("DocVersionAssociations.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(DocVersion docVersion)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -285,49 +261,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
DocVersionAssociationsPropertyDescriptor pd = new DocVersionAssociationsPropertyDescriptor(this, i);
@@ -344,7 +309,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class DocVersionAssociationsPropertyDescriptor : vlnListPropertyDescriptor
{
private DocVersionAssociation Item { get { return (DocVersionAssociation)_Item; } }
public DocVersionAssociationsPropertyDescriptor(DocVersionAssociations collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -353,10 +317,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DocVersionAssociations)
if (destType == typeof(string) && value is DocVersionAssociations associations)
{
// Return department and department role separated by comma.
return ((DocVersionAssociations)value).Items.Count.ToString() + " Associations";
return $"{associations.Items.Count} Associations";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class DocVersionInfo : ReadOnlyBase<DocVersionInfo>, IDisposable
{
public event DocVersionInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<DocVersionInfo> _CacheList = new List<DocVersionInfo>();
protected static void AddToCache(DocVersionInfo docVersionInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(docVersionInfo)) _CacheList.Remove(docVersionInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<DocVersionInfo>> _CacheByPrimaryKey = new Dictionary<string, List<DocVersionInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected DocVersion _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _VersionID;
[System.ComponentModel.DataObjectField(true, true)]
public int VersionID
@@ -252,32 +236,19 @@ namespace VEPROMS.CSLA.Library
foreach (DocVersionInfo tmp in _CacheByPrimaryKey[_VersionID.ToString()])
tmp._DocVersionAssociationCount = -1; // This will cause the data to be requeried
}
// CSLATODO: Replace base DocVersionInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current DocVersionInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check DocVersionInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current DocVersionInfo</returns>
protected override object GetIdValue()
{
return MyDocVersionInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyDocVersionInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _DocVersionInfoUnique = 0;
private static int DocVersionInfoUnique
{ get { return ++_DocVersionInfoUnique; } }
private int _MyDocVersionInfoUnique = DocVersionInfoUnique;
public int MyDocVersionInfoUnique // Absolutely Unique ID - Info
{ get { return _MyDocVersionInfoUnique; } }
private static int DocVersionInfoUnique => ++_DocVersionInfoUnique;
private readonly int _MyDocVersionInfoUnique = DocVersionInfoUnique;
// Absolutely Unique ID - Info
public int MyDocVersionInfoUnique => _MyDocVersionInfoUnique;
protected DocVersionInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -286,15 +257,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DocVersionInfo()
{
_CountFinalized++;
@@ -311,10 +278,7 @@ namespace VEPROMS.CSLA.Library
if (listDocVersionInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list
}
public virtual DocVersion Get()
{
return _Editable = DocVersion.Get(_VersionID);
}
public virtual DocVersion Get() => _Editable = DocVersion.Get(_VersionID);
public static void Refresh(DocVersion tmp)
{
string key = tmp.VersionID.ToString();
@@ -327,28 +291,28 @@ namespace VEPROMS.CSLA.Library
{
if (_FolderID != tmp.FolderID)
{
if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for old value
MyFolder?.RefreshFolderDocVersions(); // Update List for old value
_FolderID = tmp.FolderID; // Update the value
}
_MyFolder = null; // Reset list so that the next line gets a new list
if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for new value
MyFolder?.RefreshFolderDocVersions(); // Update List for new value
_VersionType = tmp.VersionType;
_Name = tmp.Name;
_Title = tmp.Title;
if (_ItemID != tmp.ItemID)
{
if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for old value
MyItem?.RefreshItemDocVersions(); // Update List for old value
_ItemID = tmp.ItemID; // Update the value
}
_MyItem = null; // Reset list so that the next line gets a new list
if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for new value
MyItem?.RefreshItemDocVersions(); // Update List for new value
if (_FormatID != tmp.FormatID)
{
if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for old value
MyFormat?.RefreshFormatDocVersions(); // Update List for old value
_FormatID = tmp.FormatID; // Update the value
}
_MyFormat = null; // Reset list so that the next line gets a new list
if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for new value
MyFormat?.RefreshFormatDocVersions(); // Update List for new value
_Config = tmp.Config;
_DTS = tmp.DTS;
_UserID = tmp.UserID;
@@ -370,18 +334,18 @@ namespace VEPROMS.CSLA.Library
_Title = tmp.Title;
if (_ItemID != tmp.ItemID)
{
if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for old value
MyItem?.RefreshItemDocVersions(); // Update List for old value
_ItemID = tmp.ItemID; // Update the value
}
_MyItem = null; // Reset list so that the next line gets a new list
if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for new value
MyItem?.RefreshItemDocVersions(); // Update List for new value
if (_FormatID != tmp.FormatID)
{
if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for old value
MyFormat?.RefreshFormatDocVersions(); // Update List for old value
_FormatID = tmp.FormatID; // Update the value
}
_MyFormat = null; // Reset list so that the next line gets a new list
if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for new value
MyFormat?.RefreshFormatDocVersions(); // Update List for new value
_Config = tmp.Config;
_DTS = tmp.DTS;
_UserID = tmp.UserID;
@@ -400,21 +364,21 @@ namespace VEPROMS.CSLA.Library
{
if (_FolderID != tmp.FolderID)
{
if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for old value
MyFolder?.RefreshFolderDocVersions(); // Update List for old value
_FolderID = tmp.FolderID; // Update the value
}
_MyFolder = null; // Reset list so that the next line gets a new list
if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for new value
MyFolder?.RefreshFolderDocVersions(); // Update List for new value
_VersionType = tmp.VersionType;
_Name = tmp.Name;
_Title = tmp.Title;
if (_ItemID != tmp.ItemID)
{
if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for old value
MyItem?.RefreshItemDocVersions(); // Update List for old value
_ItemID = tmp.ItemID; // Update the value
}
_MyItem = null; // Reset list so that the next line gets a new list
if (MyItem != null) MyItem.RefreshItemDocVersions(); // Update List for new value
MyItem?.RefreshItemDocVersions(); // Update List for new value
_Config = tmp.Config;
_DTS = tmp.DTS;
_UserID = tmp.UserID;
@@ -433,21 +397,21 @@ namespace VEPROMS.CSLA.Library
{
if (_FolderID != tmp.FolderID)
{
if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for old value
MyFolder?.RefreshFolderDocVersions(); // Update List for old value
_FolderID = tmp.FolderID; // Update the value
}
_MyFolder = null; // Reset list so that the next line gets a new list
if (MyFolder != null) MyFolder.RefreshFolderDocVersions(); // Update List for new value
MyFolder?.RefreshFolderDocVersions(); // Update List for new value
_VersionType = tmp.VersionType;
_Name = tmp.Name;
_Title = tmp.Title;
if (_FormatID != tmp.FormatID)
{
if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for old value
MyFormat?.RefreshFormatDocVersions(); // Update List for old value
_FormatID = tmp.FormatID; // Update the value
}
_MyFormat = null; // Reset list so that the next line gets a new list
if (MyFormat != null) MyFormat.RefreshFormatDocVersions(); // Update List for new value
MyFormat?.RefreshFormatDocVersions(); // Update List for new value
_Config = tmp.Config;
_DTS = tmp.DTS;
_UserID = tmp.UserID;
@@ -456,8 +420,6 @@ namespace VEPROMS.CSLA.Library
}
public static DocVersionInfo Get(int versionID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a DocVersion");
try
{
DocVersionInfo tmp = GetCachedByPrimaryKey(versionID);
@@ -496,13 +458,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _VersionID;
public int VersionID
{ get { return _VersionID; } }
public PKCriteria(int versionID)
{
_VersionID = versionID;
}
private readonly int _VersionID;
public int VersionID => _VersionID;
public PKCriteria(int versionID) => _VersionID = versionID;
}
private void ReadData(SafeDataReader dr)
{
@@ -567,7 +525,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
DocVersionInfoExtension _DocVersionInfoExtension = new DocVersionInfoExtension();
readonly DocVersionInfoExtension _DocVersionInfoExtension = new DocVersionInfoExtension();
[Serializable()]
partial class DocVersionInfoExtension : extensionBase { }
[Serializable()]
@@ -583,10 +541,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DocVersionInfo)
if (destType == typeof(string) && value is DocVersionInfo info)
{
// Return the ToString value
return ((DocVersionInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<DocVersionInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<DocVersionInfo> Items => base.Items;
public void AddEvents()
{
foreach (DocVersionInfo tmp in this)
{
@@ -44,23 +41,19 @@ namespace VEPROMS.CSLA.Library
for (int i = 0; i < Count; i++)
{
if (base[i] == sender)
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
}
}
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~DocVersionInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DocVersionInfoList()
{
_CountFinalized++;
}
@@ -104,18 +97,7 @@ namespace VEPROMS.CSLA.Library
{
_DocVersionInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static DocVersionInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<DocVersionInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on DocVersionInfoList.Get", ex);
// }
//}
public static DocVersionInfoList GetByFolderID(int folderID)
{
try
@@ -164,7 +146,7 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
private void DataPortal_Fetch()
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfoList.DataPortal_Fetch", GetHashCode());
try
{
@@ -178,7 +160,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new DocVersionInfo(dr));
while (dr.Read()) Add(new DocVersionInfo(dr));
IsReadOnly = true;
}
}
@@ -189,16 +171,13 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("DocVersionInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
[Serializable()]
private class FolderIDCriteria
{
public FolderIDCriteria(int folderID)
{
_FolderID = folderID;
}
private int _FolderID;
public FolderIDCriteria(int folderID) => _FolderID = folderID;
private int _FolderID;
public int FolderID
{
get { return _FolderID; }
@@ -207,7 +186,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(FolderIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfoList.DataPortal_FetchFolderID", GetHashCode());
try
{
@@ -222,7 +201,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new DocVersionInfo(dr));
while (dr.Read()) Add(new DocVersionInfo(dr));
IsReadOnly = true;
}
}
@@ -233,16 +212,13 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfoList.DataPortal_FetchFolderID", ex);
throw new DbCslaException("DocVersionInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
[Serializable()]
private class FormatIDCriteria
{
public FormatIDCriteria(int? formatID)
{
_FormatID = formatID;
}
private int? _FormatID;
public FormatIDCriteria(int? formatID) => _FormatID = formatID;
private int? _FormatID;
public int? FormatID
{
get { return _FormatID; }
@@ -251,7 +227,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(FormatIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfoList.DataPortal_FetchFormatID", GetHashCode());
try
{
@@ -266,7 +242,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new DocVersionInfo(dr));
while (dr.Read()) Add(new DocVersionInfo(dr));
IsReadOnly = true;
}
}
@@ -277,16 +253,13 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfoList.DataPortal_FetchFormatID", ex);
throw new DbCslaException("DocVersionInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
[Serializable()]
private class ItemIDCriteria
{
public ItemIDCriteria(int? itemID)
{
_ItemID = itemID;
}
private int? _ItemID;
public ItemIDCriteria(int? itemID) => _ItemID = itemID;
private int? _ItemID;
public int? ItemID
{
get { return _ItemID; }
@@ -295,7 +268,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(ItemIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfoList.DataPortal_FetchItemID", GetHashCode());
try
{
@@ -310,7 +283,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new DocVersionInfo(dr));
while (dr.Read()) Add(new DocVersionInfo(dr));
IsReadOnly = true;
}
}
@@ -321,48 +294,37 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfoList.DataPortal_FetchItemID", ex);
throw new DbCslaException("DocVersionInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
DocVersionInfoListPropertyDescriptor pd = new DocVersionInfoListPropertyDescriptor(this, i);
@@ -379,7 +341,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class DocVersionInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private DocVersionInfo Item { get { return (DocVersionInfo)_Item; } }
public DocVersionInfoListPropertyDescriptor(DocVersionInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -388,10 +349,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DocVersionInfoList)
if (destType == typeof(string) && value is DocVersionInfoList list)
{
// Return department and department role separated by comma.
return ((DocVersionInfoList)value).Items.Count.ToString() + " DocVersions";
return $"{list.Items.Count} DocVersions";
}
return base.ConvertTo(context, culture, value, destType);
}
+142 -303
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -95,6 +93,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Document> _CacheList = new List<Document>();
protected static void AddToCache(Document document)
{
@@ -104,6 +103,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(document)) _CacheList.Remove(document); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Document>> _CacheByPrimaryKey = new Dictionary<string, List<Document>>();
private static void ConvertListToDictionary()
{
@@ -129,15 +129,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextDocID = -1;
public static int NextDocID
{
get { return _nextDocID--; }
}
public static int NextDocID => _nextDocID--;
private int _DocID;
[System.ComponentModel.DataObjectField(true, true)]
public int DocID
@@ -354,10 +348,7 @@ namespace VEPROMS.CSLA.Library
return _DocumentEntries;
}
}
public void Reset_DocumentEntries()
{
_DocumentEntryCount = -1;
}
public void Reset_DocumentEntries() => _DocumentEntryCount = -1;
private int _DocumentPdfCount = 0;
/// <summary>
/// Count of DocumentPdfs for this Document
@@ -389,10 +380,7 @@ namespace VEPROMS.CSLA.Library
return _DocumentPdfs;
}
}
public void Reset_DocumentPdfs()
{
_DocumentPdfCount = -1;
}
public void Reset_DocumentPdfs() => _DocumentPdfCount = -1;
public override bool IsDirty
{
get
@@ -407,37 +395,22 @@ 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)) || (_DocumentPdfs == null ? false : _DocumentPdfs.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_DocumentDROUsages != null && _DocumentDROUsages.IsDirtyList(list)) || (_DocumentEntries != null && _DocumentEntries.IsDirtyList(list)) || (_DocumentPdfs != null && _DocumentPdfs.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_DocumentDROUsages == null ? true : _DocumentDROUsages.IsValidList(list)) && (_DocumentEntries == null ? true : _DocumentEntries.IsValidList(list)) && (_DocumentPdfs == null ? true : _DocumentPdfs.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_DocumentDROUsages == null || _DocumentDROUsages.IsValidList(list)) && (_DocumentEntries == null || _DocumentEntries.IsValidList(list)) && (_DocumentPdfs == null || _DocumentPdfs.IsValidList(list));
}
// CSLATODO: Replace base Document.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Document</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Document.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Document</returns>
protected override object GetIdValue()
{
return MyDocumentUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyDocumentUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -468,8 +441,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -502,37 +475,11 @@ namespace VEPROMS.CSLA.Library
_DocumentExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(DocID, "<Role(s)>");
//AuthorizationRules.AllowRead(LibTitle, "<Role(s)>");
//AuthorizationRules.AllowRead(DocContent, "<Role(s)>");
//AuthorizationRules.AllowRead(DocAscii, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(FileExtension, "<Role(s)>");
//AuthorizationRules.AllowWrite(LibTitle, "<Role(s)>");
//AuthorizationRules.AllowWrite(DocContent, "<Role(s)>");
//AuthorizationRules.AllowWrite(DocAscii, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FileExtension, "<Role(s)>");
_DocumentExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -540,57 +487,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_DocumentExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
/// <summary>
/// determines if related records (Foreign Keys) will keep this Item from being deleted
/// </summary>
public bool CanDelete
{
get
{
// Check to make sure that there are not any related records
int usedByCount = 0;
usedByCount += _DocumentDROUsageCount;
usedByCount += _DocumentEntryCount;
usedByCount += _DocumentPdfCount;
return (usedByCount == 0);
}
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _DocumentUnique = 0;
protected static int DocumentUnique
{ get { return ++_DocumentUnique; } }
private int _MyDocumentUnique = DocumentUnique;
public int MyDocumentUnique // Absolutely Unique ID - Editable
{ get { return _MyDocumentUnique; } }
protected static int DocumentUnique => ++_DocumentUnique;
private readonly int _MyDocumentUnique = DocumentUnique;
// Absolutely Unique ID - Editable
public int MyDocumentUnique => _MyDocumentUnique;
protected Document()
{/* require use of factory methods */
AddToCache(this);
@@ -599,15 +503,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Document()
{
_CountFinalized++;
@@ -632,8 +532,6 @@ namespace VEPROMS.CSLA.Library
}
public static Document New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Document");
try
{
return DataPortal.Create<Document>();
@@ -699,8 +597,6 @@ namespace VEPROMS.CSLA.Library
}
public static Document Get(int docID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Document");
try
{
Document tmp = GetCachedByPrimaryKey(docID);
@@ -726,14 +622,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Document(dr);
return null;
}
internal Document(SafeDataReader dr)
{
ReadData(dr);
}
internal Document(SafeDataReader dr) => ReadData(dr);
public static void Delete(int docID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Document");
try
{
DataPortal.Delete(new PKCriteria(docID));
@@ -745,12 +636,6 @@ namespace VEPROMS.CSLA.Library
}
public override Document Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Document");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Document");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Document");
try
{
BuildRefreshList();
@@ -770,13 +655,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _DocID;
public int DocID
{ get { return _DocID; } }
public PKCriteria(int docID)
{
_DocID = docID;
}
private readonly int _DocID;
public int DocID => _DocID;
public PKCriteria(int docID) => _DocID = docID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -861,7 +742,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Document.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -886,44 +767,52 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addDocument";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@LibTitle", _LibTitle);
cm.Parameters.AddWithValue("@DocContent", _DocContent);
cm.Parameters.AddWithValue("@DocAscii", _DocAscii);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@FileExtension", _FileExtension);
// Output Calculated Columns
SqlParameter param_DocID = new SqlParameter("@newDocID", SqlDbType.Int);
param_DocID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_DocID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_DocID = (int)cm.Parameters["@newDocID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addDocument";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@LibTitle", _LibTitle);
cm.Parameters.AddWithValue("@DocContent", _DocContent);
cm.Parameters.AddWithValue("@DocAscii", _DocAscii);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@FileExtension", _FileExtension);
// Output Calculated Columns
SqlParameter param_DocID = new SqlParameter("@newDocID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_DocID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_DocID = (int)cm.Parameters["@newDocID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_DocumentEntries != null) _DocumentEntries.Update(this);
if (_DocumentDROUsages != null) _DocumentDROUsages.Update(this);
if (_DocumentPdfs != null) _DocumentPdfs.Update(this);
_DocumentEntries?.Update(this);
_DocumentDROUsages?.Update(this);
_DocumentPdfs?.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.SQLInsert", GetHashCode());
}
catch (Exception ex)
@@ -933,7 +822,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Document.SQLInsert", ex);
}
}
[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)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.Add", 0);
@@ -953,11 +842,15 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@FileExtension", fileExtension);
// Output Calculated Columns
SqlParameter param_DocID = new SqlParameter("@newDocID", SqlDbType.Int);
param_DocID.Direction = ParameterDirection.Output;
SqlParameter param_DocID = new SqlParameter("@newDocID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_DocID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -972,7 +865,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Document.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -995,46 +888,52 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateDocument";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@DocID", _DocID);
cm.Parameters.AddWithValue("@LibTitle", _LibTitle);
cm.Parameters.AddWithValue("@DocContent", _DocContent);
cm.Parameters.AddWithValue("@DocAscii", _DocAscii);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
cm.Parameters.AddWithValue("@FileExtension", _FileExtension);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateDocument";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@DocID", _DocID);
cm.Parameters.AddWithValue("@LibTitle", _LibTitle);
cm.Parameters.AddWithValue("@DocContent", _DocContent);
cm.Parameters.AddWithValue("@DocAscii", _DocAscii);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
cm.Parameters.AddWithValue("@FileExtension", _FileExtension);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// 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);
_DocumentEntries?.Update(this);
_DocumentDROUsages?.Update(this);
_DocumentPdfs?.Update(this);
}
catch (Exception ex)
{
@@ -1045,21 +944,25 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_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);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_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);
}
MarkOld();
}
if (_DocumentEntries != null) _DocumentEntries.Update(this);
if (_DocumentDROUsages != null) _DocumentDROUsages.Update(this);
if (_DocumentPdfs != null) _DocumentPdfs.Update(this);
_DocumentEntries?.Update(this);
_DocumentDROUsages?.Update(this);
_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)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.Update", 0);
@@ -1081,8 +984,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
cm.Parameters.AddWithValue("@FileExtension", fileExtension);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -1096,12 +1001,9 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Document.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_DocID));
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_DocID));
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Delete", GetHashCode());
@@ -1126,7 +1028,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Document.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int docID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.Remove", 0);
@@ -1167,16 +1069,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _DocID;
private readonly int _DocID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int docID)
{
_DocID = docID;
}
public bool Exists => _exists;
public ExistsCommand(int docID) => _DocID = docID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Execute", GetHashCode());
@@ -1184,7 +1080,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -1206,7 +1102,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
DocumentExtension _DocumentExtension = new DocumentExtension();
readonly DocumentExtension _DocumentExtension = new DocumentExtension();
[Serializable()]
partial class DocumentExtension : extensionBase
{
@@ -1215,18 +1111,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual string DefaultFileExtension
{
get { return ".Doc"; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
public virtual string DefaultFileExtension => ".Doc";
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1255,61 +1142,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Document)
if (destType == typeof(string) && value is Document doc)
{
// Return the ToString value
return ((Document)value).ToString();
return doc.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create DocumentExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Document
// {
// partial class DocumentExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public virtual string DefaultFileExtension
// {
// get { return ".Doc"; }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty)
refreshDocumentAudits.Add(this);
}
private void ClearRefreshList()
{
_RefreshDocumentAudits = new List<DocumentAudit>();
}
private void ClearRefreshList() => _RefreshDocumentAudits = new List<DocumentAudit>();
private void BuildRefreshList()
{
ClearRefreshList();
@@ -56,6 +51,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<DocumentAudit> _CacheList = new List<DocumentAudit>();
protected static void AddToCache(DocumentAudit documentAudit)
{
@@ -65,6 +61,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(documentAudit)) _CacheList.Remove(documentAudit); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<DocumentAudit>> _CacheByPrimaryKey = new Dictionary<string, List<DocumentAudit>>();
private static void ConvertListToDictionary()
{
@@ -90,15 +87,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextAuditID = -1;
public static int NextAuditID
{
get { return _nextAuditID--; }
}
public static int NextAuditID => _nextAuditID--;
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -294,40 +285,14 @@ namespace VEPROMS.CSLA.Library
}
}
}
public override bool IsDirty
{
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
// CSLATODO: Replace base DocumentAudit.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current DocumentAudit</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
// CSLATODO: Check DocumentAudit.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current DocumentAudit</returns>
protected override object GetIdValue()
{
return MyDocumentAuditUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyDocumentAuditUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -355,8 +320,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules?.BrokenRules);
}
}
protected override void AddBusinessRules()
@@ -389,43 +354,11 @@ namespace VEPROMS.CSLA.Library
_DocumentAuditExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AuditID, "<Role(s)>");
//AuthorizationRules.AllowRead(DocID, "<Role(s)>");
//AuthorizationRules.AllowRead(LibTitle, "<Role(s)>");
//AuthorizationRules.AllowRead(DocContent, "<Role(s)>");
//AuthorizationRules.AllowRead(DocAscii, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(FileExtension, "<Role(s)>");
//AuthorizationRules.AllowRead(DocPdf, "<Role(s)>");
//AuthorizationRules.AllowRead(DeleteStatus, "<Role(s)>");
//AuthorizationRules.AllowWrite(DocID, "<Role(s)>");
//AuthorizationRules.AllowWrite(LibTitle, "<Role(s)>");
//AuthorizationRules.AllowWrite(DocContent, "<Role(s)>");
//AuthorizationRules.AllowWrite(DocAscii, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FileExtension, "<Role(s)>");
//AuthorizationRules.AllowWrite(DocPdf, "<Role(s)>");
//AuthorizationRules.AllowWrite(DeleteStatus, "<Role(s)>");
_DocumentAuditExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -433,42 +366,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_DocumentAuditExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _DocumentAuditUnique = 0;
protected static int DocumentAuditUnique
{ get { return ++_DocumentAuditUnique; } }
private int _MyDocumentAuditUnique = DocumentAuditUnique;
public int MyDocumentAuditUnique // Absolutely Unique ID - Editable
{ get { return _MyDocumentAuditUnique; } }
protected static int DocumentAuditUnique => ++_DocumentAuditUnique;
private readonly int _MyDocumentAuditUnique = DocumentAuditUnique;
// Absolutely Unique ID - Editable
public int MyDocumentAuditUnique => _MyDocumentAuditUnique;
protected DocumentAudit()
{/* require use of factory methods */
AddToCache(this);
@@ -477,15 +382,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DocumentAudit()
{
_CountFinalized++;
@@ -510,8 +411,6 @@ namespace VEPROMS.CSLA.Library
}
public static DocumentAudit New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a DocumentAudit");
try
{
return DataPortal.Create<DocumentAudit>();
@@ -564,8 +463,6 @@ namespace VEPROMS.CSLA.Library
}
public static DocumentAudit Get(long auditID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a DocumentAudit");
try
{
DocumentAudit tmp = GetCachedByPrimaryKey(auditID);
@@ -591,14 +488,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new DocumentAudit(dr);
return null;
}
internal DocumentAudit(SafeDataReader dr)
{
ReadData(dr);
}
internal DocumentAudit(SafeDataReader dr) => ReadData(dr);
public static void Delete(long auditID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a DocumentAudit");
try
{
DataPortal.Delete(new PKCriteria(auditID));
@@ -610,12 +502,6 @@ namespace VEPROMS.CSLA.Library
}
public override DocumentAudit Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a DocumentAudit");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a DocumentAudit");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a DocumentAudit");
try
{
BuildRefreshList();
@@ -635,13 +521,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private long _AuditID;
public long AuditID
{ get { return _AuditID; } }
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
private readonly long _AuditID;
public long AuditID => _AuditID;
public PKCriteria(long auditID) => _AuditID = auditID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -714,7 +596,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("DocumentAudit.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -739,38 +621,44 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addDocumentAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@DocID", _DocID);
cm.Parameters.AddWithValue("@LibTitle", _LibTitle);
cm.Parameters.AddWithValue("@DocContent", _DocContent);
cm.Parameters.AddWithValue("@DocAscii", _DocAscii);
cm.Parameters.AddWithValue("@Config", _Config);
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);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addDocumentAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@DocID", _DocID);
cm.Parameters.AddWithValue("@LibTitle", _LibTitle);
cm.Parameters.AddWithValue("@DocContent", _DocContent);
cm.Parameters.AddWithValue("@DocAscii", _DocAscii);
cm.Parameters.AddWithValue("@Config", _Config);
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);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.SQLInsert", GetHashCode());
@@ -782,7 +670,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("DocumentAudit.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Add(SqlConnection cn, ref long auditID, int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf, int deleteStatus)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.Add", 0);
@@ -805,8 +693,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@DocPdf", docPdf);
cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -821,7 +711,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("DocumentAudit.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -844,39 +734,43 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateDocumentAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@DocID", _DocID);
cm.Parameters.AddWithValue("@LibTitle", _LibTitle);
cm.Parameters.AddWithValue("@DocContent", _DocContent);
cm.Parameters.AddWithValue("@DocAscii", _DocAscii);
cm.Parameters.AddWithValue("@Config", _Config);
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);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateDocumentAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@DocID", _DocID);
cm.Parameters.AddWithValue("@LibTitle", _LibTitle);
cm.Parameters.AddWithValue("@DocContent", _DocContent);
cm.Parameters.AddWithValue("@DocAscii", _DocAscii);
cm.Parameters.AddWithValue("@Config", _Config);
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);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -889,18 +783,22 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
DocumentAudit.Add(cn, ref _AuditID, _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, _FileExtension, _DocPdf, _DeleteStatus);
else
DocumentAudit.Update(cn, ref _AuditID, _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, _FileExtension, _DocPdf, _DeleteStatus);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
DocumentAudit.Add(cn, ref _AuditID, _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, _FileExtension, _DocPdf, _DeleteStatus);
else
DocumentAudit.Update(cn, ref _AuditID, _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, _FileExtension, _DocPdf, _DeleteStatus);
}
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Update(SqlConnection cn, ref long auditID, int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf, int deleteStatus)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.Update", 0);
@@ -936,12 +834,9 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("DocumentAudit.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_AuditID));
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_AuditID));
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.DataPortal_Delete", GetHashCode());
@@ -966,7 +861,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("DocumentAudit.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, long auditID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.Remove", 0);
@@ -992,7 +887,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
DocumentAuditExtension _DocumentAuditExtension = new DocumentAuditExtension();
readonly DocumentAuditExtension _DocumentAuditExtension = new DocumentAuditExtension();
[Serializable()]
partial class DocumentAuditExtension : extensionBase
{
@@ -1029,49 +924,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DocumentAudit)
if (destType == typeof(string) && value is DocumentAudit audit)
{
// Return the ToString value
return ((DocumentAudit)value).ToString();
return audit.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create DocumentAuditExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class DocumentAudit
// {
// partial class DocumentAuditExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class DocumentAuditInfo : ReadOnlyBase<DocumentAuditInfo>, IDisposable
{
public event DocumentAuditInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<DocumentAuditInfo> _CacheList = new List<DocumentAuditInfo>();
protected static void AddToCache(DocumentAuditInfo documentAuditInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(documentAuditInfo)) _CacheList.Remove(documentAuditInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<DocumentAuditInfo>> _CacheByPrimaryKey = new Dictionary<string, List<DocumentAuditInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected DocumentAudit _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -180,32 +164,19 @@ namespace VEPROMS.CSLA.Library
return _DeleteStatus;
}
}
// CSLATODO: Replace base DocumentAuditInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current DocumentAuditInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check DocumentAuditInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current DocumentAuditInfo</returns>
protected override object GetIdValue()
{
return MyDocumentAuditInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyDocumentAuditInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _DocumentAuditInfoUnique = 0;
private static int DocumentAuditInfoUnique
{ get { return ++_DocumentAuditInfoUnique; } }
private int _MyDocumentAuditInfoUnique = DocumentAuditInfoUnique;
public int MyDocumentAuditInfoUnique // Absolutely Unique ID - Info
{ get { return _MyDocumentAuditInfoUnique; } }
private static int DocumentAuditInfoUnique => ++_DocumentAuditInfoUnique;
private readonly int _MyDocumentAuditInfoUnique = DocumentAuditInfoUnique;
// Absolutely Unique ID - Info
public int MyDocumentAuditInfoUnique => _MyDocumentAuditInfoUnique;
protected DocumentAuditInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -214,15 +185,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DocumentAuditInfo()
{
_CountFinalized++;
@@ -239,10 +206,7 @@ namespace VEPROMS.CSLA.Library
if (listDocumentAuditInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list
}
public virtual DocumentAudit Get()
{
return _Editable = DocumentAudit.Get(_AuditID);
}
public virtual DocumentAudit Get() => _Editable = DocumentAudit.Get(_AuditID);
public static void Refresh(DocumentAudit tmp)
{
string key = tmp.AuditID.ToString();
@@ -267,8 +231,6 @@ namespace VEPROMS.CSLA.Library
}
public static DocumentAuditInfo Get(long auditID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a DocumentAudit");
try
{
DocumentAuditInfo tmp = GetCachedByPrimaryKey(auditID);
@@ -307,13 +269,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private long _AuditID;
public long AuditID
{ get { return _AuditID; } }
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
private readonly long _AuditID;
public long AuditID => _AuditID;
public PKCriteria(long auditID) => _AuditID = auditID;
}
private void ReadData(SafeDataReader dr)
{
@@ -377,7 +335,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
DocumentAuditInfoExtension _DocumentAuditInfoExtension = new DocumentAuditInfoExtension();
readonly DocumentAuditInfoExtension _DocumentAuditInfoExtension = new DocumentAuditInfoExtension();
[Serializable()]
partial class DocumentAuditInfoExtension : extensionBase { }
[Serializable()]
@@ -393,10 +351,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DocumentAuditInfo)
if (destType == typeof(string) && value is DocumentAuditInfo info)
{
// Return the ToString value
return ((DocumentAuditInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<DocumentAuditInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<DocumentAuditInfo> Items => base.Items;
public void AddEvents()
{
foreach (DocumentAuditInfo tmp in this)
{
@@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~DocumentAuditInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DocumentAuditInfoList()
{
_CountFinalized++;
}
@@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on DocumentAuditInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all DocumentAuditInfo.
/// </summary>
public static void Reset()
{
_DocumentAuditInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static DocumentAuditInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<DocumentAuditInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on DocumentAuditInfoList.Get", ex);
// }
//}
private DocumentAuditInfoList()
/// <summary>
/// Reset the list of all DocumentAuditInfo.
/// </summary>
public static void Reset() => _DocumentAuditInfoList = null;
private DocumentAuditInfoList()
{ /* require use of factory methods */ }
#endregion
#region Data Access Portal
@@ -149,41 +127,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -205,7 +172,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class DocumentAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private DocumentAuditInfo Item { get { return (DocumentAuditInfo)_Item; } }
public DocumentAuditInfoListPropertyDescriptor(DocumentAuditInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -214,10 +180,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DocumentAuditInfoList)
if (destType == typeof(string) && value is DocumentAuditInfoList list)
{
// Return department and department role separated by comma.
return ((DocumentAuditInfoList)value).Items.Count.ToString() + " DocumentAudits";
return $"{list.Items.Count} DocumentAudits";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _DROUsageID;
[System.ComponentModel.DataObjectField(true, true)]
public int DROUsageID
@@ -232,10 +226,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current DocumentDROUsage</returns>
protected override object GetIdValue()
{
return MyDocumentDROUsageUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyDocumentDROUsageUnique; // Absolutely Unique ID
// CSLATODO: Replace base DocumentDROUsage.ToString function as necessary
/// <summary>
/// Overrides Base ToString
@@ -259,18 +250,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyRODb == null ? false : _MyRODb.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyRODb != null && _MyRODb.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRODb == null ? true : _MyRODb.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyRODb == null || _MyRODb.IsValidList(list));
}
#endregion
#region ValidationRules
@@ -300,8 +288,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -331,78 +319,22 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(DROUsageID, "<Role(s)>");
//AuthorizationRules.AllowRead(ROID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ROID, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(RODbID, "<Role(s)>");
//AuthorizationRules.AllowWrite(RODbID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _DocumentDROUsageUnique = 0;
private static int DocumentDROUsageUnique
{ get { return ++_DocumentDROUsageUnique; } }
private int _MyDocumentDROUsageUnique = DocumentDROUsageUnique;
public int MyDocumentDROUsageUnique // Absolutely Unique ID - Editable FK
{ get { return _MyDocumentDROUsageUnique; } }
internal static DocumentDROUsage New(string roid, RODb myRODb)
{
return new DocumentDROUsage(roid, myRODb);
}
internal static DocumentDROUsage Get(SafeDataReader dr)
{
return new DocumentDROUsage(dr);
}
private static int DocumentDROUsageUnique => ++_DocumentDROUsageUnique;
private readonly int _MyDocumentDROUsageUnique = DocumentDROUsageUnique;
// Absolutely Unique ID - Editable FK
public int MyDocumentDROUsageUnique => _MyDocumentDROUsageUnique;
internal static DocumentDROUsage New(string roid, RODb myRODb) => new DocumentDROUsage(roid, myRODb);
internal static DocumentDROUsage Get(SafeDataReader dr) => new DocumentDROUsage(dr);
public DocumentDROUsage()
{
MarkAsChild();
@@ -431,15 +363,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DocumentDROUsage()
{
_CountFinalized++;
@@ -481,33 +409,46 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Document myDocument)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = DROUsage.Add(cn, ref _DROUsageID, myDocument, _ROID, _Config, _DTS, _UserID, _MyRODb);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = DROUsage.Add(cn, ref _DROUsageID, myDocument, _ROID, _Config, _DTS, _UserID, _MyRODb);
}
MarkOld();
}
internal void Update(Document myDocument)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = DROUsage.Update(cn, ref _DROUsageID, myDocument.DocID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _RODbID);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = DROUsage.Update(cn, ref _DROUsageID, myDocument.DocID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _RODbID);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Document myDocument)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
DROUsage.Remove(cn, _DROUsageID);
if (IsNew) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
DROUsage.Remove(cn, _DROUsageID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
DocumentDROUsageExtension _DocumentDROUsageExtension = new DocumentDROUsageExtension();
readonly DocumentDROUsageExtension _DocumentDROUsageExtension = new DocumentDROUsageExtension();
[Serializable()]
partial class DocumentDROUsageExtension : extensionBase
{
@@ -516,18 +457,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultDocID
{
get { return 0; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultDocID => 0;
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -556,61 +488,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DocumentDROUsage)
if (destType == typeof(string) && value is DocumentDROUsage usage)
{
// Return the ToString value
return ((DocumentDROUsage)value).ToString();
return usage.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create DocumentDROUsageExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class DocumentDROUsage
// {
// partial class DocumentDROUsageExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultDocID
// {
// get { return 0; }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public DocumentDROUsage this[DROUsage myDROUsage]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public DocumentDROUsage this[DROUsage myDROUsage]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<DocumentDROUsage> Items
{
get { return base.Items; }
}
public DocumentDROUsage GetItem(DROUsage myDROUsage)
public new System.Collections.Generic.IList<DocumentDROUsage> Items => base.Items;
public DocumentDROUsage GetItem(DROUsage myDROUsage)
{
foreach (DocumentDROUsage dROUsage in this)
if (dROUsage.DROUsageID == myDROUsage.DROUsageID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public DocumentDROUsage Add(string roid, RODb myRODb) // One to Many
{
DocumentDROUsage dROUsage = DocumentDROUsage.New(roid, myRODb);
this.Add(dROUsage);
Add(dROUsage);
return dROUsage;
}
public void Remove(DROUsage myDROUsage)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (DocumentDROUsage child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (DocumentDROUsage child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static DocumentDROUsages New()
{
return new DocumentDROUsages();
}
internal static DocumentDROUsages Get(SafeDataReader dr)
{
return new DocumentDROUsages(dr);
}
public static DocumentDROUsages GetByDocID(int docID)
#endregion
#region Factory Methods
internal static DocumentDROUsages New() => new DocumentDROUsages();
internal static DocumentDROUsages Get(SafeDataReader dr) => new DocumentDROUsages(dr);
public static DocumentDROUsages GetByDocID(int docID)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on DocumentDROUsages.GetByDocID", ex);
}
}
private DocumentDROUsages()
{
MarkAsChild();
}
internal DocumentDROUsages(SafeDataReader dr)
private DocumentDROUsages() => MarkAsChild();
internal DocumentDROUsages(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~DocumentDROUsages()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DocumentDROUsages()
{
_CountFinalized++;
}
@@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(DocumentDROUsage.Get(dr));
this.RaiseListChangedEvents = true;
Add(DocumentDROUsage.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class DocIDCriteria
{
public DocIDCriteria(int docID)
{
_DocID = docID;
}
private int _DocID;
public DocIDCriteria(int docID) => _DocID = docID;
private int _DocID;
public int DocID
{
get { return _DocID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(DocIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentDROUsages.DataPortal_FetchDocID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new DocumentDROUsage(dr));
while (dr.Read()) Add(new DocumentDROUsage(dr));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentDROUsages.DataPortal_FetchDocID", ex);
throw new DbCslaException("DocumentDROUsages.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Document document)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
DocumentDROUsagesPropertyDescriptor pd = new DocumentDROUsagesPropertyDescriptor(this, i);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class DocumentDROUsagesPropertyDescriptor : vlnListPropertyDescriptor
{
private DocumentDROUsage Item { get { return (DocumentDROUsage)_Item; } }
public DocumentDROUsagesPropertyDescriptor(DocumentDROUsages collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DocumentDROUsages)
if (destType == typeof(string) && value is DocumentDROUsages usages)
{
// Return department and department role separated by comma.
return ((DocumentDROUsages)value).Items.Count.ToString() + " DROUsages";
return $"{usages.Items.Count} DROUsages";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public DocumentEntry this[Entry myEntry]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public DocumentEntry this[Entry myEntry]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<DocumentEntry> Items
{
get { return base.Items; }
}
public DocumentEntry GetItem(Entry myEntry)
public new System.Collections.Generic.IList<DocumentEntry> Items => base.Items;
public DocumentEntry GetItem(Entry myEntry)
{
foreach (DocumentEntry entry in this)
if (entry.ContentID == myEntry.ContentID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public DocumentEntry Add(Entry myEntry) // One to Many
{
DocumentEntry entry = DocumentEntry.New(myEntry);
this.Add(entry);
Add(entry);
return entry;
}
public void Remove(Entry myEntry)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (DocumentEntry child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (DocumentEntry child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static DocumentEntries New()
{
return new DocumentEntries();
}
internal static DocumentEntries Get(SafeDataReader dr)
{
return new DocumentEntries(dr);
}
public static DocumentEntries GetByDocID(int docID)
#endregion
#region Factory Methods
internal static DocumentEntries New() => new DocumentEntries();
internal static DocumentEntries Get(SafeDataReader dr) => new DocumentEntries(dr);
public static DocumentEntries GetByDocID(int docID)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on DocumentEntries.GetByDocID", ex);
}
}
private DocumentEntries()
{
MarkAsChild();
}
internal DocumentEntries(SafeDataReader dr)
private DocumentEntries() => MarkAsChild();
internal DocumentEntries(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~DocumentEntries()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DocumentEntries()
{
_CountFinalized++;
}
@@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(DocumentEntry.Get(dr));
this.RaiseListChangedEvents = true;
Add(DocumentEntry.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class DocIDCriteria
{
public DocIDCriteria(int docID)
{
_DocID = docID;
}
private int _DocID;
public DocIDCriteria(int docID) => _DocID = docID;
private int _DocID;
public int DocID
{
get { return _DocID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(DocIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentEntries.DataPortal_FetchDocID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new DocumentEntry(dr));
while (dr.Read()) Add(new DocumentEntry(dr));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentEntries.DataPortal_FetchDocID", ex);
throw new DbCslaException("DocumentEntries.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Document document)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
DocumentEntriesPropertyDescriptor pd = new DocumentEntriesPropertyDescriptor(this, i);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class DocumentEntriesPropertyDescriptor : vlnListPropertyDescriptor
{
private DocumentEntry Item { get { return (DocumentEntry)_Item; } }
public DocumentEntriesPropertyDescriptor(DocumentEntries collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DocumentEntries)
if (destType == typeof(string) && value is DocumentEntries entries)
{
// Return department and department role separated by comma.
return ((DocumentEntries)value).Items.Count.ToString() + " Entries";
return $"{entries.Items.Count} Entries";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)]
public int ContentID
@@ -170,35 +164,13 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current DocumentEntry</returns>
protected override object GetIdValue()
{
return MyDocumentEntryUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base DocumentEntry.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current DocumentEntry</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty
{
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
protected override object GetIdValue() => MyDocumentEntryUnique; // Absolutely Unique ID
public override bool IsDirty => base.IsDirty;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsDirtyList(List<object> list) => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsValidList(List<object> list) => (IsNew && !IsDirty) || base.IsValid;
#endregion
#region ValidationRules
[NonSerialized]
@@ -226,8 +198,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -239,72 +211,22 @@ namespace VEPROMS.CSLA.Library
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100));
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _DocumentEntryUnique = 0;
private static int DocumentEntryUnique
{ get { return ++_DocumentEntryUnique; } }
private int _MyDocumentEntryUnique = DocumentEntryUnique;
public int MyDocumentEntryUnique // Absolutely Unique ID - Editable FK
{ get { return _MyDocumentEntryUnique; } }
internal static DocumentEntry New(Entry myEntry)
{
return new DocumentEntry(myEntry);
}
internal static DocumentEntry Get(SafeDataReader dr)
{
return new DocumentEntry(dr);
}
private static int DocumentEntryUnique => ++_DocumentEntryUnique;
private readonly int _MyDocumentEntryUnique = DocumentEntryUnique;
// Absolutely Unique ID - Editable FK
public int MyDocumentEntryUnique => _MyDocumentEntryUnique;
internal static DocumentEntry New(Entry myEntry) => new DocumentEntry(myEntry);
internal static DocumentEntry Get(SafeDataReader dr) => new DocumentEntry(dr);
public DocumentEntry()
{
MarkAsChild();
@@ -331,15 +253,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DocumentEntry()
{
_CountFinalized++;
@@ -379,33 +297,46 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Document myDocument)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Entry.Add(cn, _MyEntry.MyContent, myDocument, _DTS, _UserID);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Entry.Add(cn, _MyEntry.MyContent, myDocument, _DTS, _UserID);
}
MarkOld();
}
internal void Update(Document myDocument)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Entry.Update(cn, _ContentID, myDocument.DocID, _DTS, _UserID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Entry.Update(cn, _ContentID, myDocument.DocID, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Document myDocument)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Entry.Remove(cn, _ContentID);
if (IsNew) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Entry.Remove(cn, _ContentID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
DocumentEntryExtension _DocumentEntryExtension = new DocumentEntryExtension();
readonly DocumentEntryExtension _DocumentEntryExtension = new DocumentEntryExtension();
[Serializable()]
partial class DocumentEntryExtension : extensionBase
{
@@ -414,14 +345,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -450,57 +375,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DocumentEntry)
if (destType == typeof(string) && value is DocumentEntry entry)
{
// Return the ToString value
return ((DocumentEntry)value).ToString();
return entry.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create DocumentEntryExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class DocumentEntry
// {
// partial class DocumentEntryExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class DocumentInfo : ReadOnlyBase<DocumentInfo>, IDisposable
{
public event DocumentInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<DocumentInfo> _CacheList = new List<DocumentInfo>();
protected static void AddToCache(DocumentInfo documentInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(documentInfo)) _CacheList.Remove(documentInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<DocumentInfo>> _CacheByPrimaryKey = new Dictionary<string, List<DocumentInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Document _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _DocID;
[System.ComponentModel.DataObjectField(true, true)]
public int DocID
@@ -276,32 +260,19 @@ namespace VEPROMS.CSLA.Library
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
/// </summary>
/// <returns>A string representation of current DocumentInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check DocumentInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current DocumentInfo</returns>
protected override object GetIdValue()
{
return MyDocumentInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyDocumentInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _DocumentInfoUnique = 0;
private static int DocumentInfoUnique
{ get { return ++_DocumentInfoUnique; } }
private int _MyDocumentInfoUnique = DocumentInfoUnique;
public int MyDocumentInfoUnique // Absolutely Unique ID - Info
{ get { return _MyDocumentInfoUnique; } }
private static int DocumentInfoUnique => ++_DocumentInfoUnique;
private readonly int _MyDocumentInfoUnique = DocumentInfoUnique;
// Absolutely Unique ID - Info
public int MyDocumentInfoUnique => _MyDocumentInfoUnique;
protected DocumentInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -310,15 +281,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DocumentInfo()
{
_CountFinalized++;
@@ -335,10 +302,7 @@ namespace VEPROMS.CSLA.Library
if (listDocumentInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(DocID.ToString()); // remove the list
}
public virtual Document Get()
{
return _Editable = Document.Get(_DocID);
}
public virtual Document Get() => _Editable = Document.Get(_DocID);
public static void Refresh(Document tmp)
{
string key = tmp.DocID.ToString();
@@ -361,8 +325,6 @@ namespace VEPROMS.CSLA.Library
}
public static DocumentInfo Get(int docID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Document");
try
{
DocumentInfo tmp = GetCachedByPrimaryKey(docID);
@@ -401,13 +363,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _DocID;
public int DocID
{ get { return _DocID; } }
public PKCriteria(int docID)
{
_DocID = docID;
}
private readonly int _DocID;
public int DocID => _DocID;
public PKCriteria(int docID) => _DocID = docID;
}
private void ReadData(SafeDataReader dr)
{
@@ -472,7 +430,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
DocumentInfoExtension _DocumentInfoExtension = new DocumentInfoExtension();
readonly DocumentInfoExtension _DocumentInfoExtension = new DocumentInfoExtension();
[Serializable()]
partial class DocumentInfoExtension : extensionBase { }
[Serializable()]
@@ -488,10 +446,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DocumentInfo)
if (destType == typeof(string) && value is DocumentInfo info)
{
// Return the ToString value
return ((DocumentInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<DocumentInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<DocumentInfo> Items => base.Items;
public void AddEvents()
{
foreach (DocumentInfo tmp in this)
{
@@ -44,23 +41,19 @@ namespace VEPROMS.CSLA.Library
for (int i = 0; i < Count; i++)
{
if (base[i] == sender)
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
}
}
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~DocumentInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DocumentInfoList()
{
_CountFinalized++;
}
@@ -97,32 +90,17 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on DocumentInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all DocumentInfo.
/// </summary>
public static void Reset()
{
_DocumentInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static DocumentInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<DocumentInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on DocumentInfoList.Get", ex);
// }
//}
private DocumentInfoList()
/// <summary>
/// Reset the list of all DocumentInfo.
/// </summary>
public static void Reset() => _DocumentInfoList = null;
private DocumentInfoList()
{ /* require use of factory methods */ }
#endregion
#region Data Access Portal
private void DataPortal_Fetch()
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfoList.DataPortal_Fetch", GetHashCode());
try
{
@@ -136,7 +114,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new DocumentInfo(dr));
while (dr.Read()) Add(new DocumentInfo(dr));
IsReadOnly = true;
}
}
@@ -147,48 +125,37 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("DocumentInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
DocumentInfoListPropertyDescriptor pd = new DocumentInfoListPropertyDescriptor(this, i);
@@ -205,7 +172,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class DocumentInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private DocumentInfo Item { get { return (DocumentInfo)_Item; } }
public DocumentInfoListPropertyDescriptor(DocumentInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -214,10 +180,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DocumentInfoList)
if (destType == typeof(string) && value is DocumentInfoList list)
{
// Return department and department role separated by comma.
return ((DocumentInfoList)value).Items.Count.ToString() + " Documents";
return $"{list.Items.Count} Documents";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _DebugStatus;
/// <summary>
/// > 0 for Debug
@@ -171,35 +165,13 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current DocumentPdf</returns>
protected override object GetIdValue()
{
return MyDocumentPdfUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base DocumentPdf.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current DocumentPdf</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty
{
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
protected override object GetIdValue() => MyDocumentPdfUnique; // Absolutely Unique ID
public override bool IsDirty => base.IsDirty;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsDirtyList(List<object> list) => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsValidList(List<object> list) => (IsNew && !IsDirty) || base.IsValid;
#endregion
#region ValidationRules
[NonSerialized]
@@ -227,8 +199,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -240,80 +212,21 @@ namespace VEPROMS.CSLA.Library
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100));
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(DebugStatus, "<Role(s)>");
//AuthorizationRules.AllowRead(TopRow, "<Role(s)>");
//AuthorizationRules.AllowRead(PageLength, "<Role(s)>");
//AuthorizationRules.AllowRead(LeftMargin, "<Role(s)>");
//AuthorizationRules.AllowRead(PageWidth, "<Role(s)>");
//AuthorizationRules.AllowRead(PageCount, "<Role(s)>");
//AuthorizationRules.AllowWrite(PageCount, "<Role(s)>");
//AuthorizationRules.AllowRead(DocPdf, "<Role(s)>");
//AuthorizationRules.AllowWrite(DocPdf, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _DocumentPdfUnique = 0;
private static int DocumentPdfUnique
{ get { return ++_DocumentPdfUnique; } }
private int _MyDocumentPdfUnique = DocumentPdfUnique;
public int MyDocumentPdfUnique // Absolutely Unique ID - Editable FK
{ get { return _MyDocumentPdfUnique; } }
internal static DocumentPdf New(int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount)
{
return new DocumentPdf(debugStatus, topRow, pageLength, leftMargin, pageWidth, pageCount);
}
internal static DocumentPdf Get(SafeDataReader dr)
{
return new DocumentPdf(dr);
}
private static int DocumentPdfUnique => ++_DocumentPdfUnique;
private readonly int _MyDocumentPdfUnique = DocumentPdfUnique;
// Absolutely Unique ID - Editable FK
public int MyDocumentPdfUnique => _MyDocumentPdfUnique;
internal static DocumentPdf New(int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount) => new DocumentPdf(debugStatus, topRow, pageLength, leftMargin, pageWidth, pageCount);
internal static DocumentPdf Get(SafeDataReader dr) => new DocumentPdf(dr);
public DocumentPdf()
{
MarkAsChild();
@@ -345,15 +258,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DocumentPdf()
{
_CountFinalized++;
@@ -392,33 +301,45 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Document myDocument)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Pdf.Add(cn, myDocument, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth, _PageCount, _DocPdf, _DTS, _UserID);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Pdf.Add(cn, myDocument, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth, _PageCount, _DocPdf, _DTS, _UserID);
}
MarkOld();
}
internal void Update(Document myDocument)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Pdf.Update(cn, myDocument.DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth, _PageCount, _DocPdf, _DTS, _UserID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Pdf.Update(cn, myDocument.DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth, _PageCount, _DocPdf, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
internal void DeleteSelf(Document myDocument)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Pdf.Remove(cn, myDocument.DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth);
if (IsNew) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Pdf.Remove(cn, myDocument.DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
DocumentPdfExtension _DocumentPdfExtension = new DocumentPdfExtension();
readonly DocumentPdfExtension _DocumentPdfExtension = new DocumentPdfExtension();
[Serializable()]
partial class DocumentPdfExtension : extensionBase
{
@@ -427,14 +348,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -463,57 +378,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DocumentPdf)
if (destType == typeof(string) && value is DocumentPdf docpdf)
{
// Return the ToString value
return ((DocumentPdf)value).ToString();
return docpdf.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create DocumentPdfExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class DocumentPdf
// {
// partial class DocumentPdfExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public DocumentPdf this[int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public DocumentPdf this[int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<DocumentPdf> Items
{
get { return base.Items; }
}
public DocumentPdf GetItem(int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth)
public new System.Collections.Generic.IList<DocumentPdf> Items => base.Items;
public DocumentPdf GetItem(int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth)
{
foreach (DocumentPdf pdf in this)
if (pdf.DebugStatus == debugStatus && pdf.TopRow == topRow && pdf.PageLength == pageLength && pdf.LeftMargin == leftMargin && pdf.PageWidth == pageWidth)
@@ -63,7 +55,7 @@ namespace VEPROMS.CSLA.Library
if (!Contains(debugStatus, topRow, pageLength, leftMargin, pageWidth))
{
DocumentPdf pdf = DocumentPdf.New(debugStatus, topRow, pageLength, leftMargin, pageWidth, pageCount);
this.Add(pdf);
Add(pdf);
return pdf;
}
else
@@ -108,23 +100,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (DocumentPdf child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (DocumentPdf child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -142,20 +131,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static DocumentPdfs New()
{
return new DocumentPdfs();
}
internal static DocumentPdfs Get(SafeDataReader dr)
{
return new DocumentPdfs(dr);
}
public static DocumentPdfs GetByDocID(int docID)
#endregion
#region Factory Methods
internal static DocumentPdfs New() => new DocumentPdfs();
internal static DocumentPdfs Get(SafeDataReader dr) => new DocumentPdfs(dr);
public static DocumentPdfs GetByDocID(int docID)
{
try
{
@@ -166,11 +149,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on DocumentPdfs.GetByDocID", ex);
}
}
private DocumentPdfs()
{
MarkAsChild();
}
internal DocumentPdfs(SafeDataReader dr)
private DocumentPdfs() => MarkAsChild();
internal DocumentPdfs(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -179,16 +159,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~DocumentPdfs()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~DocumentPdfs()
{
_CountFinalized++;
}
@@ -203,19 +179,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(DocumentPdf.Get(dr));
this.RaiseListChangedEvents = true;
Add(DocumentPdf.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class DocIDCriteria
{
public DocIDCriteria(int docID)
{
_DocID = docID;
}
private int _DocID;
public DocIDCriteria(int docID) => _DocID = docID;
private int _DocID;
public int DocID
{
get { return _DocID; }
@@ -224,7 +197,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(DocIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentPdfs.DataPortal_FetchDocID", GetHashCode());
try
{
@@ -238,7 +211,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new DocumentPdf(dr));
while (dr.Read()) Add(new DocumentPdf(dr));
}
}
}
@@ -248,11 +221,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentPdfs.DataPortal_FetchDocID", ex);
throw new DbCslaException("DocumentPdfs.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Document document)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -271,49 +244,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
DocumentPdfsPropertyDescriptor pd = new DocumentPdfsPropertyDescriptor(this, i);
@@ -330,7 +292,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class DocumentPdfsPropertyDescriptor : vlnListPropertyDescriptor
{
private DocumentPdf Item { get { return (DocumentPdf)_Item; } }
public DocumentPdfsPropertyDescriptor(DocumentPdfs collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -339,10 +300,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is DocumentPdfs)
if (destType == typeof(string) && value is DocumentPdfs pdfs)
{
// Return department and department role separated by comma.
return ((DocumentPdfs)value).Items.Count.ToString() + " Pdfs";
return $"{pdfs.Items.Count} Pdfs";
}
return base.ConvertTo(context, culture, value, destType);
}
+113 -236
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -57,6 +55,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Entry> _CacheList = new List<Entry>();
protected static void AddToCache(Entry entry)
{
@@ -66,6 +65,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(entry)) _CacheList.Remove(entry); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Entry>> _CacheByPrimaryKey = new Dictionary<string, List<Entry>>();
private static void ConvertListToDictionary()
{
@@ -91,10 +91,7 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)]
public int ContentID
@@ -199,7 +196,7 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyDocument == null ? false : _MyDocument.IsDirtyList(list));
return base.IsDirty || (_MyDocument != null && _MyDocument.IsDirtyList(list));
}
public override bool IsValid
{
@@ -208,28 +205,16 @@ namespace VEPROMS.CSLA.Library
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocument == null ? true : _MyDocument.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyDocument == null || _MyDocument.IsValidList(list));
}
// CSLATODO: Replace base Entry.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Entry</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Entry.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Entry</returns>
protected override object GetIdValue()
{
return MyEntryUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyEntryUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -258,8 +243,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -288,29 +273,11 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(DocID, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DocID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_EntryExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -318,42 +285,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_EntryExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _EntryUnique = 0;
protected static int EntryUnique
{ get { return ++_EntryUnique; } }
private int _MyEntryUnique = EntryUnique;
public int MyEntryUnique // Absolutely Unique ID - Editable
{ get { return _MyEntryUnique; } }
protected static int EntryUnique => ++_EntryUnique;
private readonly int _MyEntryUnique = EntryUnique;
// Absolutely Unique ID - Editable
public int MyEntryUnique => _MyEntryUnique;
protected Entry()
{/* require use of factory methods */
AddToCache(this);
@@ -362,15 +301,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Entry()
{
_CountFinalized++;
@@ -395,8 +330,6 @@ namespace VEPROMS.CSLA.Library
}
public static Entry New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Entry");
try
{
return DataPortal.Create<Entry>();
@@ -464,8 +397,6 @@ namespace VEPROMS.CSLA.Library
}
public static Entry Get(int contentID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Entry");
try
{
Entry tmp = GetCachedByPrimaryKey(contentID);
@@ -491,14 +422,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Entry(dr);
return null;
}
internal Entry(SafeDataReader dr)
{
ReadData(dr);
}
internal Entry(SafeDataReader dr) => ReadData(dr);
public static void Delete(int contentID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Entry");
try
{
DataPortal.Delete(new PKCriteria(contentID));
@@ -510,12 +436,6 @@ namespace VEPROMS.CSLA.Library
}
public override Entry Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Entry");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Entry");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Entry");
try
{
BuildRefreshList();
@@ -535,13 +455,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _ContentID;
public int ContentID
{ get { return _ContentID; } }
public PKCriteria(int contentID)
{
_ContentID = contentID;
}
private readonly int _ContentID;
public int ContentID => _ContentID;
public PKCriteria(int contentID) => _ContentID = contentID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -609,7 +525,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Entry.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -634,33 +550,39 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyDocument != null) _MyDocument.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyDocument?.Update();
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addEntry";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@DocID", DocID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addEntry";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@DocID", DocID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.SQLInsert", GetHashCode());
@@ -672,7 +594,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Entry.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, Content myContent, Document myDocument, DateTime dts, string userID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.Add", 0);
@@ -689,8 +611,10 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -704,7 +628,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Entry.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -727,38 +651,44 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.SQLUpdate", GetHashCode());
try
{
if (_MyDocument != null) _MyDocument.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyDocument?.Update();
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateEntry";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@DocID", DocID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateEntry";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@DocID", DocID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -771,14 +701,18 @@ namespace VEPROMS.CSLA.Library
}
internal void Update(Content content)
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Entry.Add(cn, content, MyDocument, _DTS, _UserID);
else
_LastChanged = Entry.Update(cn, content.ContentID, _DocID, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = Entry.Add(cn, content, MyDocument, _DTS, _UserID);
else
_LastChanged = Entry.Update(cn, content.ContentID, _DocID, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
// B2018-126 & B2018-133: Refresh for library document usage change (note that original checkin had a null check for
// _MyDocument.DocumentEntries that was causing a sql Distributed Transaction Coordinator error - this was removed
@@ -790,7 +724,7 @@ namespace VEPROMS.CSLA.Library
}
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, int contentID, int docID, DateTime dts, string userID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.Update", 0);
@@ -808,8 +742,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -823,12 +759,9 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Entry.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_ContentID));
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_ContentID));
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Delete", GetHashCode());
@@ -853,7 +786,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Entry.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int contentID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.Remove", 0);
@@ -894,16 +827,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _ContentID;
private readonly int _ContentID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int contentID)
{
_ContentID = contentID;
}
public bool Exists => _exists;
public ExistsCommand(int contentID) => _ContentID = contentID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Execute", GetHashCode());
@@ -911,7 +838,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -933,7 +860,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
EntryExtension _EntryExtension = new EntryExtension();
readonly EntryExtension _EntryExtension = new EntryExtension();
[Serializable()]
partial class EntryExtension : extensionBase
{
@@ -942,14 +869,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -978,57 +899,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Entry)
if (destType == typeof(string) && value is Entry entry)
{
// Return the ToString value
return ((Entry)value).ToString();
return entry.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create EntryExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Entry
// {
// partial class EntryExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty)
refreshEntryAudits.Add(this);
}
private void ClearRefreshList()
{
_RefreshEntryAudits = new List<EntryAudit>();
}
private void ClearRefreshList() => _RefreshEntryAudits = new List<EntryAudit>();
private void BuildRefreshList()
{
ClearRefreshList();
@@ -56,6 +51,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<EntryAudit> _CacheList = new List<EntryAudit>();
protected static void AddToCache(EntryAudit entryAudit)
{
@@ -65,6 +61,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(entryAudit)) _CacheList.Remove(entryAudit); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<EntryAudit>> _CacheByPrimaryKey = new Dictionary<string, List<EntryAudit>>();
private static void ConvertListToDictionary()
{
@@ -90,15 +87,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextAuditID = -1;
public static int NextAuditID
{
get { return _nextAuditID--; }
}
public static int NextAuditID => _nextAuditID--;
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -200,40 +191,14 @@ namespace VEPROMS.CSLA.Library
}
}
}
public override bool IsDirty
{
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
// CSLATODO: Replace base EntryAudit.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current EntryAudit</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
// CSLATODO: Check EntryAudit.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current EntryAudit</returns>
protected override object GetIdValue()
{
return MyEntryAuditUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyEntryAuditUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -261,8 +226,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -281,33 +246,11 @@ namespace VEPROMS.CSLA.Library
_EntryAuditExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AuditID, "<Role(s)>");
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(DocID, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(DeleteStatus, "<Role(s)>");
//AuthorizationRules.AllowWrite(ContentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DocID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DeleteStatus, "<Role(s)>");
_EntryAuditExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -315,42 +258,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_EntryAuditExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _EntryAuditUnique = 0;
protected static int EntryAuditUnique
{ get { return ++_EntryAuditUnique; } }
private int _MyEntryAuditUnique = EntryAuditUnique;
public int MyEntryAuditUnique // Absolutely Unique ID - Editable
{ get { return _MyEntryAuditUnique; } }
protected static int EntryAuditUnique => ++_EntryAuditUnique;
private readonly int _MyEntryAuditUnique = EntryAuditUnique;
// Absolutely Unique ID - Editable
public int MyEntryAuditUnique => _MyEntryAuditUnique;
protected EntryAudit()
{/* require use of factory methods */
AddToCache(this);
@@ -359,15 +274,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~EntryAudit()
{
_CountFinalized++;
@@ -392,8 +303,6 @@ namespace VEPROMS.CSLA.Library
}
public static EntryAudit New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a EntryAudit");
try
{
return DataPortal.Create<EntryAudit>();
@@ -431,8 +340,6 @@ namespace VEPROMS.CSLA.Library
}
public static EntryAudit Get(long auditID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a EntryAudit");
try
{
EntryAudit tmp = GetCachedByPrimaryKey(auditID);
@@ -464,8 +371,6 @@ namespace VEPROMS.CSLA.Library
}
public static void Delete(long auditID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a EntryAudit");
try
{
DataPortal.Delete(new PKCriteria(auditID));
@@ -477,12 +382,6 @@ namespace VEPROMS.CSLA.Library
}
public override EntryAudit Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a EntryAudit");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a EntryAudit");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a EntryAudit");
try
{
BuildRefreshList();
@@ -502,13 +401,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private long _AuditID;
public long AuditID
{ get { return _AuditID; } }
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
private readonly long _AuditID;
public long AuditID => _AuditID;
public PKCriteria(long auditID) => _AuditID = auditID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -576,7 +471,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("EntryAudit.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -601,33 +496,39 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addEntryAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@DocID", _DocID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addEntryAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@DocID", _DocID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.SQLInsert", GetHashCode());
@@ -639,7 +540,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("EntryAudit.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Add(SqlConnection cn, ref long auditID, int contentID, int docID, DateTime dts, string userID, int deleteStatus)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.Add", 0);
@@ -657,8 +558,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -673,7 +576,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("EntryAudit.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -696,34 +599,38 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateEntryAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@DocID", _DocID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateEntryAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@DocID", _DocID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -736,18 +643,22 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
EntryAudit.Add(cn, ref _AuditID, _ContentID, _DocID, _DTS, _UserID, _DeleteStatus);
else
EntryAudit.Update(cn, ref _AuditID, _ContentID, _DocID, _DTS, _UserID, _DeleteStatus);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
EntryAudit.Add(cn, ref _AuditID, _ContentID, _DocID, _DTS, _UserID, _DeleteStatus);
else
EntryAudit.Update(cn, ref _AuditID, _ContentID, _DocID, _DTS, _UserID, _DeleteStatus);
}
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Update(SqlConnection cn, ref long auditID, int contentID, int docID, DateTime dts, string userID, int deleteStatus)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.Update", 0);
@@ -778,12 +689,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("EntryAudit.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_AuditID));
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.DataPortal_Delete", GetHashCode());
@@ -808,7 +719,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("EntryAudit.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, long auditID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.Remove", 0);
@@ -834,7 +745,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
EntryAuditExtension _EntryAuditExtension = new EntryAuditExtension();
readonly EntryAuditExtension _EntryAuditExtension = new EntryAuditExtension();
[Serializable()]
partial class EntryAuditExtension : extensionBase
{
@@ -871,49 +782,14 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is EntryAudit)
if (destType == typeof(string) && value is EntryAudit audit)
{
// Return the ToString value
return ((EntryAudit)value).ToString();
return audit.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create EntryAuditExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class EntryAudit
// {
// partial class EntryAuditExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class EntryAuditInfo : ReadOnlyBase<EntryAuditInfo>, IDisposable
{
public event EntryAuditInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<EntryAuditInfo> _CacheList = new List<EntryAuditInfo>();
protected static void AddToCache(EntryAuditInfo entryAuditInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(entryAuditInfo)) _CacheList.Remove(entryAuditInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<EntryAuditInfo>> _CacheByPrimaryKey = new Dictionary<string, List<EntryAuditInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected EntryAudit _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -144,32 +128,19 @@ namespace VEPROMS.CSLA.Library
return _DeleteStatus;
}
}
// CSLATODO: Replace base EntryAuditInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current EntryAuditInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check EntryAuditInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current EntryAuditInfo</returns>
protected override object GetIdValue()
{
return MyEntryAuditInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyEntryAuditInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _EntryAuditInfoUnique = 0;
private static int EntryAuditInfoUnique
{ get { return ++_EntryAuditInfoUnique; } }
private int _MyEntryAuditInfoUnique = EntryAuditInfoUnique;
public int MyEntryAuditInfoUnique // Absolutely Unique ID - Info
{ get { return _MyEntryAuditInfoUnique; } }
private static int EntryAuditInfoUnique => ++_EntryAuditInfoUnique;
private readonly int _MyEntryAuditInfoUnique = EntryAuditInfoUnique;
// Absolutely Unique ID - Info
public int MyEntryAuditInfoUnique => _MyEntryAuditInfoUnique;
protected EntryAuditInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -178,15 +149,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~EntryAuditInfo()
{
_CountFinalized++;
@@ -203,10 +170,7 @@ namespace VEPROMS.CSLA.Library
if (listEntryAuditInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list
}
public virtual EntryAudit Get()
{
return _Editable = EntryAudit.Get(_AuditID);
}
public virtual EntryAudit Get() => _Editable = EntryAudit.Get(_AuditID);
public static void Refresh(EntryAudit tmp)
{
string key = tmp.AuditID.ToString();
@@ -227,8 +191,6 @@ namespace VEPROMS.CSLA.Library
}
public static EntryAuditInfo Get(long auditID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a EntryAudit");
try
{
EntryAuditInfo tmp = GetCachedByPrimaryKey(auditID);
@@ -267,13 +229,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private long _AuditID;
public long AuditID
{ get { return _AuditID; } }
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
private readonly long _AuditID;
public long AuditID => _AuditID;
public PKCriteria(long auditID) => _AuditID = auditID;
}
private void ReadData(SafeDataReader dr)
{
@@ -333,7 +291,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
EntryAuditInfoExtension _EntryAuditInfoExtension = new EntryAuditInfoExtension();
readonly EntryAuditInfoExtension _EntryAuditInfoExtension = new EntryAuditInfoExtension();
[Serializable()]
partial class EntryAuditInfoExtension : extensionBase { }
[Serializable()]
@@ -349,10 +307,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is EntryAuditInfo)
if (destType == typeof(string) && value is EntryAuditInfo info)
{
// Return the ToString value
return ((EntryAuditInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<EntryAuditInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<EntryAuditInfo> Items => base.Items;
public void AddEvents()
{
foreach (EntryAuditInfo tmp in this)
{
@@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~EntryAuditInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~EntryAuditInfoList()
{
_CountFinalized++;
}
@@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on EntryAuditInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all EntryAuditInfo.
/// </summary>
public static void Reset()
{
_EntryAuditInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static EntryAuditInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<EntryAuditInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on EntryAuditInfoList.Get", ex);
// }
//}
private EntryAuditInfoList()
/// <summary>
/// Reset the list of all EntryAuditInfo.
/// </summary>
public static void Reset() => _EntryAuditInfoList = null;
private EntryAuditInfoList()
{ /* require use of factory methods */ }
#endregion
#region Data Access Portal
@@ -149,41 +127,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -205,7 +172,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class EntryAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private EntryAuditInfo Item { get { return (EntryAuditInfo)_Item; } }
public EntryAuditInfoListPropertyDescriptor(EntryAuditInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -214,10 +180,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is EntryAuditInfoList)
if (destType == typeof(string) && value is EntryAuditInfoList list)
{
// Return department and department role separated by comma.
return ((EntryAuditInfoList)value).Items.Count.ToString() + " EntryAudits";
return $"{list.Items.Count} EntryAudits";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class EntryInfo : ReadOnlyBase<EntryInfo>, IDisposable
{
public event EntryInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<EntryInfo> _CacheList = new List<EntryInfo>();
protected static void AddToCache(EntryInfo entryInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(entryInfo)) _CacheList.Remove(entryInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<EntryInfo>> _CacheByPrimaryKey = new Dictionary<string, List<EntryInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Entry _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)]
public int ContentID
@@ -149,32 +133,19 @@ namespace VEPROMS.CSLA.Library
return _UserID;
}
}
// CSLATODO: Replace base EntryInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current EntryInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check EntryInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current EntryInfo</returns>
protected override object GetIdValue()
{
return MyEntryInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyEntryInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _EntryInfoUnique = 0;
private static int EntryInfoUnique
{ get { return ++_EntryInfoUnique; } }
private int _MyEntryInfoUnique = EntryInfoUnique;
public int MyEntryInfoUnique // Absolutely Unique ID - Info
{ get { return _MyEntryInfoUnique; } }
private static int EntryInfoUnique => ++_EntryInfoUnique;
private readonly int _MyEntryInfoUnique = EntryInfoUnique;
// Absolutely Unique ID - Info
public int MyEntryInfoUnique => _MyEntryInfoUnique;
protected EntryInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -183,15 +154,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~EntryInfo()
{
_CountFinalized++;
@@ -208,10 +175,7 @@ namespace VEPROMS.CSLA.Library
if (listEntryInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list
}
public virtual Entry Get()
{
return _Editable = Entry.Get(_ContentID);
}
public virtual Entry Get() => _Editable = Entry.Get(_ContentID);
public static void Refresh(Entry tmp)
{
string key = tmp.ContentID.ToString();
@@ -224,11 +188,11 @@ namespace VEPROMS.CSLA.Library
{
if (_DocID != tmp.DocID)
{
if (MyDocument != null) MyDocument.RefreshDocumentEntries(); // Update List for old value
MyDocument?.RefreshDocumentEntries(); // Update List for old value
_DocID = tmp.DocID; // Update the value
}
_MyDocument = null; // Reset list so that the next line gets a new list
if (MyDocument != null) MyDocument.RefreshDocumentEntries(); // Update List for new value
MyDocument?.RefreshDocumentEntries(); // Update List for new value
_DTS = tmp.DTS;
_UserID = tmp.UserID;
_EntryInfoExtension.Refresh(this);
@@ -251,8 +215,6 @@ namespace VEPROMS.CSLA.Library
}
public static EntryInfo Get(int contentID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Entry");
try
{
EntryInfo tmp = GetCachedByPrimaryKey(contentID);
@@ -291,13 +253,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _ContentID;
public int ContentID
{ get { return _ContentID; } }
public PKCriteria(int contentID)
{
_ContentID = contentID;
}
private readonly int _ContentID;
public int ContentID => _ContentID;
public PKCriteria(int contentID) => _ContentID = contentID;
}
private void ReadData(SafeDataReader dr)
{
@@ -355,7 +313,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
EntryInfoExtension _EntryInfoExtension = new EntryInfoExtension();
readonly EntryInfoExtension _EntryInfoExtension = new EntryInfoExtension();
[Serializable()]
partial class EntryInfoExtension : extensionBase { }
[Serializable()]
@@ -371,10 +329,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is EntryInfo)
if (destType == typeof(string) && value is EntryInfo info)
{
// Return the ToString value
return ((EntryInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<EntryInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<EntryInfo> Items => base.Items;
public void AddEvents()
{
foreach (EntryInfo tmp in this)
{
@@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~EntryInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~EntryInfoList()
{
_CountFinalized++;
}
@@ -104,18 +97,6 @@ namespace VEPROMS.CSLA.Library
{
_EntryInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static EntryInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<EntryInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on EntryInfoList.Get", ex);
// }
//}
public static EntryInfoList GetByContentID(int contentID)
{
try
@@ -180,11 +161,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ContentIDCriteria
{
public ContentIDCriteria(int contentID)
{
_ContentID = contentID;
}
private int _ContentID;
public ContentIDCriteria(int contentID) => _ContentID = contentID;
private int _ContentID;
public int ContentID
{
get { return _ContentID; }
@@ -224,11 +202,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class DocIDCriteria
{
public DocIDCriteria(int docID)
{
_DocID = docID;
}
private int _DocID;
public DocIDCriteria(int docID) => _DocID = docID;
private int _DocID;
public int DocID
{
get { return _DocID; }
@@ -265,41 +240,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -321,7 +285,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class EntryInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private EntryInfo Item { get { return (EntryInfo)_Item; } }
public EntryInfoListPropertyDescriptor(EntryInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -330,10 +293,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is EntryInfoList)
if (destType == typeof(string) && value is EntryInfoList list)
{
// Return department and department role separated by comma.
return ((EntryInfoList)value).Items.Count.ToString() + " Entries";
return $"{list.Items.Count} Entries";
}
return base.ConvertTo(context, culture, value, destType);
}
+134 -263
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -58,6 +56,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Figure> _CacheList = new List<Figure>();
protected static void AddToCache(Figure figure)
{
@@ -67,7 +66,9 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(figure)) _CacheList.Remove(figure); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Figure>> _CacheByPrimaryKey = new Dictionary<string, List<Figure>>();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Figure>> _CacheByROFstID_ImageID = new Dictionary<string, List<Figure>>();
private static void ConvertListToDictionary()
{
@@ -102,15 +103,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextFigureID = -1;
public static int NextFigureID
{
get { return _nextFigureID--; }
}
public static int NextFigureID => _nextFigureID--;
private int _FigureID;
[System.ComponentModel.DataObjectField(true, true)]
public int FigureID
@@ -252,37 +247,22 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyROFst == null ? false : _MyROFst.IsDirtyList(list)) || (_MyROImage == null ? false : _MyROImage.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyROFst != null && _MyROFst.IsDirtyList(list)) || (_MyROImage != null && _MyROImage.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyROFst == null ? true : _MyROFst.IsValidList(list)) && (_MyROImage == null ? true : _MyROImage.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyROFst == null || _MyROFst.IsValidList(list)) && (_MyROImage == null || _MyROImage.IsValidList(list));
}
// CSLATODO: Replace base Figure.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Figure</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Figure.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Figure</returns>
protected override object GetIdValue()
{
return MyFigureUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyFigureUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -312,8 +292,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -355,33 +335,11 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(FigureID, "<Role(s)>");
//AuthorizationRules.AllowRead(ROFstID, "<Role(s)>");
//AuthorizationRules.AllowRead(ImageID, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ROFstID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ImageID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_FigureExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -389,42 +347,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_FigureExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _FigureUnique = 0;
protected static int FigureUnique
{ get { return ++_FigureUnique; } }
private int _MyFigureUnique = FigureUnique;
public int MyFigureUnique // Absolutely Unique ID - Editable
{ get { return _MyFigureUnique; } }
protected static int FigureUnique => ++_FigureUnique;
private readonly int _MyFigureUnique = FigureUnique;
// Absolutely Unique ID - Editable
public int MyFigureUnique => _MyFigureUnique;
protected Figure()
{/* require use of factory methods */
AddToCache(this);
@@ -433,15 +363,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Figure()
{
_CountFinalized++;
@@ -478,8 +404,6 @@ namespace VEPROMS.CSLA.Library
}
public static Figure New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Figure");
try
{
return DataPortal.Create<Figure>();
@@ -548,8 +472,6 @@ namespace VEPROMS.CSLA.Library
}
public static Figure Get(int figureID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Figure");
try
{
Figure tmp = GetCachedByPrimaryKey(figureID);
@@ -572,8 +494,6 @@ namespace VEPROMS.CSLA.Library
}
public static Figure GetByROFstID_ImageID(int rOFstID, int imageID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Figure");
try
{
Figure tmp = GetCachedByROFstID_ImageID(rOFstID, imageID);
@@ -599,14 +519,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Figure(dr);
return null;
}
internal Figure(SafeDataReader dr)
{
ReadData(dr);
}
internal Figure(SafeDataReader dr) => ReadData(dr);
public static void Delete(int figureID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Figure");
try
{
DataPortal.Delete(new PKCriteria(figureID));
@@ -618,12 +533,6 @@ namespace VEPROMS.CSLA.Library
}
public override Figure Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Figure");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Figure");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Figure");
try
{
BuildRefreshList();
@@ -643,23 +552,17 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _FigureID;
public int FigureID
{ get { return _FigureID; } }
public PKCriteria(int figureID)
{
_FigureID = figureID;
}
private readonly int _FigureID;
public int FigureID => _FigureID;
public PKCriteria(int figureID) => _FigureID = figureID;
}
[Serializable()]
private class ROFstID_ImageIDCriteria
{
private int _ROFstID;
public int ROFstID
{ get { return _ROFstID; } }
private int _ImageID;
public int ImageID
{ get { return _ImageID; } }
private readonly int _ROFstID;
public int ROFstID => _ROFstID;
private readonly int _ImageID;
public int ImageID => _ImageID;
public ROFstID_ImageIDCriteria(int rOFstID, int imageID)
{
_ROFstID = rOFstID;
@@ -771,7 +674,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Figure.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -796,39 +699,47 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyROFst != null) _MyROFst.Update();
if (_MyROImage != null) _MyROImage.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyROFst?.Update();
_MyROImage?.Update();
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addFigure";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ROFstID", ROFstID);
cm.Parameters.AddWithValue("@ImageID", ImageID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_FigureID = new SqlParameter("@newFigureID", SqlDbType.Int);
param_FigureID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_FigureID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_FigureID = (int)cm.Parameters["@newFigureID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addFigure";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ROFstID", ROFstID);
cm.Parameters.AddWithValue("@ImageID", ImageID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_FigureID = new SqlParameter("@newFigureID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_FigureID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_FigureID = (int)cm.Parameters["@newFigureID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.SQLInsert", GetHashCode());
@@ -840,7 +751,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Figure.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int figureID, ROFst myROFst, ROImage myROImage, string config, DateTime dts, string userID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.Add", 0);
@@ -858,11 +769,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns
SqlParameter param_FigureID = new SqlParameter("@newFigureID", SqlDbType.Int);
param_FigureID.Direction = ParameterDirection.Output;
SqlParameter param_FigureID = new SqlParameter("@newFigureID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_FigureID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -877,7 +792,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Figure.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -900,41 +815,47 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.SQLUpdate", GetHashCode());
try
{
if (_MyROFst != null) _MyROFst.Update();
if (_MyROImage != null) _MyROImage.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyROFst?.Update();
_MyROImage?.Update();
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateFigure";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@FigureID", _FigureID);
cm.Parameters.AddWithValue("@ROFstID", ROFstID);
cm.Parameters.AddWithValue("@ImageID", ImageID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateFigure";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@FigureID", _FigureID);
cm.Parameters.AddWithValue("@ROFstID", ROFstID);
cm.Parameters.AddWithValue("@ImageID", ImageID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -947,18 +868,22 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Figure.Add(cn, ref _FigureID, _MyROFst, _MyROImage, _Config, _DTS, _UserID);
else
_LastChanged = Figure.Update(cn, ref _FigureID, _ROFstID, _ImageID, _Config, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = Figure.Add(cn, ref _FigureID, _MyROFst, _MyROImage, _Config, _DTS, _UserID);
else
_LastChanged = Figure.Update(cn, ref _FigureID, _ROFstID, _ImageID, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int figureID, int rOFstID, int imageID, string config, DateTime dts, string userID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.Update", 0);
@@ -978,8 +903,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -993,12 +920,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Figure.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_FigureID));
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.DataPortal_Delete", GetHashCode());
@@ -1023,7 +950,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Figure.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int figureID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.Remove", 0);
@@ -1064,16 +991,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _FigureID;
private readonly int _FigureID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int figureID)
{
_FigureID = figureID;
}
public bool Exists => _exists;
public ExistsCommand(int figureID) => _FigureID = figureID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.DataPortal_Execute", GetHashCode());
@@ -1081,7 +1002,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -1103,7 +1024,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
FigureExtension _FigureExtension = new FigureExtension();
readonly FigureExtension _FigureExtension = new FigureExtension();
[Serializable()]
partial class FigureExtension : extensionBase
{
@@ -1112,14 +1033,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1148,57 +1063,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Figure)
if (destType == typeof(string) && value is Figure figure)
{
// Return the ToString value
return ((Figure)value).ToString();
return figure.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create FigureExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Figure
// {
// partial class FigureExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class FigureInfo : ReadOnlyBase<FigureInfo>, IDisposable
{
public event FigureInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<FigureInfo> _CacheList = new List<FigureInfo>();
protected static void AddToCache(FigureInfo figureInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(figureInfo)) _CacheList.Remove(figureInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<FigureInfo>> _CacheByPrimaryKey = new Dictionary<string, List<FigureInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Figure _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _FigureID;
[System.ComponentModel.DataObjectField(true, true)]
public int FigureID
@@ -166,32 +150,19 @@ namespace VEPROMS.CSLA.Library
return _UserID;
}
}
// CSLATODO: Replace base FigureInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current FigureInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check FigureInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current FigureInfo</returns>
protected override object GetIdValue()
{
return MyFigureInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyFigureInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _FigureInfoUnique = 0;
private static int FigureInfoUnique
{ get { return ++_FigureInfoUnique; } }
private int _MyFigureInfoUnique = FigureInfoUnique;
public int MyFigureInfoUnique // Absolutely Unique ID - Info
{ get { return _MyFigureInfoUnique; } }
private static int FigureInfoUnique => ++_FigureInfoUnique;
private readonly int _MyFigureInfoUnique = FigureInfoUnique;
// Absolutely Unique ID - Info
public int MyFigureInfoUnique => _MyFigureInfoUnique;
protected FigureInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -200,15 +171,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FigureInfo()
{
_CountFinalized++;
@@ -225,10 +192,7 @@ namespace VEPROMS.CSLA.Library
if (listFigureInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(FigureID.ToString()); // remove the list
}
public virtual Figure Get()
{
return _Editable = Figure.Get(_FigureID);
}
public virtual Figure Get() => _Editable = Figure.Get(_FigureID);
public static void Refresh(Figure tmp)
{
string key = tmp.FigureID.ToString();
@@ -241,18 +205,18 @@ namespace VEPROMS.CSLA.Library
{
if (_ROFstID != tmp.ROFstID)
{
if (MyROFst != null) MyROFst.RefreshROFstFigures(); // Update List for old value
MyROFst?.RefreshROFstFigures(); // Update List for old value
_ROFstID = tmp.ROFstID; // Update the value
}
_MyROFst = null; // Reset list so that the next line gets a new list
if (MyROFst != null) MyROFst.RefreshROFstFigures(); // Update List for new value
MyROFst?.RefreshROFstFigures(); // Update List for new value
if (_ImageID != tmp.ImageID)
{
if (MyROImage != null) MyROImage.RefreshROImageFigures(); // Update List for old value
MyROImage?.RefreshROImageFigures(); // Update List for old value
_ImageID = tmp.ImageID; // Update the value
}
_MyROImage = null; // Reset list so that the next line gets a new list
if (MyROImage != null) MyROImage.RefreshROImageFigures(); // Update List for new value
MyROImage?.RefreshROImageFigures(); // Update List for new value
_Config = tmp.Config;
_DTS = tmp.DTS;
_UserID = tmp.UserID;
@@ -271,11 +235,11 @@ namespace VEPROMS.CSLA.Library
{
if (_ImageID != tmp.ImageID)
{
if (MyROImage != null) MyROImage.RefreshROImageFigures(); // Update List for old value
MyROImage?.RefreshROImageFigures(); // Update List for old value
_ImageID = tmp.ImageID; // Update the value
}
_MyROImage = null; // Reset list so that the next line gets a new list
if (MyROImage != null) MyROImage.RefreshROImageFigures(); // Update List for new value
MyROImage?.RefreshROImageFigures(); // Update List for new value
_Config = tmp.Config;
_DTS = tmp.DTS;
_UserID = tmp.UserID;
@@ -294,11 +258,11 @@ namespace VEPROMS.CSLA.Library
{
if (_ROFstID != tmp.ROFstID)
{
if (MyROFst != null) MyROFst.RefreshROFstFigures(); // Update List for old value
MyROFst?.RefreshROFstFigures(); // Update List for old value
_ROFstID = tmp.ROFstID; // Update the value
}
_MyROFst = null; // Reset list so that the next line gets a new list
if (MyROFst != null) MyROFst.RefreshROFstFigures(); // Update List for new value
MyROFst?.RefreshROFstFigures(); // Update List for new value
_Config = tmp.Config;
_DTS = tmp.DTS;
_UserID = tmp.UserID;
@@ -307,8 +271,6 @@ namespace VEPROMS.CSLA.Library
}
public static FigureInfo Get(int figureID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Figure");
try
{
FigureInfo tmp = GetCachedByPrimaryKey(figureID);
@@ -347,13 +309,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _FigureID;
public int FigureID
{ get { return _FigureID; } }
public PKCriteria(int figureID)
{
_FigureID = figureID;
}
private readonly int _FigureID;
public int FigureID => _FigureID;
public PKCriteria(int figureID) => _FigureID = figureID;
}
private string _ROImage_FileName = string.Empty;
public string ROImage_FileName
@@ -427,7 +385,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
FigureInfoExtension _FigureInfoExtension = new FigureInfoExtension();
readonly FigureInfoExtension _FigureInfoExtension = new FigureInfoExtension();
[Serializable()]
partial class FigureInfoExtension : extensionBase { }
[Serializable()]
@@ -443,10 +401,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FigureInfo)
if (destType == typeof(string) && value is FigureInfo info)
{
// Return the ToString value
return ((FigureInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<FigureInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<FigureInfo> Items => base.Items;
public void AddEvents()
{
foreach (FigureInfo tmp in this)
{
@@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~FigureInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FigureInfoList()
{
_CountFinalized++;
}
@@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on FigureInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all FigureInfo.
/// </summary>
public static void Reset()
{
_FigureInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static FigureInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<FigureInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on FigureInfoList.Get", ex);
// }
//}
public static FigureInfoList GetByROFstID(int rOFstID)
/// <summary>
/// Reset the list of all FigureInfo.
/// </summary>
public static void Reset() => _FigureInfoList = null;
public static FigureInfoList GetByROFstID(int rOFstID)
{
try
{
@@ -180,11 +158,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ROFstIDCriteria
{
public ROFstIDCriteria(int rOFstID)
{
_ROFstID = rOFstID;
}
private int _ROFstID;
public ROFstIDCriteria(int rOFstID) => _ROFstID = rOFstID;
private int _ROFstID;
public int ROFstID
{
get { return _ROFstID; }
@@ -224,11 +199,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ImageIDCriteria
{
public ImageIDCriteria(int imageID)
{
_ImageID = imageID;
}
private int _ImageID;
public ImageIDCriteria(int imageID) => _ImageID = imageID;
private int _ImageID;
public int ImageID
{
get { return _ImageID; }
@@ -265,41 +237,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -321,7 +282,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class FigureInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private FigureInfo Item { get { return (FigureInfo)_Item; } }
public FigureInfoListPropertyDescriptor(FigureInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -330,10 +290,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FigureInfoList)
if (destType == typeof(string) && value is FigureInfoList list)
{
// Return department and department role separated by comma.
return ((FigureInfoList)value).Items.Count.ToString() + " Figures";
return $"{list.Items.Count} Figures";
}
return base.ConvertTo(context, culture, value, destType);
}
+171 -344
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -91,6 +89,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Folder> _CacheList = new List<Folder>();
protected static void AddToCache(Folder folder)
{
@@ -100,7 +99,9 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(folder)) _CacheList.Remove(folder); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Folder>> _CacheByPrimaryKey = new Dictionary<string, List<Folder>>();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Folder>> _CacheByParentID_Name = new Dictionary<string, List<Folder>>();
private static void ConvertListToDictionary()
{
@@ -135,15 +136,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextFolderID = -1;
public static int NextFolderID
{
get { return _nextFolderID--; }
}
public static int NextFolderID => _nextFolderID--;
private int _FolderID;
[System.ComponentModel.DataObjectField(true, true)]
public int FolderID
@@ -407,10 +402,7 @@ namespace VEPROMS.CSLA.Library
return _FolderAssignments;
}
}
public void Reset_FolderAssignments()
{
_FolderAssignmentCount = -1;
}
public void Reset_FolderAssignments() => _FolderAssignmentCount = -1;
private int _FolderDocVersionCount = 0;
/// <summary>
/// Count of FolderDocVersions for this Folder
@@ -442,10 +434,7 @@ namespace VEPROMS.CSLA.Library
return _FolderDocVersions;
}
}
public void Reset_FolderDocVersions()
{
_FolderDocVersionCount = -1;
}
public void Reset_FolderDocVersions() => _FolderDocVersionCount = -1;
private int _ChildFolderCount = 0;
/// <summary>
/// Count of ChildFolders for this Folder
@@ -477,10 +466,7 @@ namespace VEPROMS.CSLA.Library
return _ChildFolders;
}
}
public void Reset_ChildFolders()
{
_ChildFolderCount = -1;
}
public void Reset_ChildFolders() => _ChildFolderCount = -1;
public override bool IsDirty
{
get
@@ -495,37 +481,22 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_FolderAssignments == null ? false : _FolderAssignments.IsDirtyList(list)) || (_FolderDocVersions == null ? false : _FolderDocVersions.IsDirtyList(list)) || (_ChildFolders == null ? false : _ChildFolders.IsDirtyList(list)) || (_MyConnection == null ? false : _MyConnection.IsDirtyList(list)) || (_MyFormat == null ? false : _MyFormat.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_FolderAssignments != null && _FolderAssignments.IsDirtyList(list)) || (_FolderDocVersions != null && _FolderDocVersions.IsDirtyList(list)) || (_ChildFolders != null && _ChildFolders.IsDirtyList(list)) || (_MyConnection != null && _MyConnection.IsDirtyList(list)) || (_MyFormat != null && _MyFormat.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_FolderAssignments == null ? true : _FolderAssignments.IsValidList(list)) && (_FolderDocVersions == null ? true : _FolderDocVersions.IsValidList(list)) && (_ChildFolders == null ? true : _ChildFolders.IsValidList(list)) && (_MyConnection == null ? true : _MyConnection.IsValidList(list)) && (_MyFormat == null ? true : _MyFormat.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_FolderAssignments == null || _FolderAssignments.IsValidList(list)) && (_FolderDocVersions == null || _FolderDocVersions.IsValidList(list)) && (_ChildFolders == null || _ChildFolders.IsValidList(list)) && (_MyConnection == null || _MyConnection.IsValidList(list)) && (_MyFormat == null || _MyFormat.IsValidList(list));
}
// CSLATODO: Replace base Folder.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Folder</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Folder.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Folder</returns>
protected override object GetIdValue()
{
return MyFolderUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyFolderUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -558,8 +529,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules?.BrokenRules);
}
}
protected override void AddBusinessRules()
@@ -604,43 +575,11 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(FolderID, "<Role(s)>");
//AuthorizationRules.AllowRead(ParentID, "<Role(s)>");
//AuthorizationRules.AllowRead(DBID, "<Role(s)>");
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
//AuthorizationRules.AllowRead(Title, "<Role(s)>");
//AuthorizationRules.AllowRead(ShortName, "<Role(s)>");
//AuthorizationRules.AllowRead(FormatID, "<Role(s)>");
//AuthorizationRules.AllowRead(ManualOrder, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ParentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DBID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
//AuthorizationRules.AllowWrite(Title, "<Role(s)>");
//AuthorizationRules.AllowWrite(ShortName, "<Role(s)>");
//AuthorizationRules.AllowWrite(FormatID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ManualOrder, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
_FolderExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -648,57 +587,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_FolderExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
/// <summary>
/// determines if related records (Foreign Keys) will keep this Item from being deleted
/// </summary>
public bool CanDelete
{
get
{
// Check to make sure that there are not any related records
int usedByCount = 0;
usedByCount += _FolderAssignmentCount;
usedByCount += _FolderDocVersionCount;
usedByCount += _ChildFolderCount;
return (usedByCount == 0);
}
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _FolderUnique = 0;
protected static int FolderUnique
{ get { return ++_FolderUnique; } }
private int _MyFolderUnique = FolderUnique;
public int MyFolderUnique // Absolutely Unique ID - Editable
{ get { return _MyFolderUnique; } }
protected static int FolderUnique => ++_FolderUnique;
private readonly int _MyFolderUnique = FolderUnique;
// Absolutely Unique ID - Editable
public int MyFolderUnique => _MyFolderUnique;
protected Folder()
{/* require use of factory methods */
AddToCache(this);
@@ -707,15 +603,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Folder()
{
_CountFinalized++;
@@ -752,8 +644,6 @@ namespace VEPROMS.CSLA.Library
}
public static Folder New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Folder");
try
{
return DataPortal.Create<Folder>();
@@ -860,8 +750,6 @@ namespace VEPROMS.CSLA.Library
}
public static Folder Get(int folderID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Folder");
try
{
Folder tmp = GetCachedByPrimaryKey(folderID);
@@ -884,8 +772,6 @@ namespace VEPROMS.CSLA.Library
}
public static Folder GetByParentID_Name(int parentID, string name)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Folder");
try
{
Folder tmp = GetCachedByParentID_Name(parentID, name);
@@ -911,15 +797,14 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Folder(dr, parent);
return null;
}
internal Folder(SafeDataReader dr)
{
ReadData(dr);
}
internal Folder(SafeDataReader dr) => ReadData(dr);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
private Folder(SafeDataReader dr, Folder parent)
{
ReadData(dr);
MarkAsChild();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal Folder(SafeDataReader dr, int parentID)
{
ReadData(dr);
@@ -927,8 +812,6 @@ namespace VEPROMS.CSLA.Library
}
public static void Delete(int folderID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Folder");
try
{
// B2019-060: On delete, remove the folder from cache:
@@ -943,12 +826,6 @@ namespace VEPROMS.CSLA.Library
}
public override Folder Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Folder");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Folder");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Folder");
try
{
BuildRefreshList();
@@ -968,23 +845,17 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _FolderID;
public int FolderID
{ get { return _FolderID; } }
public PKCriteria(int folderID)
{
_FolderID = folderID;
}
private readonly int _FolderID;
public int FolderID => _FolderID;
public PKCriteria(int folderID) => _FolderID = folderID;
}
[Serializable()]
private class ParentID_NameCriteria
{
private int _ParentID;
public int ParentID
{ get { return _ParentID; } }
private string _Name;
public string Name
{ get { return _Name; } }
private readonly int _ParentID;
public int ParentID => _ParentID;
private readonly string _Name;
public string Name => _Name;
public ParentID_NameCriteria(int parentID, string name)
{
_ParentID = parentID;
@@ -1112,7 +983,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Folder.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -1137,49 +1008,57 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyConnection != null) _MyConnection.Update();
if (_MyFormat != null) _MyFormat.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyConnection?.Update();
_MyFormat?.Update();
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addFolder";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ParentID", ParentID);
cm.Parameters.AddWithValue("@DBID", DBID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Title", _Title);
cm.Parameters.AddWithValue("@ShortName", _ShortName);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@ManualOrder", _ManualOrder);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
// Output Calculated Columns
SqlParameter param_FolderID = new SqlParameter("@newFolderID", SqlDbType.Int);
param_FolderID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_FolderID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_FolderID = (int)cm.Parameters["@newFolderID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addFolder";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ParentID", ParentID);
cm.Parameters.AddWithValue("@DBID", DBID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Title", _Title);
cm.Parameters.AddWithValue("@ShortName", _ShortName);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@ManualOrder", _ManualOrder);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
// Output Calculated Columns
SqlParameter param_FolderID = new SqlParameter("@newFolderID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_FolderID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_FolderID = (int)cm.Parameters["@newFolderID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_FolderAssignments != null) _FolderAssignments.Update(this);
if (_FolderDocVersions != null) _FolderDocVersions.Update(this);
if (_ChildFolders != null) _ChildFolders.Update(this);
_FolderAssignments?.Update(this);
_FolderDocVersions?.Update(this);
_ChildFolders?.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.SQLInsert", GetHashCode());
}
catch (Exception ex)
@@ -1189,7 +1068,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Folder.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int folderID, Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.Add", 0);
@@ -1212,11 +1091,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UsrID", usrID);
// Output Calculated Columns
SqlParameter param_FolderID = new SqlParameter("@newFolderID", SqlDbType.Int);
param_FolderID.Direction = ParameterDirection.Output;
SqlParameter param_FolderID = new SqlParameter("@newFolderID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_FolderID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -1231,7 +1114,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Folder.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -1256,51 +1139,57 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.SQLUpdate", GetHashCode());
try
{
if (_MyConnection != null) _MyConnection.Update();
if (_MyFormat != null) _MyFormat.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyConnection?.Update();
_MyFormat?.Update();
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateFolder";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@FolderID", _FolderID);
cm.Parameters.AddWithValue("@ParentID", ParentID);
cm.Parameters.AddWithValue("@DBID", DBID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Title", _Title);
cm.Parameters.AddWithValue("@ShortName", _ShortName);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@ManualOrder", _ManualOrder);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateFolder";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@FolderID", _FolderID);
cm.Parameters.AddWithValue("@ParentID", ParentID);
cm.Parameters.AddWithValue("@DBID", DBID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Title", _Title);
cm.Parameters.AddWithValue("@ShortName", _ShortName);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@ManualOrder", _ManualOrder);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
if (_FolderAssignments != null) _FolderAssignments.Update(this);
if (_FolderDocVersions != null) _FolderDocVersions.Update(this);
if (_ChildFolders != null) _ChildFolders.Update(this);
_FolderAssignments?.Update(this);
_FolderDocVersions?.Update(this);
_ChildFolders?.Update(this);
}
catch (Exception ex)
{
@@ -1313,31 +1202,40 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Folder.Add(cn, ref _FolderID, _MyParent, _MyConnection, _Name, _Title, _ShortName, _MyFormat, _ManualOrder, _Config, _DTS, _UsrID);
else
_LastChanged = Folder.Update(cn, ref _FolderID, _ParentID, _DBID, _Name, _Title, _ShortName, _FormatID, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = Folder.Add(cn, ref _FolderID, _MyParent, _MyConnection, _Name, _Title, _ShortName, _MyFormat, _ManualOrder, _Config, _DTS, _UsrID);
else
_LastChanged = Folder.Update(cn, ref _FolderID, _ParentID, _DBID, _Name, _Title, _ShortName, _FormatID, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged);
}
MarkOld();
}
if (_FolderAssignments != null) _FolderAssignments.Update(this);
if (_FolderDocVersions != null) _FolderDocVersions.Update(this);
if (_ChildFolders != null) _ChildFolders.Update(this);
_FolderAssignments?.Update(this);
_FolderDocVersions?.Update(this);
_ChildFolders?.Update(this);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Folder folder)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Folder.Remove(cn, _FolderID);
if (IsNew) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Folder.Remove(cn, _FolderID);
}
MarkNew();
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int folderID, int parentID, int dbid, string name, string title, string shortName, int? formatID, double? manualOrder, string config, DateTime dts, string usrID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.Update", 0);
@@ -1362,8 +1260,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UsrID", usrID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -1377,12 +1277,9 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Folder.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_FolderID));
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_FolderID));
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Delete", GetHashCode());
@@ -1407,7 +1304,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Folder.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int folderID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.Remove", 0);
@@ -1431,7 +1328,7 @@ namespace VEPROMS.CSLA.Library
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void DeleteFolderAdmin(int folderID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.Remove", 0);
@@ -1473,16 +1370,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _FolderID;
private readonly int _FolderID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int folderID)
{
_FolderID = folderID;
}
public bool Exists => _exists;
public ExistsCommand(int folderID) => _FolderID = folderID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Execute", GetHashCode());
@@ -1490,7 +1381,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -1512,7 +1403,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
FolderExtension _FolderExtension = new FolderExtension();
readonly FolderExtension _FolderExtension = new FolderExtension();
[Serializable()]
partial class FolderExtension : extensionBase
{
@@ -1521,22 +1412,10 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultParentID
{
get { return 1; }
}
public virtual int DefaultDBID
{
get { return 1; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUsrID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultParentID => 1;
public virtual int DefaultDBID => 1;
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUsrID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1565,65 +1444,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Folder)
if (destType == typeof(string) && value is Folder folder)
{
// Return the ToString value
return ((Folder)value).ToString();
return folder.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create FolderExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Folder
// {
// partial class FolderExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultParentID
// {
// get { return 1; }
// }
// public virtual int DefaultDBID
// {
// get { return 1; }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUsrID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _AID;
[System.ComponentModel.DataObjectField(true, true)]
public int AID
@@ -298,19 +292,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current FolderAssignment</returns>
protected override object GetIdValue()
{
return MyFolderAssignmentUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base FolderAssignment.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current FolderAssignment</returns>
//public override string ToString()
//{
// return base.ToString();
//}
protected override object GetIdValue() => MyFolderAssignmentUnique; // Absolutely Unique ID
public override bool IsDirty
{
get
@@ -325,18 +307,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirtyList(list)) || (_MyRole == null ? false : _MyRole.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyGroup != null && _MyGroup.IsDirtyList(list)) || (_MyRole != null && _MyRole.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValidList(list)) && (_MyRole == null ? true : _MyRole.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyGroup == null || _MyGroup.IsValidList(list)) && (_MyRole == null || _MyRole.IsValidList(list));
}
#endregion
#region ValidationRules
@@ -367,8 +346,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -430,80 +409,21 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AID, "<Role(s)>");
//AuthorizationRules.AllowRead(GID, "<Role(s)>");
//AuthorizationRules.AllowWrite(GID, "<Role(s)>");
//AuthorizationRules.AllowRead(RID, "<Role(s)>");
//AuthorizationRules.AllowWrite(RID, "<Role(s)>");
//AuthorizationRules.AllowRead(StartDate, "<Role(s)>");
//AuthorizationRules.AllowWrite(StartDate, "<Role(s)>");
//AuthorizationRules.AllowRead(EndDate, "<Role(s)>");
//AuthorizationRules.AllowWrite(EndDate, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _FolderAssignmentUnique = 0;
private static int FolderAssignmentUnique
{ get { return ++_FolderAssignmentUnique; } }
private int _MyFolderAssignmentUnique = FolderAssignmentUnique;
public int MyFolderAssignmentUnique // Absolutely Unique ID - Editable FK
{ get { return _MyFolderAssignmentUnique; } }
internal static FolderAssignment New(Group myGroup, Role myRole)
{
return new FolderAssignment(myGroup, myRole);
}
internal static FolderAssignment Get(SafeDataReader dr)
{
return new FolderAssignment(dr);
}
private static int FolderAssignmentUnique => ++_FolderAssignmentUnique;
private readonly int _MyFolderAssignmentUnique = FolderAssignmentUnique;
// Absolutely Unique ID - Editable FK
public int MyFolderAssignmentUnique => _MyFolderAssignmentUnique;
internal static FolderAssignment New(Group myGroup, Role myRole) => new FolderAssignment(myGroup, myRole);
internal static FolderAssignment Get(SafeDataReader dr) => new FolderAssignment(dr);
public FolderAssignment()
{
MarkAsChild();
@@ -534,15 +454,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FolderAssignment()
{
_CountFinalized++;
@@ -588,33 +504,46 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Folder myFolder)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Assignment.Add(cn, ref _AID, _MyGroup, _MyRole, myFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Assignment.Add(cn, ref _AID, _MyGroup, _MyRole, myFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID);
}
MarkOld();
}
internal void Update(Folder myFolder)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Assignment.Update(cn, ref _AID, _GID, _RID, myFolder.FolderID, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Assignment.Update(cn, ref _AID, _GID, _RID, myFolder.FolderID, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Folder myFolder)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Assignment.Remove(cn, _AID);
if (IsNew) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Assignment.Remove(cn, _AID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
FolderAssignmentExtension _FolderAssignmentExtension = new FolderAssignmentExtension();
readonly FolderAssignmentExtension _FolderAssignmentExtension = new FolderAssignmentExtension();
[Serializable()]
partial class FolderAssignmentExtension : extensionBase
{
@@ -623,18 +552,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual string DefaultStartDate
{
get { return DateTime.Now.ToShortDateString(); }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUsrID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual string DefaultStartDate => DateTime.Now.ToShortDateString();
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUsrID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -663,61 +583,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FolderAssignment)
if (destType == typeof(string) && value is FolderAssignment assignment)
{
// Return the ToString value
return ((FolderAssignment)value).ToString();
return assignment.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create FolderAssignmentExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class FolderAssignment
// {
// partial class FolderAssignmentExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual SmartDate DefaultStartDate
// {
// get { return DateTime.Now.ToShortDateString(); }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUsrID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public FolderAssignment this[Assignment myAssignment]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public FolderAssignment this[Assignment myAssignment]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<FolderAssignment> Items
{
get { return base.Items; }
}
public FolderAssignment GetItem(Assignment myAssignment)
public new System.Collections.Generic.IList<FolderAssignment> Items => base.Items;
public FolderAssignment GetItem(Assignment myAssignment)
{
foreach (FolderAssignment assignment in this)
if (assignment.AID == myAssignment.AID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public FolderAssignment Add(Group myGroup, Role myRole) // One to Many
{
FolderAssignment assignment = FolderAssignment.New(myGroup, myRole);
this.Add(assignment);
Add(assignment);
return assignment;
}
public void Remove(Assignment myAssignment)
@@ -103,11 +95,8 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
@@ -137,7 +126,7 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
@@ -161,11 +150,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on FolderAssignments.GetByFolderID", ex);
}
}
private FolderAssignments()
{
MarkAsChild();
}
internal FolderAssignments(SafeDataReader dr)
private FolderAssignments() => MarkAsChild();
internal FolderAssignments(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +160,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~FolderAssignments()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FolderAssignments()
{
_CountFinalized++;
}
@@ -198,10 +180,10 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(FolderAssignment.Get(dr));
this.RaiseListChangedEvents = true;
Add(FolderAssignment.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class FolderIDCriteria
@@ -219,7 +201,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(FolderIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderAssignments.DataPortal_FetchFolderID", GetHashCode());
try
{
@@ -233,7 +215,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new FolderAssignment(dr));
while (dr.Read()) Add(new FolderAssignment(dr));
}
}
}
@@ -243,11 +225,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderAssignments.DataPortal_FetchFolderID", ex);
throw new DbCslaException("FolderAssignments.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Folder folder)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +248,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public String GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
FolderAssignmentsPropertyDescriptor pd = new FolderAssignmentsPropertyDescriptor(this, i);
@@ -325,7 +296,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class FolderAssignmentsPropertyDescriptor : vlnListPropertyDescriptor
{
private FolderAssignment Item { get { return (FolderAssignment)_Item; } }
public FolderAssignmentsPropertyDescriptor(FolderAssignments collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +304,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FolderAssignments)
if (destType == typeof(string) && value is FolderAssignments assignments)
{
// Return department and department role separated by comma.
return ((FolderAssignments)value).Items.Count.ToString() + " Assignments";
return $"{assignments.Items.Count} Assignments";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _VersionID;
[System.ComponentModel.DataObjectField(true, true)]
public int VersionID
@@ -239,35 +233,13 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current FolderDocVersion</returns>
protected override object GetIdValue()
{
return MyFolderDocVersionUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base FolderDocVersion.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current FolderDocVersion</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty
{
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
protected override object GetIdValue() => MyFolderDocVersionUnique; // Absolutely Unique ID
public override bool IsDirty => base.IsDirty;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsDirtyList(List<object> list) => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsValidList(List<object> list) => (IsNew && !IsDirty) || base.IsValid;
#endregion
#region ValidationRules
[NonSerialized]
@@ -297,8 +269,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -321,84 +293,22 @@ namespace VEPROMS.CSLA.Library
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100));
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(VersionID, "<Role(s)>");
//AuthorizationRules.AllowRead(VersionType, "<Role(s)>");
//AuthorizationRules.AllowWrite(VersionType, "<Role(s)>");
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
//AuthorizationRules.AllowRead(Title, "<Role(s)>");
//AuthorizationRules.AllowWrite(Title, "<Role(s)>");
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(FormatID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FormatID, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _FolderDocVersionUnique = 0;
private static int FolderDocVersionUnique
{ get { return ++_FolderDocVersionUnique; } }
private int _MyFolderDocVersionUnique = FolderDocVersionUnique;
public int MyFolderDocVersionUnique // Absolutely Unique ID - Editable FK
{ get { return _MyFolderDocVersionUnique; } }
internal static FolderDocVersion New(string name)
{
return new FolderDocVersion(name);
}
internal static FolderDocVersion Get(SafeDataReader dr)
{
return new FolderDocVersion(dr);
}
private static int FolderDocVersionUnique => ++_FolderDocVersionUnique;
private readonly int _MyFolderDocVersionUnique = FolderDocVersionUnique;
// Absolutely Unique ID - Editable FK
public int MyFolderDocVersionUnique => _MyFolderDocVersionUnique;
internal static FolderDocVersion New(string name) => new FolderDocVersion(name);
internal static FolderDocVersion Get(SafeDataReader dr) => new FolderDocVersion(dr);
public FolderDocVersion()
{
MarkAsChild();
@@ -428,15 +338,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FolderDocVersion()
{
_CountFinalized++;
@@ -475,33 +381,46 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Folder myFolder)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = DocVersion.Add(cn, ref _VersionID, myFolder, _VersionType, _Name, _Title, _MyItem, _MyFormat, _Config, _DTS, _UserID);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = DocVersion.Add(cn, ref _VersionID, myFolder, _VersionType, _Name, _Title, _MyItem, _MyFormat, _Config, _DTS, _UserID);
}
MarkOld();
}
internal void Update(Folder myFolder)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = DocVersion.Update(cn, ref _VersionID, myFolder.FolderID, _VersionType, _Name, _Title, _ItemID, _FormatID, _Config, _DTS, _UserID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = DocVersion.Update(cn, ref _VersionID, myFolder.FolderID, _VersionType, _Name, _Title, _ItemID, _FormatID, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Folder myFolder)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
DocVersion.Remove(cn, _VersionID);
if (IsNew) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
DocVersion.Remove(cn, _VersionID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
FolderDocVersionExtension _FolderDocVersionExtension = new FolderDocVersionExtension();
readonly FolderDocVersionExtension _FolderDocVersionExtension = new FolderDocVersionExtension();
[Serializable()]
partial class FolderDocVersionExtension : extensionBase
{
@@ -510,18 +429,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultVersionType
{
get { return 0; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultVersionType => 0;
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -550,61 +460,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FolderDocVersion)
if (destType == typeof(string) && value is FolderDocVersion version)
{
// Return the ToString value
return ((FolderDocVersion)value).ToString();
return version.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create FolderDocVersionExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class FolderDocVersion
// {
// partial class FolderDocVersionExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultVersionType
// {
// get { return 0; }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public FolderDocVersion this[DocVersion myDocVersion]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public FolderDocVersion this[DocVersion myDocVersion]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<FolderDocVersion> Items
{
get { return base.Items; }
}
public FolderDocVersion GetItem(DocVersion myDocVersion)
public new System.Collections.Generic.IList<FolderDocVersion> Items => base.Items;
public FolderDocVersion GetItem(DocVersion myDocVersion)
{
foreach (FolderDocVersion docVersion in this)
if (docVersion.VersionID == myDocVersion.VersionID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public FolderDocVersion Add(string name) // One to Many
{
FolderDocVersion docVersion = FolderDocVersion.New(name);
this.Add(docVersion);
Add(docVersion);
return docVersion;
}
public void Remove(DocVersion myDocVersion)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (FolderDocVersion child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (FolderDocVersion child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static FolderDocVersions New()
{
return new FolderDocVersions();
}
internal static FolderDocVersions Get(SafeDataReader dr)
{
return new FolderDocVersions(dr);
}
public static FolderDocVersions GetByFolderID(int folderID)
#endregion
#region Factory Methods
internal static FolderDocVersions New() => new FolderDocVersions();
internal static FolderDocVersions Get(SafeDataReader dr) => new FolderDocVersions(dr);
public static FolderDocVersions GetByFolderID(int folderID)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on FolderDocVersions.GetByFolderID", ex);
}
}
private FolderDocVersions()
{
MarkAsChild();
}
internal FolderDocVersions(SafeDataReader dr)
private FolderDocVersions() => MarkAsChild();
internal FolderDocVersions(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~FolderDocVersions()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FolderDocVersions()
{
_CountFinalized++;
}
@@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(FolderDocVersion.Get(dr));
this.RaiseListChangedEvents = true;
Add(FolderDocVersion.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class FolderIDCriteria
{
public FolderIDCriteria(int folderID)
{
_FolderID = folderID;
}
private int _FolderID;
public FolderIDCriteria(int folderID) => _FolderID = folderID;
private int _FolderID;
public int FolderID
{
get { return _FolderID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(FolderIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderDocVersions.DataPortal_FetchFolderID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new FolderDocVersion(dr));
while (dr.Read()) Add(new FolderDocVersion(dr));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderDocVersions.DataPortal_FetchFolderID", ex);
throw new DbCslaException("FolderDocVersions.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Folder folder)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
FolderDocVersionsPropertyDescriptor pd = new FolderDocVersionsPropertyDescriptor(this, i);
@@ -334,10 +296,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FolderDocVersions)
if (destType == typeof(string) && value is FolderDocVersions versions)
{
// Return department and department role separated by comma.
return ((FolderDocVersions)value).Items.Count.ToString() + " DocVersions";
return $"{versions.Items.Count} DocVersions";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class FolderInfo : ReadOnlyBase<FolderInfo>, IDisposable
{
public event FolderInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<FolderInfo> _CacheList = new List<FolderInfo>();
protected static void AddToCache(FolderInfo folderInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(folderInfo)) _CacheList.Remove(folderInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<FolderInfo>> _CacheByPrimaryKey = new Dictionary<string, List<FolderInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Folder _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _FolderID;
[System.ComponentModel.DataObjectField(true, true)]
public int FolderID
@@ -330,32 +314,19 @@ namespace VEPROMS.CSLA.Library
foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()])
tmp._ChildFolderCount = -1; // This will cause the data to be requeried
}
// CSLATODO: Replace base FolderInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current FolderInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check FolderInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current FolderInfo</returns>
protected override object GetIdValue()
{
return MyFolderInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyFolderInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _FolderInfoUnique = 0;
private static int FolderInfoUnique
{ get { return ++_FolderInfoUnique; } }
private int _MyFolderInfoUnique = FolderInfoUnique;
public int MyFolderInfoUnique // Absolutely Unique ID - Info
{ get { return _MyFolderInfoUnique; } }
private static int FolderInfoUnique => ++_FolderInfoUnique;
private readonly int _MyFolderInfoUnique = FolderInfoUnique;
// Absolutely Unique ID - Info
public int MyFolderInfoUnique => _MyFolderInfoUnique;
protected FolderInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -364,15 +335,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FolderInfo()
{
_CountFinalized++;
@@ -389,10 +356,7 @@ namespace VEPROMS.CSLA.Library
if (listFolderInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(FolderID.ToString()); // remove the list
}
public virtual Folder Get()
{
return _Editable = Folder.Get(_FolderID);
}
public virtual Folder Get() => _Editable = Folder.Get(_FolderID);
public static void Refresh(Folder tmp)
{
string key = tmp.FolderID.ToString();
@@ -405,28 +369,28 @@ namespace VEPROMS.CSLA.Library
{
if (_ParentID != tmp.ParentID)
{
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for old value
MyParent?.RefreshChildFolders(); // Update List for old value
_ParentID = tmp.ParentID; // Update the value
}
_MyParent = null; // Reset list so that the next line gets a new list
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for new value
MyParent?.RefreshChildFolders(); // Update List for new value
if (_DBID != tmp.DBID)
{
if (MyConnection != null) MyConnection.RefreshConnectionFolders(); // Update List for old value
MyConnection?.RefreshConnectionFolders(); // Update List for old value
_DBID = tmp.DBID; // Update the value
}
_MyConnection = null; // Reset list so that the next line gets a new list
if (MyConnection != null) MyConnection.RefreshConnectionFolders(); // Update List for new value
MyConnection?.RefreshConnectionFolders(); // Update List for new value
_Name = tmp.Name;
_Title = tmp.Title;
_ShortName = tmp.ShortName;
if (_FormatID != tmp.FormatID)
{
if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for old value
MyFormat?.RefreshFormatFolders(); // Update List for old value
_FormatID = tmp.FormatID; // Update the value
}
_MyFormat = null; // Reset list so that the next line gets a new list
if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for new value
MyFormat?.RefreshFormatFolders(); // Update List for new value
_ManualOrder = tmp.ManualOrder;
_Config = tmp.Config;
_DTS = tmp.DTS;
@@ -446,21 +410,21 @@ namespace VEPROMS.CSLA.Library
{
if (_ParentID != tmp.ParentID)
{
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for old value
MyParent?.RefreshChildFolders(); // Update List for old value
_ParentID = tmp.ParentID; // Update the value
}
_MyParent = null; // Reset list so that the next line gets a new list
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for new value
MyParent?.RefreshChildFolders(); // Update List for new value
_Name = tmp.Name;
_Title = tmp.Title;
_ShortName = tmp.ShortName;
if (_FormatID != tmp.FormatID)
{
if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for old value
MyFormat?.RefreshFormatFolders(); // Update List for old value
_FormatID = tmp.FormatID; // Update the value
}
_MyFormat = null; // Reset list so that the next line gets a new list
if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for new value
MyFormat?.RefreshFormatFolders(); // Update List for new value
_ManualOrder = tmp.ManualOrder;
_Config = tmp.Config;
_DTS = tmp.DTS;
@@ -480,18 +444,18 @@ namespace VEPROMS.CSLA.Library
{
if (_ParentID != tmp.ParentID)
{
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for old value
MyParent?.RefreshChildFolders(); // Update List for old value
_ParentID = tmp.ParentID; // Update the value
}
_MyParent = null; // Reset list so that the next line gets a new list
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for new value
MyParent?.RefreshChildFolders(); // Update List for new value
if (_DBID != tmp.DBID)
{
if (MyConnection != null) MyConnection.RefreshConnectionFolders(); // Update List for old value
MyConnection?.RefreshConnectionFolders(); // Update List for old value
_DBID = tmp.DBID; // Update the value
}
_MyConnection = null; // Reset list so that the next line gets a new list
if (MyConnection != null) MyConnection.RefreshConnectionFolders(); // Update List for new value
MyConnection?.RefreshConnectionFolders(); // Update List for new value
_Name = tmp.Name;
_Title = tmp.Title;
_ShortName = tmp.ShortName;
@@ -513,8 +477,6 @@ namespace VEPROMS.CSLA.Library
public static FolderInfo Get(int folderID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Folder");
try
{
FolderInfo tmp = GetCachedByPrimaryKey(folderID);
@@ -553,13 +515,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _FolderID;
public int FolderID
{ get { return _FolderID; } }
public PKCriteria(int folderID)
{
_FolderID = folderID;
}
private readonly int _FolderID;
public int FolderID => _FolderID;
public PKCriteria(int folderID) => _FolderID = folderID;
}
private void ReadData(SafeDataReader dr)
{
@@ -627,7 +585,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
FolderInfoExtension _FolderInfoExtension = new FolderInfoExtension();
readonly FolderInfoExtension _FolderInfoExtension = new FolderInfoExtension();
[Serializable()]
partial class FolderInfoExtension : extensionBase { }
[Serializable()]
@@ -643,10 +601,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FolderInfo)
if (destType == typeof(string) && value is FolderInfo info)
{
// Return the ToString value
return ((FolderInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<FolderInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<FolderInfo> Items => base.Items;
public void AddEvents()
{
foreach (FolderInfo tmp in this)
{
@@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~FolderInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FolderInfoList()
{
_CountFinalized++;
}
@@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on FolderInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all FolderInfo.
/// </summary>
public static void Reset()
{
_FolderInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static FolderInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<FolderInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on FolderInfoList.Get", ex);
// }
//}
public static FolderInfoList GetChildren(int parentID)
/// <summary>
/// Reset the list of all FolderInfo.
/// </summary>
public static void Reset() => _FolderInfoList = null;
public static FolderInfoList GetChildren(int parentID)
{
try
{
@@ -194,11 +172,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ParentIDCriteria
{
public ParentIDCriteria(int parentID)
{
_ParentID = parentID;
}
private int _ParentID;
public ParentIDCriteria(int parentID) => _ParentID = parentID;
private int _ParentID;
public int ParentID
{
get { return _ParentID; }
@@ -238,11 +213,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class DBIDCriteria
{
public DBIDCriteria(int dbid)
{
_DBID = dbid;
}
private int _DBID;
public DBIDCriteria(int dbid) => _DBID = dbid;
private int _DBID;
public int DBID
{
get { return _DBID; }
@@ -282,11 +254,8 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class FormatIDCriteria
{
public FormatIDCriteria(int? formatID)
{
_FormatID = formatID;
}
private int? _FormatID;
public FormatIDCriteria(int? formatID) => _FormatID = formatID;
private int? _FormatID;
public int? FormatID
{
get { return _FormatID; }
@@ -323,41 +292,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -379,7 +337,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class FolderInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private FolderInfo Item { get { return (FolderInfo)_Item; } }
public FolderInfoListPropertyDescriptor(FolderInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -388,10 +345,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FolderInfoList)
if (destType == typeof(string) && value is FolderInfoList list)
{
// Return department and department role separated by comma.
return ((FolderInfoList)value).Items.Count.ToString() + " Folders";
return $"{list.Items.Count} Folders";
}
return base.ConvertTo(context, culture, value, destType);
}
+163 -323
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -102,6 +100,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Format> _CacheList = new List<Format>();
protected static void AddToCache(Format format)
{
@@ -111,7 +110,9 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(format)) _CacheList.Remove(format); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Format>> _CacheByPrimaryKey = new Dictionary<string, List<Format>>();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Format>> _CacheByParentID_Name = new Dictionary<string, List<Format>>();
private static void ConvertListToDictionary()
{
@@ -154,15 +155,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextFormatID = -1;
public static int NextFormatID
{
get { return _nextFormatID--; }
}
public static int NextFormatID => _nextFormatID--;
private int _FormatID;
[System.ComponentModel.DataObjectField(true, true)]
public int FormatID
@@ -367,10 +362,7 @@ namespace VEPROMS.CSLA.Library
return _FormatContents;
}
}
public void Reset_FormatContents()
{
_FormatContentCount = -1;
}
public void Reset_FormatContents() => _FormatContentCount = -1;
private int _FormatDocVersionCount = 0;
/// <summary>
/// Count of FormatDocVersions for this Format
@@ -402,10 +394,7 @@ namespace VEPROMS.CSLA.Library
return _FormatDocVersions;
}
}
public void Reset_FormatDocVersions()
{
_FormatDocVersionCount = -1;
}
public void Reset_FormatDocVersions() => _FormatDocVersionCount = -1;
private int _FormatFolderCount = 0;
/// <summary>
/// Count of FormatFolders for this Format
@@ -472,10 +461,7 @@ namespace VEPROMS.CSLA.Library
return _ChildFormats;
}
}
public void Reset_ChildFormats()
{
_ChildFormatCount = -1;
}
public void Reset_ChildFormats() => _ChildFormatCount = -1;
public override bool IsDirty
{
get
@@ -490,37 +476,22 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_FormatContents == null ? false : _FormatContents.IsDirtyList(list)) || (_FormatDocVersions == null ? false : _FormatDocVersions.IsDirtyList(list)) || (_FormatFolders == null ? false : _FormatFolders.IsDirtyList(list)) || (_ChildFormats == null ? false : _ChildFormats.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_FormatContents != null && _FormatContents.IsDirtyList(list)) || (_FormatDocVersions != null && _FormatDocVersions.IsDirtyList(list)) || (_FormatFolders != null && _FormatFolders.IsDirtyList(list)) || (_ChildFormats != null && _ChildFormats.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_FormatContents == null ? true : _FormatContents.IsValidList(list)) && (_FormatDocVersions == null ? true : _FormatDocVersions.IsValidList(list)) && (_FormatFolders == null ? true : _FormatFolders.IsValidList(list)) && (_ChildFormats == null ? true : _ChildFormats.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_FormatContents == null || _FormatContents.IsValidList(list)) && (_FormatDocVersions == null || _FormatDocVersions.IsValidList(list)) && (_FormatFolders == null || _FormatFolders.IsValidList(list)) && (_ChildFormats == null || _ChildFormats.IsValidList(list));
}
// CSLATODO: Replace base Format.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Format</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Format.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Format</returns>
protected override object GetIdValue()
{
return MyFormatUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyFormatUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -552,8 +523,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -566,8 +537,6 @@ namespace VEPROMS.CSLA.Library
ValidationRules.AddRule(
Csla.Validation.CommonRules.StringMaxLength,
new Csla.Validation.CommonRules.MaxLengthRuleArgs("Description", 250));
//ValidationRules.AddRule(
// Csla.Validation.CommonRules.StringRequired, "Data");
ValidationRules.AddRule(
Csla.Validation.CommonRules.StringMaxLength,
new Csla.Validation.CommonRules.MaxLengthRuleArgs("Data", 1073741823));
@@ -591,37 +560,11 @@ namespace VEPROMS.CSLA.Library
_FormatExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(FormatID, "<Role(s)>");
//AuthorizationRules.AllowRead(ParentID, "<Role(s)>");
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
//AuthorizationRules.AllowRead(Description, "<Role(s)>");
//AuthorizationRules.AllowRead(Data, "<Role(s)>");
//AuthorizationRules.AllowRead(GenMac, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ParentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
//AuthorizationRules.AllowWrite(Description, "<Role(s)>");
//AuthorizationRules.AllowWrite(Data, "<Role(s)>");
//AuthorizationRules.AllowWrite(GenMac, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_FormatExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -629,58 +572,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_FormatExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
/// <summary>
/// determines if related records (Foreign Keys) will keep this Item from being deleted
/// </summary>
public bool CanDelete
{
get
{
// Check to make sure that there are not any related records
int usedByCount = 0;
usedByCount += _FormatContentCount;
usedByCount += _FormatDocVersionCount;
usedByCount += _FormatFolderCount;
usedByCount += _ChildFormatCount;
return (usedByCount == 0);
}
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _FormatUnique = 0;
protected static int FormatUnique
{ get { return ++_FormatUnique; } }
private int _MyFormatUnique = FormatUnique;
public int MyFormatUnique // Absolutely Unique ID - Editable
{ get { return _MyFormatUnique; } }
protected static int FormatUnique => ++_FormatUnique;
private readonly int _MyFormatUnique = FormatUnique;
// Absolutely Unique ID - Editable
public int MyFormatUnique => _MyFormatUnique;
protected Format()
{/* require use of factory methods */
AddToCache(this);
@@ -689,15 +588,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Format()
{
_CountFinalized++;
@@ -734,8 +629,6 @@ namespace VEPROMS.CSLA.Library
}
public static Format New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Format");
try
{
return DataPortal.Create<Format>();
@@ -811,8 +704,6 @@ namespace VEPROMS.CSLA.Library
}
public static Format Get(int formatID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Format");
try
{
Format tmp = GetCachedByPrimaryKey(formatID);
@@ -835,8 +726,6 @@ namespace VEPROMS.CSLA.Library
}
public static Format GetByParentID_Name(int parentID, string name)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Format");
try
{
Format tmp = GetCachedByParentID_Name(parentID, name);
@@ -862,15 +751,14 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Format(dr, parent);
return null;
}
internal Format(SafeDataReader dr)
{
ReadData(dr);
}
internal Format(SafeDataReader dr) => ReadData(dr);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
private Format(SafeDataReader dr, Format parent)
{
ReadData(dr);
MarkAsChild();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal Format(SafeDataReader dr, int parentID)
{
ReadData(dr);
@@ -878,8 +766,6 @@ namespace VEPROMS.CSLA.Library
}
public static void Delete(int formatID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Format");
try
{
DataPortal.Delete(new PKCriteria(formatID));
@@ -891,12 +777,6 @@ namespace VEPROMS.CSLA.Library
}
public override Format Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Format");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Format");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Format");
try
{
BuildRefreshList();
@@ -916,23 +796,17 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _FormatID;
public int FormatID
{ get { return _FormatID; } }
public PKCriteria(int formatID)
{
_FormatID = formatID;
}
private readonly int _FormatID;
public int FormatID => _FormatID;
public PKCriteria(int formatID) => _FormatID = formatID;
}
[Serializable()]
private class ParentID_NameCriteria
{
private int _ParentID;
public int ParentID
{ get { return _ParentID; } }
private string _Name;
public string Name
{ get { return _Name; } }
private readonly int _ParentID;
public int ParentID => _ParentID;
private readonly string _Name;
public string Name => _Name;
public ParentID_NameCriteria(int parentID, string name)
{
_ParentID = parentID;
@@ -1076,7 +950,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Format.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -1101,46 +975,54 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addFormat";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ParentID", ParentID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Description", _Description);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
cm.Parameters.AddWithValue("@GenMac", _GenMac);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_FormatID = new SqlParameter("@newFormatID", SqlDbType.Int);
param_FormatID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_FormatID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_FormatID = (int)cm.Parameters["@newFormatID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addFormat";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ParentID", ParentID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Description", _Description);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
cm.Parameters.AddWithValue("@GenMac", _GenMac);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_FormatID = new SqlParameter("@newFormatID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_FormatID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_FormatID = (int)cm.Parameters["@newFormatID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_FormatFolders != null) _FormatFolders.Update(this);
if (_FormatContents != null) _FormatContents.Update(this);
if (_FormatDocVersions != null) _FormatDocVersions.Update(this);
if (_ChildFormats != null) _ChildFormats.Update(this);
_FormatFolders?.Update(this);
_FormatContents?.Update(this);
_FormatDocVersions?.Update(this);
_ChildFormats?.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.SQLInsert", GetHashCode());
}
catch (Exception ex)
@@ -1150,7 +1032,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Format.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int formatID, Format myParent, string name, string description, string data, string config, string genMac, DateTime dts, string userID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.Add", 0);
@@ -1171,11 +1053,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns
SqlParameter param_FormatID = new SqlParameter("@newFormatID", SqlDbType.Int);
param_FormatID.Direction = ParameterDirection.Output;
SqlParameter param_FormatID = new SqlParameter("@newFormatID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_FormatID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -1190,7 +1076,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Format.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -1213,48 +1099,54 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateFormat";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@FormatID", _FormatID);
cm.Parameters.AddWithValue("@ParentID", ParentID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Description", _Description);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
cm.Parameters.AddWithValue("@GenMac", _GenMac);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateFormat";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@FormatID", _FormatID);
cm.Parameters.AddWithValue("@ParentID", ParentID);
cm.Parameters.AddWithValue("@Name", _Name);
cm.Parameters.AddWithValue("@Description", _Description);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
cm.Parameters.AddWithValue("@GenMac", _GenMac);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
if (_FormatFolders != null) _FormatFolders.Update(this);
if (_FormatContents != null) _FormatContents.Update(this);
if (_FormatDocVersions != null) _FormatDocVersions.Update(this);
if (_ChildFormats != null) _ChildFormats.Update(this);
_FormatFolders?.Update(this);
_FormatContents?.Update(this);
_FormatDocVersions?.Update(this);
_ChildFormats?.Update(this);
}
catch (Exception ex)
{
@@ -1265,32 +1157,41 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Format.Add(cn, ref _FormatID, _MyParent, _Name, _Description, _Data, _Config, _GenMac, _DTS, _UserID);
else
_LastChanged = Format.Update(cn, ref _FormatID, _ParentID, _Name, _Description, _Data, _Config, _GenMac, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = Format.Add(cn, ref _FormatID, _MyParent, _Name, _Description, _Data, _Config, _GenMac, _DTS, _UserID);
else
_LastChanged = Format.Update(cn, ref _FormatID, _ParentID, _Name, _Description, _Data, _Config, _GenMac, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
if (_FormatFolders != null) _FormatFolders.Update(this);
if (_FormatContents != null) _FormatContents.Update(this);
if (_FormatDocVersions != null) _FormatDocVersions.Update(this);
if (_ChildFormats != null) _ChildFormats.Update(this);
_FormatFolders?.Update(this);
_FormatContents?.Update(this);
_FormatDocVersions?.Update(this);
_ChildFormats?.Update(this);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Format format)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Format.Remove(cn, _FormatID);
if (IsNew) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Format.Remove(cn, _FormatID);
}
MarkNew();
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int formatID, int parentID, string name, string description, string data, string config, string genMac, DateTime dts, string userID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.Update", 0);
@@ -1313,8 +1214,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -1328,12 +1231,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Format.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_FormatID));
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Delete", GetHashCode());
@@ -1358,7 +1261,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Format.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int formatID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.Remove", 0);
@@ -1399,16 +1302,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _FormatID;
private readonly int _FormatID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int formatID)
{
_FormatID = formatID;
}
public bool Exists => _exists;
public ExistsCommand(int formatID) => _FormatID = formatID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Execute", GetHashCode());
@@ -1416,7 +1313,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -1438,7 +1335,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
FormatExtension _FormatExtension = new FormatExtension();
readonly FormatExtension _FormatExtension = new FormatExtension();
[Serializable()]
partial class FormatExtension : extensionBase
{
@@ -1447,18 +1344,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultParentID
{
get { return 1; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultParentID => 1;
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1487,61 +1375,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Format)
if (destType == typeof(string) && value is Format format)
{
// Return the ToString value
return ((Format)value).ToString();
return format.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create FormatExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Format
// {
// partial class FormatExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultParentID
// {
// get { return 1; }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)]
public int ContentID
@@ -182,10 +176,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current FormatContent</returns>
protected override object GetIdValue()
{
return MyFormatContentUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyFormatContentUnique; // Absolutely Unique ID
// CSLATODO: Replace base FormatContent.ToString function as necessary
/// <summary>
/// Overrides Base ToString
@@ -195,22 +186,12 @@ namespace VEPROMS.CSLA.Library
//{
// return base.ToString();
//}
public override bool IsDirty
{
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
public override bool IsDirty => base.IsDirty;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsDirtyList(List<object> list) => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsValidList(List<object> list) => (IsNew && !IsDirty) || base.IsValid;
#endregion
#region ValidationRules
[NonSerialized]
@@ -239,7 +220,7 @@ namespace VEPROMS.CSLA.Library
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -260,80 +241,22 @@ namespace VEPROMS.CSLA.Library
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100));
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(Number, "<Role(s)>");
//AuthorizationRules.AllowWrite(Number, "<Role(s)>");
//AuthorizationRules.AllowRead(Text, "<Role(s)>");
//AuthorizationRules.AllowWrite(Text, "<Role(s)>");
//AuthorizationRules.AllowRead(Type, "<Role(s)>");
//AuthorizationRules.AllowWrite(Type, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _FormatContentUnique = 0;
private static int FormatContentUnique
{ get { return ++_FormatContentUnique; } }
private int _MyFormatContentUnique = FormatContentUnique;
public int MyFormatContentUnique // Absolutely Unique ID - Editable FK
{ get { return _MyFormatContentUnique; } }
internal static FormatContent New()
{
return new FormatContent();
}
internal static FormatContent Get(SafeDataReader dr)
{
return new FormatContent(dr);
}
private static int FormatContentUnique => ++_FormatContentUnique;
private readonly int _MyFormatContentUnique = FormatContentUnique;
// Absolutely Unique ID - Editable FK
public int MyFormatContentUnique => _MyFormatContentUnique;
internal static FormatContent New() => new FormatContent();
internal static FormatContent Get(SafeDataReader dr) => new FormatContent(dr);
public FormatContent()
{
MarkAsChild();
@@ -351,15 +274,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FormatContent()
{
_CountFinalized++;
@@ -397,32 +316,45 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Content.Add(cn, ref _ContentID, _Number, _Text, _Type, myFormat, _Config, _DTS, _UserID);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Content.Add(cn, ref _ContentID, _Number, _Text, _Type, myFormat, _Config, _DTS, _UserID);
}
MarkOld();
}
internal void Update(Format myFormat)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Content.Update(cn, ref _ContentID, _Number, _Text, _Type, myFormat != null ? (int?)myFormat.FormatID : (int?)null, _Config, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Content.Update(cn, ref _ContentID, _Number, _Text, _Type, myFormat != null ? (int?)myFormat.FormatID : (int?)null, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Format myFormat)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Content.Remove(cn, _ContentID);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Content.Remove(cn, _ContentID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
FormatContentExtension _FormatContentExtension = new FormatContentExtension();
readonly FormatContentExtension _FormatContentExtension = new FormatContentExtension();
[Serializable()]
partial class FormatContentExtension : extensionBase
{
@@ -431,14 +363,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -467,57 +393,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FormatContent)
if (destType == typeof(string) && value is FormatContent content)
{
// Return the ToString value
return ((FormatContent)value).ToString();
return content.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create FormatContentExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class FormatContent
// {
// partial class FormatContentExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public FormatContent this[Content myContent]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public FormatContent this[Content myContent]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<FormatContent> Items
{
get { return base.Items; }
}
public FormatContent GetItem(Content myContent)
public new System.Collections.Generic.IList<FormatContent> Items => base.Items;
public FormatContent GetItem(Content myContent)
{
foreach (FormatContent content in this)
if (content.ContentID == myContent.ContentID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public FormatContent Add() // One to Many
{
FormatContent content = FormatContent.New();
this.Add(content);
Add(content);
return content;
}
public void Remove(Content myContent)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (FormatContent child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (FormatContent child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static FormatContents New()
{
return new FormatContents();
}
internal static FormatContents Get(SafeDataReader dr)
{
return new FormatContents(dr);
}
public static FormatContents GetByFormatID(int formatID)
#endregion
#region Factory Methods
internal static FormatContents New() => new FormatContents();
internal static FormatContents Get(SafeDataReader dr) => new FormatContents(dr);
public static FormatContents GetByFormatID(int formatID)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on FormatContents.GetByFormatID", ex);
}
}
private FormatContents()
{
MarkAsChild();
}
internal FormatContents(SafeDataReader dr)
private FormatContents() => MarkAsChild();
internal FormatContents(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~FormatContents()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FormatContents()
{
_CountFinalized++;
}
@@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(FormatContent.Get(dr));
this.RaiseListChangedEvents = true;
Add(FormatContent.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class FormatIDCriteria
{
public FormatIDCriteria(int formatID)
{
_FormatID = formatID;
}
private int _FormatID;
public FormatIDCriteria(int formatID) => _FormatID = formatID;
private int _FormatID;
public int FormatID
{
get { return _FormatID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(FormatIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatContents.DataPortal_FetchFormatID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new FormatContent(dr));
while (dr.Read()) Add(new FormatContent(dr));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatContents.DataPortal_FetchFormatID", ex);
throw new DbCslaException("FormatContents.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Format format)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
FormatContentsPropertyDescriptor pd = new FormatContentsPropertyDescriptor(this, i);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class FormatContentsPropertyDescriptor : vlnListPropertyDescriptor
{
private FormatContent Item { get { return (FormatContent)_Item; } }
public FormatContentsPropertyDescriptor(FormatContents collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FormatContents)
if (destType == typeof(string) && value is FormatContents contents)
{
// Return department and department role separated by comma.
return ((FormatContents)value).Items.Count.ToString() + " Contents";
return $"{contents.Items.Count} Contents";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _VersionID;
[System.ComponentModel.DataObjectField(true, true)]
public int VersionID
@@ -329,10 +323,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current FormatDocVersion</returns>
protected override object GetIdValue()
{
return MyFormatDocVersionUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyFormatDocVersionUnique; // Absolutely Unique ID
// CSLATODO: Replace base FormatDocVersion.ToString function as necessary
/// <summary>
/// Overrides Base ToString
@@ -356,18 +347,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyFolder != null && _MyFolder.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyFolder == null || _MyFolder.IsValidList(list));
}
#endregion
#region ValidationRules
@@ -398,8 +386,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -432,84 +420,22 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(VersionID, "<Role(s)>");
//AuthorizationRules.AllowRead(FolderID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FolderID, "<Role(s)>");
//AuthorizationRules.AllowRead(VersionType, "<Role(s)>");
//AuthorizationRules.AllowWrite(VersionType, "<Role(s)>");
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
//AuthorizationRules.AllowRead(Title, "<Role(s)>");
//AuthorizationRules.AllowWrite(Title, "<Role(s)>");
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _FormatDocVersionUnique = 0;
private static int FormatDocVersionUnique
{ get { return ++_FormatDocVersionUnique; } }
private int _MyFormatDocVersionUnique = FormatDocVersionUnique;
public int MyFormatDocVersionUnique // Absolutely Unique ID - Editable FK
{ get { return _MyFormatDocVersionUnique; } }
internal static FormatDocVersion New(Folder myFolder, string name)
{
return new FormatDocVersion(myFolder, name);
}
internal static FormatDocVersion Get(SafeDataReader dr)
{
return new FormatDocVersion(dr);
}
private static int FormatDocVersionUnique => ++_FormatDocVersionUnique;
private readonly int _MyFormatDocVersionUnique = FormatDocVersionUnique;
// Absolutely Unique ID - Editable FK
public int MyFormatDocVersionUnique => _MyFormatDocVersionUnique;
internal static FormatDocVersion New(Folder myFolder, string name) => new FormatDocVersion(myFolder, name);
internal static FormatDocVersion Get(SafeDataReader dr) => new FormatDocVersion(dr);
public FormatDocVersion()
{
MarkAsChild();
@@ -540,15 +466,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FormatDocVersion()
{
_CountFinalized++;
@@ -597,33 +519,46 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Format myFormat)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = DocVersion.Add(cn, ref _VersionID, _MyFolder, _VersionType, _Name, _Title, _MyItem, myFormat, _Config, _DTS, _UserID);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = DocVersion.Add(cn, ref _VersionID, _MyFolder, _VersionType, _Name, _Title, _MyItem, myFormat, _Config, _DTS, _UserID);
}
MarkOld();
}
internal void Update(Format myFormat)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = DocVersion.Update(cn, ref _VersionID, _FolderID, _VersionType, _Name, _Title, _ItemID, myFormat != null ? (int?)myFormat.FormatID : (int?)null, _Config, _DTS, _UserID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = DocVersion.Update(cn, ref _VersionID, _FolderID, _VersionType, _Name, _Title, _ItemID, myFormat != null ? (int?)myFormat.FormatID : (int?)null, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Format myFormat)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
DocVersion.Remove(cn, _VersionID);
if (IsNew) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
DocVersion.Remove(cn, _VersionID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
FormatDocVersionExtension _FormatDocVersionExtension = new FormatDocVersionExtension();
readonly FormatDocVersionExtension _FormatDocVersionExtension = new FormatDocVersionExtension();
[Serializable()]
partial class FormatDocVersionExtension : extensionBase
{
@@ -632,18 +567,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultVersionType
{
get { return 0; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultVersionType => 0;
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -672,61 +598,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FormatDocVersion)
if (destType == typeof(string) && value is FormatDocVersion version)
{
// Return the ToString value
return ((FormatDocVersion)value).ToString();
return version.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create FormatDocVersionExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class FormatDocVersion
// {
// partial class FormatDocVersionExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultVersionType
// {
// get { return 0; }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public FormatDocVersion this[DocVersion myDocVersion]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public FormatDocVersion this[DocVersion myDocVersion]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<FormatDocVersion> Items
{
get { return base.Items; }
}
public FormatDocVersion GetItem(DocVersion myDocVersion)
public new System.Collections.Generic.IList<FormatDocVersion> Items => base.Items;
public FormatDocVersion GetItem(DocVersion myDocVersion)
{
foreach (FormatDocVersion docVersion in this)
if (docVersion.VersionID == myDocVersion.VersionID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public FormatDocVersion Add(Folder myFolder, string name) // One to Many
{
FormatDocVersion docVersion = FormatDocVersion.New(myFolder, name);
this.Add(docVersion);
Add(docVersion);
return docVersion;
}
public void Remove(DocVersion myDocVersion)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (FormatDocVersion child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (FormatDocVersion child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static FormatDocVersions New()
{
return new FormatDocVersions();
}
internal static FormatDocVersions Get(SafeDataReader dr)
{
return new FormatDocVersions(dr);
}
public static FormatDocVersions GetByFormatID(int formatID)
#endregion
#region Factory Methods
internal static FormatDocVersions New() => new FormatDocVersions();
internal static FormatDocVersions Get(SafeDataReader dr) => new FormatDocVersions(dr);
public static FormatDocVersions GetByFormatID(int formatID)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on FormatDocVersions.GetByFormatID", ex);
}
}
private FormatDocVersions()
{
MarkAsChild();
}
internal FormatDocVersions(SafeDataReader dr)
private FormatDocVersions() => MarkAsChild();
internal FormatDocVersions(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~FormatDocVersions()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FormatDocVersions()
{
_CountFinalized++;
}
@@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(FormatDocVersion.Get(dr));
this.RaiseListChangedEvents = true;
Add(FormatDocVersion.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class FormatIDCriteria
{
public FormatIDCriteria(int formatID)
{
_FormatID = formatID;
}
private int _FormatID;
public FormatIDCriteria(int formatID) => _FormatID = formatID;
private int _FormatID;
public int FormatID
{
get { return _FormatID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(FormatIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatDocVersions.DataPortal_FetchFormatID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new FormatDocVersion(dr));
while (dr.Read()) Add(new FormatDocVersion(dr));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatDocVersions.DataPortal_FetchFormatID", ex);
throw new DbCslaException("FormatDocVersions.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Format format)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
FormatDocVersionsPropertyDescriptor pd = new FormatDocVersionsPropertyDescriptor(this, i);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class FormatDocVersionsPropertyDescriptor : vlnListPropertyDescriptor
{
private FormatDocVersion Item { get { return (FormatDocVersion)_Item; } }
public FormatDocVersionsPropertyDescriptor(FormatDocVersions collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FormatDocVersions)
if (destType == typeof(string) && value is FormatDocVersions versions)
{
// Return department and department role separated by comma.
return ((FormatDocVersions)value).Items.Count.ToString() + " DocVersions";
return $"{versions.Items.Count} DocVersions";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _FolderID;
[System.ComponentModel.DataObjectField(true, true)]
public int FolderID
@@ -321,19 +315,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current FormatFolder</returns>
protected override object GetIdValue()
{
return MyFormatFolderUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base FormatFolder.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current FormatFolder</returns>
//public override string ToString()
//{
// return base.ToString();
//}
protected override object GetIdValue() => MyFormatFolderUnique; // Absolutely Unique ID
public override bool IsDirty
{
get
@@ -348,18 +330,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirtyList(list)) || (_MyConnection == null ? false : _MyConnection.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyFolder != null && _MyFolder.IsDirtyList(list)) || (_MyConnection != null && _MyConnection.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)) && (_MyConnection == null ? true : _MyConnection.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyFolder == null || _MyFolder.IsValidList(list)) && (_MyConnection == null || _MyConnection.IsValidList(list));
}
#endregion
#region ValidationRules
@@ -390,8 +369,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -439,86 +418,22 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(FolderID, "<Role(s)>");
//AuthorizationRules.AllowRead(ParentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ParentID, "<Role(s)>");
//AuthorizationRules.AllowRead(DBID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DBID, "<Role(s)>");
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
//AuthorizationRules.AllowRead(Title, "<Role(s)>");
//AuthorizationRules.AllowWrite(Title, "<Role(s)>");
//AuthorizationRules.AllowRead(ShortName, "<Role(s)>");
//AuthorizationRules.AllowWrite(ShortName, "<Role(s)>");
//AuthorizationRules.AllowRead(ManualOrder, "<Role(s)>");
//AuthorizationRules.AllowWrite(ManualOrder, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _FormatFolderUnique = 0;
private static int FormatFolderUnique
{ get { return ++_FormatFolderUnique; } }
private int _MyFormatFolderUnique = FormatFolderUnique;
public int MyFormatFolderUnique // Absolutely Unique ID - Editable FK
{ get { return _MyFormatFolderUnique; } }
internal static FormatFolder New(Folder myParent, string name, string shortName)
{
return new FormatFolder(myParent, name, shortName);
}
internal static FormatFolder Get(SafeDataReader dr)
{
return new FormatFolder(dr);
}
private static int FormatFolderUnique => ++_FormatFolderUnique;
private readonly int _MyFormatFolderUnique = FormatFolderUnique;
// Absolutely Unique ID - Editable FK
public int MyFormatFolderUnique => _MyFormatFolderUnique;
internal static FormatFolder New(Folder myParent, string name, string shortName) => new FormatFolder(myParent, name, shortName);
internal static FormatFolder Get(SafeDataReader dr) => new FormatFolder(dr);
public FormatFolder()
{
MarkAsChild();
@@ -552,15 +467,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FormatFolder()
{
_CountFinalized++;
@@ -607,33 +518,46 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Format myFormat)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Folder.Add(cn, ref _FolderID, Folder.Get(_ParentID), _MyConnection, _Name, _Title, _ShortName, myFormat, _ManualOrder, _Config, _DTS, _UsrID);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Folder.Add(cn, ref _FolderID, Folder.Get(_ParentID), _MyConnection, _Name, _Title, _ShortName, myFormat, _ManualOrder, _Config, _DTS, _UsrID);
}
MarkOld();
}
internal void Update(Format myFormat)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Folder.Update(cn, ref _FolderID, _ParentID, _DBID, _Name, _Title, _ShortName, myFormat != null ? (int?)myFormat.FormatID : (int?)null, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Folder.Update(cn, ref _FolderID, _ParentID, _DBID, _Name, _Title, _ShortName, myFormat != null ? (int?)myFormat.FormatID : (int?)null, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Format myFormat)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Folder.Remove(cn, _FolderID);
if (IsNew) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Folder.Remove(cn, _FolderID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
FormatFolderExtension _FormatFolderExtension = new FormatFolderExtension();
readonly FormatFolderExtension _FormatFolderExtension = new FormatFolderExtension();
[Serializable()]
partial class FormatFolderExtension : extensionBase
{
@@ -642,22 +566,10 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultParentID
{
get { return 1; }
}
public virtual int DefaultDBID
{
get { return 1; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUsrID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultParentID => 1;
public virtual int DefaultDBID => 1;
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUsrID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -686,65 +598,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FormatFolder)
if (destType == typeof(string) && value is FormatFolder folder)
{
// Return the ToString value
return ((FormatFolder)value).ToString();
return folder.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create FormatFolderExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class FormatFolder
// {
// partial class FormatFolderExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultParentID
// {
// get { return 1; }
// }
// public virtual int DefaultDBID
// {
// get { return 1; }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUsrID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public FormatFolder this[Folder myFolder]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public FormatFolder this[Folder myFolder]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<FormatFolder> Items
{
get { return base.Items; }
}
public FormatFolder GetItem(Folder myFolder)
public new System.Collections.Generic.IList<FormatFolder> Items => base.Items;
public FormatFolder GetItem(Folder myFolder)
{
foreach (FormatFolder folder in this)
if (folder.FolderID == myFolder.FolderID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public FormatFolder Add(Folder myParent, string name, string shortName) // One to Many
{
FormatFolder folder = FormatFolder.New(myParent, name, shortName);
this.Add(folder);
Add(folder);
return folder;
}
public void Remove(Folder myFolder)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (FormatFolder child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (FormatFolder child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return (hasBrokenRules?.BrokenRules);
}
}
#endregion
#region Factory Methods
internal static FormatFolders New()
{
return new FormatFolders();
}
internal static FormatFolders Get(SafeDataReader dr)
{
return new FormatFolders(dr);
}
public static FormatFolders GetByFormatID(int formatID)
#endregion
#region Factory Methods
internal static FormatFolders New() => new FormatFolders();
internal static FormatFolders Get(SafeDataReader dr) => new FormatFolders(dr);
public static FormatFolders GetByFormatID(int formatID)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on FormatFolders.GetByFormatID", ex);
}
}
private FormatFolders()
{
MarkAsChild();
}
internal FormatFolders(SafeDataReader dr)
private FormatFolders() => MarkAsChild();
internal FormatFolders(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~FormatFolders()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FormatFolders()
{
_CountFinalized++;
}
@@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(FormatFolder.Get(dr));
this.RaiseListChangedEvents = true;
Add(FormatFolder.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class FormatIDCriteria
{
public FormatIDCriteria(int formatID)
{
_FormatID = formatID;
}
private int _FormatID;
public FormatIDCriteria(int formatID) => _FormatID = formatID;
private int _FormatID;
public int FormatID
{
get { return _FormatID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(FormatIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatFolders.DataPortal_FetchFormatID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new FormatFolder(dr));
while (dr.Read()) Add(new FormatFolder(dr));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatFolders.DataPortal_FetchFormatID", ex);
throw new DbCslaException("FormatFolders.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Format format)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,39 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
FormatFoldersPropertyDescriptor pd = new FormatFoldersPropertyDescriptor(this, i);
@@ -325,7 +288,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class FormatFoldersPropertyDescriptor : vlnListPropertyDescriptor
{
private FormatFolder Item { get { return (FormatFolder)_Item; } }
public FormatFoldersPropertyDescriptor(FormatFolders collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +296,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FormatFolders)
if (destType == typeof(string) && value is FormatFolders folders)
{
// Return department and department role separated by comma.
return ((FormatFolders)value).Items.Count.ToString() + " Folders";
return $"{folders.Items.Count} Folders";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class FormatInfo : ReadOnlyBase<FormatInfo>, IDisposable
{
public event FormatInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<FormatInfo> _CacheList = new List<FormatInfo>();
protected static void AddToCache(FormatInfo formatInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(formatInfo)) _CacheList.Remove(formatInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<FormatInfo>> _CacheByPrimaryKey = new Dictionary<string, List<FormatInfo>>();
private static void ConvertListToDictionary()
{
@@ -81,21 +78,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Format _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _FormatID;
[System.ComponentModel.DataObjectField(true, true)]
public int FormatID
@@ -342,32 +326,19 @@ namespace VEPROMS.CSLA.Library
foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()])
tmp._ChildFormatCount = -1; // This will cause the data to be requeried
}
// CSLATODO: Replace base FormatInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current FormatInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check FormatInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current FormatInfo</returns>
protected override object GetIdValue()
{
return MyFormatInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyFormatInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _FormatInfoUnique = 0;
private static int FormatInfoUnique
{ get { return ++_FormatInfoUnique; } }
private int _MyFormatInfoUnique = FormatInfoUnique;
public int MyFormatInfoUnique // Absolutely Unique ID - Info
{ get { return _MyFormatInfoUnique; } }
private static int FormatInfoUnique => ++_FormatInfoUnique;
private readonly int _MyFormatInfoUnique = FormatInfoUnique;
// Absolutely Unique ID - Info
public int MyFormatInfoUnique => _MyFormatInfoUnique;
protected FormatInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -376,15 +347,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FormatInfo()
{
_CountFinalized++;
@@ -417,11 +384,11 @@ namespace VEPROMS.CSLA.Library
{
if (_ParentID != tmp.ParentID)
{
if (MyParent != null) MyParent.RefreshChildFormats(); // Update List for old value
MyParent?.RefreshChildFormats(); // Update List for old value
_ParentID = tmp.ParentID; // Update the value
}
_MyParent = null; // Reset list so that the next line gets a new list
if (MyParent != null) MyParent.RefreshChildFormats(); // Update List for new value
MyParent?.RefreshChildFormats(); // Update List for new value
_Name = tmp.Name;
_Description = tmp.Description;
_Data = tmp.Data;
@@ -434,8 +401,6 @@ namespace VEPROMS.CSLA.Library
}
public static FormatInfo Get(int formatID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Format");
try
{
FormatInfo tmp = GetCachedByPrimaryKey(formatID);
@@ -474,13 +439,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _FormatID;
public int FormatID
{ get { return _FormatID; } }
public PKCriteria(int formatID)
{
_FormatID = formatID;
}
private readonly int _FormatID;
public int FormatID => _FormatID;
public PKCriteria(int formatID) => _FormatID = formatID;
}
public static string _Failed = null;
public static string Failed
@@ -564,7 +525,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
FormatInfoExtension _FormatInfoExtension = new FormatInfoExtension();
readonly FormatInfoExtension _FormatInfoExtension = new FormatInfoExtension();
[Serializable()]
partial class FormatInfoExtension : extensionBase { }
[Serializable()]
@@ -580,10 +541,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FormatInfo)
if (destType == typeof(string) && value is FormatInfo info)
{
// Return the ToString value
return ((FormatInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<FormatInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<FormatInfo> Items => base.Items;
public void AddEvents()
{
foreach (FormatInfo tmp in this)
{
@@ -44,23 +41,19 @@ namespace VEPROMS.CSLA.Library
for (int i = 0; i < Count; i++)
{
if (base[i] == sender)
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
}
}
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~FormatInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~FormatInfoList()
{
_CountFinalized++;
}
@@ -105,18 +98,6 @@ namespace VEPROMS.CSLA.Library
_FormatInfoList = null;
_SortedFormatInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static FormatInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<FormatInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on FormatInfoList.Get", ex);
// }
//}
public static FormatInfoList GetChildren(int parentID)
{
try
@@ -137,7 +118,7 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
private void DataPortal_Fetch()
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfoList.DataPortal_Fetch", GetHashCode());
try
{
@@ -151,7 +132,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new FormatInfo(dr));
while (dr.Read()) Add(new FormatInfo(dr));
IsReadOnly = true;
}
}
@@ -170,16 +151,13 @@ namespace VEPROMS.CSLA.Library
System.Windows.Forms.MessageBox.Show(sbMsg.ToString(), "Update Stored Procedures", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
throw new DbCslaException("FormatInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
[Serializable()]
private class ParentIDCriteria
{
public ParentIDCriteria(int parentID)
{
_ParentID = parentID;
}
private int _ParentID;
public ParentIDCriteria(int parentID) => _ParentID = parentID;
private int _ParentID;
public int ParentID
{
get { return _ParentID; }
@@ -188,7 +166,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(ParentIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfoList.DataPortal_FetchParentID", GetHashCode());
try
{
@@ -203,7 +181,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new FormatInfo(dr));
while (dr.Read()) Add(new FormatInfo(dr));
IsReadOnly = true;
}
}
@@ -214,48 +192,37 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfoList.DataPortal_FetchParentID", ex);
throw new DbCslaException("FormatInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
FormatInfoListPropertyDescriptor pd = new FormatInfoListPropertyDescriptor(this, i);
@@ -272,7 +239,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class FormatInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private FormatInfo Item { get { return (FormatInfo)_Item; } }
public FormatInfoListPropertyDescriptor(FormatInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -281,10 +247,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FormatInfoList)
if (destType == typeof(string) && value is FormatInfoList list)
{
// Return department and department role separated by comma.
return ((FormatInfoList)value).Items.Count.ToString() + " Formats";
return $"{list.Items.Count} Formats";
}
return base.ConvertTo(context, culture, value, destType);
}
+116 -251
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty)
refreshGrids.Add(this);
}
private void ClearRefreshList()
{
_RefreshGrids = new List<Grid>();
}
private void ClearRefreshList() => _RefreshGrids = new List<Grid>();
private void BuildRefreshList()
{
ClearRefreshList();
@@ -56,6 +51,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Grid> _CacheList = new List<Grid>();
protected static void AddToCache(Grid grid)
{
@@ -65,6 +61,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(grid)) _CacheList.Remove(grid); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Grid>> _CacheByPrimaryKey = new Dictionary<string, List<Grid>>();
private static void ConvertListToDictionary()
{
@@ -90,10 +87,7 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)]
public int ContentID
@@ -192,40 +186,18 @@ namespace VEPROMS.CSLA.Library
}
}
private byte[] _LastChanged = new byte[8];//timestamp
public override bool IsDirty
{
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
// CSLATODO: Replace base Grid.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Grid</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty => base.IsDirty;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsDirtyList(List<object> list) => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsValidList(List<object> list) => (IsNew && !IsDirty) || base.IsValid;
// CSLATODO: Check Grid.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Grid</returns>
protected override object GetIdValue()
{
return MyGridUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyGridUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -253,8 +225,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -281,31 +253,11 @@ namespace VEPROMS.CSLA.Library
_GridExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(Data, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Data, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_GridExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -313,42 +265,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_GridExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _GridUnique = 0;
protected static int GridUnique
{ get { return ++_GridUnique; } }
private int _MyGridUnique = GridUnique;
public int MyGridUnique // Absolutely Unique ID - Editable
{ get { return _MyGridUnique; } }
protected static int GridUnique => ++_GridUnique;
private readonly int _MyGridUnique = GridUnique;
// Absolutely Unique ID - Editable
public int MyGridUnique => _MyGridUnique;
protected Grid()
{/* require use of factory methods */
AddToCache(this);
@@ -357,15 +281,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Grid()
{
_CountFinalized++;
@@ -390,8 +310,6 @@ namespace VEPROMS.CSLA.Library
}
public static Grid New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Grid");
try
{
return DataPortal.Create<Grid>();
@@ -468,8 +386,6 @@ namespace VEPROMS.CSLA.Library
}
public static Grid Get(int contentID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Grid");
try
{
Grid tmp = GetCachedByPrimaryKey(contentID);
@@ -495,14 +411,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Grid(dr);
return null;
}
internal Grid(SafeDataReader dr)
{
ReadData(dr);
}
internal Grid(SafeDataReader dr) => ReadData(dr);
public static void Delete(int contentID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Grid");
try
{
DataPortal.Delete(new PKCriteria(contentID));
@@ -514,12 +425,6 @@ namespace VEPROMS.CSLA.Library
}
public override Grid Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Grid");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Grid");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Grid");
try
{
BuildRefreshList();
@@ -539,13 +444,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _ContentID;
public int ContentID
{ get { return _ContentID; } }
public PKCriteria(int contentID)
{
_ContentID = contentID;
}
private readonly int _ContentID;
public int ContentID => _ContentID;
public PKCriteria(int contentID) => _ContentID = contentID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -614,7 +515,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Grid.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -639,33 +540,39 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addGrid";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addGrid";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.SQLInsert", GetHashCode());
@@ -677,7 +584,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Grid.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, Content myContent, string data, string config, DateTime dts, string userID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.Add", 0);
@@ -695,8 +602,10 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -710,7 +619,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Grid.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -733,38 +642,44 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateGrid";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateGrid";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -777,18 +692,22 @@ namespace VEPROMS.CSLA.Library
}
internal void Update(Content content)
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Grid.Add(cn, content, _Data, _Config, _DTS, _UserID);
else
_LastChanged = Grid.Update(cn, content.ContentID, _Data, _Config, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = Grid.Add(cn, content, _Data, _Config, _DTS, _UserID);
else
_LastChanged = Grid.Update(cn, content.ContentID, _Data, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, int contentID, string data, string config, DateTime dts, string userID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.Update", 0);
@@ -807,8 +726,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -822,12 +743,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Grid.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_ContentID));
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.DataPortal_Delete", GetHashCode());
@@ -852,7 +773,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Grid.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int contentID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.Remove", 0);
@@ -893,16 +814,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _ContentID;
private readonly int _ContentID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int contentID)
{
_ContentID = contentID;
}
public bool Exists => _exists;
public ExistsCommand(int contentID) => _ContentID = contentID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.DataPortal_Execute", GetHashCode());
@@ -910,7 +825,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -932,7 +847,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
GridExtension _GridExtension = new GridExtension();
readonly GridExtension _GridExtension = new GridExtension();
[Serializable()]
partial class GridExtension : extensionBase
{
@@ -941,14 +856,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -977,57 +886,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Grid)
if (destType == typeof(string) && value is Grid mygrid)
{
// Return the ToString value
return ((Grid)value).ToString();
return mygrid.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create GridExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Grid
// {
// partial class GridExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
+105 -247
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -56,6 +54,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<GridAudit> _CacheList = new List<GridAudit>();
protected static void AddToCache(GridAudit gridAudit)
{
@@ -65,6 +64,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(gridAudit)) _CacheList.Remove(gridAudit); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<GridAudit>> _CacheByPrimaryKey = new Dictionary<string, List<GridAudit>>();
private static void ConvertListToDictionary()
{
@@ -90,15 +90,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextAuditID = -1;
public static int NextAuditID
{
get { return _nextAuditID--; }
}
public static int NextAuditID => _nextAuditID--;
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -238,40 +232,14 @@ namespace VEPROMS.CSLA.Library
}
}
}
public override bool IsDirty
{
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
// CSLATODO: Replace base GridAudit.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current GridAudit</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
// CSLATODO: Check GridAudit.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current GridAudit</returns>
protected override object GetIdValue()
{
return MyGridAuditUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyGridAuditUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -299,8 +267,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -327,37 +295,11 @@ namespace VEPROMS.CSLA.Library
_GridAuditExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AuditID, "<Role(s)>");
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(Data, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(DeleteStatus, "<Role(s)>");
//AuthorizationRules.AllowRead(ContentAuditID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ContentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Data, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DeleteStatus, "<Role(s)>");
//AuthorizationRules.AllowWrite(ContentAuditID, "<Role(s)>");
_GridAuditExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -365,42 +307,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_GridAuditExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _GridAuditUnique = 0;
protected static int GridAuditUnique
{ get { return ++_GridAuditUnique; } }
private int _MyGridAuditUnique = GridAuditUnique;
public int MyGridAuditUnique // Absolutely Unique ID - Editable
{ get { return _MyGridAuditUnique; } }
protected static int GridAuditUnique => ++_GridAuditUnique;
private readonly int _MyGridAuditUnique = GridAuditUnique;
// Absolutely Unique ID - Editable
public int MyGridAuditUnique => _MyGridAuditUnique;
protected GridAudit()
{/* require use of factory methods */
AddToCache(this);
@@ -409,15 +323,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~GridAudit()
{
_CountFinalized++;
@@ -442,8 +352,6 @@ namespace VEPROMS.CSLA.Library
}
public static GridAudit New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a GridAudit");
try
{
return DataPortal.Create<GridAudit>();
@@ -520,8 +428,6 @@ namespace VEPROMS.CSLA.Library
}
public static GridAudit Get(long auditID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a GridAudit");
try
{
GridAudit tmp = GetCachedByPrimaryKey(auditID);
@@ -547,14 +453,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new GridAudit(dr);
return null;
}
internal GridAudit(SafeDataReader dr)
{
ReadData(dr);
}
internal GridAudit(SafeDataReader dr) => ReadData(dr);
public static void Delete(long auditID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a GridAudit");
try
{
DataPortal.Delete(new PKCriteria(auditID));
@@ -566,12 +467,6 @@ namespace VEPROMS.CSLA.Library
}
public override GridAudit Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a GridAudit");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a GridAudit");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a GridAudit");
try
{
BuildRefreshList();
@@ -591,13 +486,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private long _AuditID;
public long AuditID
{ get { return _AuditID; } }
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
private readonly long _AuditID;
public long AuditID => _AuditID;
public PKCriteria(long auditID) => _AuditID = auditID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -667,7 +558,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("GridAudit.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -692,35 +583,41 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addGridAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
cm.Parameters.AddWithValue("@ContentAuditID", _ContentAuditID);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addGridAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
cm.Parameters.AddWithValue("@ContentAuditID", _ContentAuditID);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.SQLInsert", GetHashCode());
@@ -732,7 +629,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("GridAudit.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Add(SqlConnection cn, ref long auditID, int contentID, string data, string config, DateTime dts, string userID, int deleteStatus, long contentAuditID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.Add", 0);
@@ -752,8 +649,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus);
cm.Parameters.AddWithValue("@ContentAuditID", contentAuditID);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -768,7 +667,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("GridAudit.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -791,36 +690,40 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateGridAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
cm.Parameters.AddWithValue("@ContentAuditID", _ContentAuditID);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateGridAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
cm.Parameters.AddWithValue("@ContentAuditID", _ContentAuditID);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -833,18 +736,22 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
GridAudit.Add(cn, ref _AuditID, _ContentID, _Data, _Config, _DTS, _UserID, _DeleteStatus, _ContentAuditID);
else
GridAudit.Update(cn, ref _AuditID, _ContentID, _Data, _Config, _DTS, _UserID, _DeleteStatus, _ContentAuditID);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
GridAudit.Add(cn, ref _AuditID, _ContentID, _Data, _Config, _DTS, _UserID, _DeleteStatus, _ContentAuditID);
else
GridAudit.Update(cn, ref _AuditID, _ContentID, _Data, _Config, _DTS, _UserID, _DeleteStatus, _ContentAuditID);
}
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Update(SqlConnection cn, ref long auditID, int contentID, string data, string config, DateTime dts, string userID, int deleteStatus, long contentAuditID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.Update", 0);
@@ -877,12 +784,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("GridAudit.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_AuditID));
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.DataPortal_Delete", GetHashCode());
@@ -907,7 +814,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("GridAudit.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, long auditID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.Remove", 0);
@@ -948,16 +855,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private long _AuditID;
private readonly long _AuditID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(long auditID)
{
_AuditID = auditID;
}
public bool Exists => _exists;
public ExistsCommand(long auditID) => _AuditID = auditID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.DataPortal_Execute", GetHashCode());
@@ -965,7 +866,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -987,7 +888,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
GridAuditExtension _GridAuditExtension = new GridAuditExtension();
readonly GridAuditExtension _GridAuditExtension = new GridAuditExtension();
[Serializable()]
partial class GridAuditExtension : extensionBase
{
@@ -996,10 +897,7 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual long DefaultContentAuditID
{
get { return 0; }
}
public virtual long DefaultContentAuditID => 0;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1028,53 +926,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is GridAudit)
if (destType == typeof(string) && value is GridAudit audit)
{
// Return the ToString value
return ((GridAudit)value).ToString();
return audit.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create GridAuditExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class GridAudit
// {
// partial class GridAuditExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual long DefaultContentAuditID
// {
// get { return 0; }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class GridAuditInfo : ReadOnlyBase<GridAuditInfo>, IDisposable
{
public event GridAuditInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<GridAuditInfo> _CacheList = new List<GridAuditInfo>();
protected static void AddToCache(GridAuditInfo gridAuditInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(gridAuditInfo)) _CacheList.Remove(gridAuditInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<GridAuditInfo>> _CacheByPrimaryKey = new Dictionary<string, List<GridAuditInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected GridAudit _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -162,32 +146,19 @@ namespace VEPROMS.CSLA.Library
return _ContentAuditID;
}
}
// CSLATODO: Replace base GridAuditInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current GridAuditInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check GridAuditInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current GridAuditInfo</returns>
protected override object GetIdValue()
{
return MyGridAuditInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyGridAuditInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _GridAuditInfoUnique = 0;
private static int GridAuditInfoUnique
{ get { return ++_GridAuditInfoUnique; } }
private int _MyGridAuditInfoUnique = GridAuditInfoUnique;
public int MyGridAuditInfoUnique // Absolutely Unique ID - Info
{ get { return _MyGridAuditInfoUnique; } }
private static int GridAuditInfoUnique => ++_GridAuditInfoUnique;
private readonly int _MyGridAuditInfoUnique = GridAuditInfoUnique;
// Absolutely Unique ID - Info
public int MyGridAuditInfoUnique => _MyGridAuditInfoUnique;
protected GridAuditInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -196,15 +167,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~GridAuditInfo()
{
_CountFinalized++;
@@ -221,10 +188,7 @@ namespace VEPROMS.CSLA.Library
if (listGridAuditInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list
}
public virtual GridAudit Get()
{
return _Editable = GridAudit.Get(_AuditID);
}
public virtual GridAudit Get() => _Editable = GridAudit.Get(_AuditID);
public static void Refresh(GridAudit tmp)
{
string key = tmp.AuditID.ToString();
@@ -247,8 +211,6 @@ namespace VEPROMS.CSLA.Library
}
public static GridAuditInfo Get(long auditID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a GridAudit");
try
{
GridAuditInfo tmp = GetCachedByPrimaryKey(auditID);
@@ -287,13 +249,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private long _AuditID;
public long AuditID
{ get { return _AuditID; } }
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
private readonly long _AuditID;
public long AuditID => _AuditID;
public PKCriteria(long auditID) => _AuditID = auditID;
}
private void ReadData(SafeDataReader dr)
{
@@ -355,7 +313,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
GridAuditInfoExtension _GridAuditInfoExtension = new GridAuditInfoExtension();
readonly GridAuditInfoExtension _GridAuditInfoExtension = new GridAuditInfoExtension();
[Serializable()]
partial class GridAuditInfoExtension : extensionBase { }
[Serializable()]
@@ -371,10 +329,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is GridAuditInfo)
if (destType == typeof(string) && value is GridAuditInfo info)
{
// Return the ToString value
return ((GridAuditInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<GridAuditInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<GridAuditInfo> Items => base.Items;
public void AddEvents()
{
foreach (GridAuditInfo tmp in this)
{
@@ -44,23 +41,19 @@ namespace VEPROMS.CSLA.Library
for (int i = 0; i < Count; i++)
{
if (base[i] == sender)
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
}
}
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~GridAuditInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~GridAuditInfoList()
{
_CountFinalized++;
}
@@ -97,32 +90,17 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on GridAuditInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all GridAuditInfo.
/// </summary>
public static void Reset()
{
_GridAuditInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static GridAuditInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<GridAuditInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on GridAuditInfoList.Get", ex);
// }
//}
private GridAuditInfoList()
/// <summary>
/// Reset the list of all GridAuditInfo.
/// </summary>
public static void Reset() => _GridAuditInfoList = null;
private GridAuditInfoList()
{ /* require use of factory methods */ }
#endregion
#region Data Access Portal
private void DataPortal_Fetch()
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAuditInfoList.DataPortal_Fetch", GetHashCode());
try
{
@@ -136,7 +114,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new GridAuditInfo(dr));
while (dr.Read()) Add(new GridAuditInfo(dr));
IsReadOnly = true;
}
}
@@ -147,48 +125,38 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAuditInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("GridAuditInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
GridAuditInfoListPropertyDescriptor pd = new GridAuditInfoListPropertyDescriptor(this, i);
@@ -205,7 +173,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class GridAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private GridAuditInfo Item { get { return (GridAuditInfo)_Item; } }
public GridAuditInfoListPropertyDescriptor(GridAuditInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -214,10 +181,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is GridAuditInfoList)
if (destType == typeof(string) && value is GridAuditInfoList list)
{
// Return department and department role separated by comma.
return ((GridAuditInfoList)value).Items.Count.ToString() + " GridAudits";
return $"{list.Items.Count} GridAudits";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
@@ -30,14 +28,12 @@ namespace VEPROMS.CSLA.Library
public partial class GridInfo : ReadOnlyBase<GridInfo>, IDisposable
{
public event GridInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<GridInfo> _CacheList = new List<GridInfo>();
protected static void AddToCache(GridInfo gridInfo)
{
@@ -47,6 +43,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(gridInfo)) _CacheList.Remove(gridInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<GridInfo>> _CacheByPrimaryKey = new Dictionary<string, List<GridInfo>>();
private static void ConvertListToDictionary()
{
@@ -92,21 +89,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Grid _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)]
public int ContentID
@@ -165,32 +149,19 @@ namespace VEPROMS.CSLA.Library
return _UserID;
}
}
// CSLATODO: Replace base GridInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current GridInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check GridInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current GridInfo</returns>
protected override object GetIdValue()
{
return MyGridInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyGridInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _GridInfoUnique = 0;
private static int GridInfoUnique
{ get { return ++_GridInfoUnique; } }
private int _MyGridInfoUnique = GridInfoUnique;
public int MyGridInfoUnique // Absolutely Unique ID - Info
{ get { return _MyGridInfoUnique; } }
private static int GridInfoUnique => ++_GridInfoUnique;
private readonly int _MyGridInfoUnique = GridInfoUnique;
// Absolutely Unique ID - Info
public int MyGridInfoUnique => _MyGridInfoUnique;
protected GridInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -199,15 +170,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~GridInfo()
{
_CountFinalized++;
@@ -224,10 +191,7 @@ namespace VEPROMS.CSLA.Library
if (listGridInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list
}
public virtual Grid Get()
{
return _Editable = Grid.Get(_ContentID);
}
public virtual Grid Get() => _Editable = Grid.Get(_ContentID);
public static void Refresh(Grid tmp)
{
string key = tmp.ContentID.ToString();
@@ -247,8 +211,6 @@ namespace VEPROMS.CSLA.Library
}
public static GridInfo Get(int contentID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Grid");
try
{
GridInfo tmp = GetCachedByPrimaryKey(contentID);
@@ -287,13 +249,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _ContentID;
public int ContentID
{ get { return _ContentID; } }
public PKCriteria(int contentID)
{
_ContentID = contentID;
}
private readonly int _ContentID;
public int ContentID => _ContentID;
public PKCriteria(int contentID) => _ContentID = contentID;
}
private void ReadData(SafeDataReader dr)
{
@@ -352,7 +310,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
GridInfoExtension _GridInfoExtension = new GridInfoExtension();
readonly GridInfoExtension _GridInfoExtension = new GridInfoExtension();
[Serializable()]
partial class GridInfoExtension : extensionBase { }
[Serializable()]
@@ -368,10 +326,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is GridInfo)
if (destType == typeof(string) && value is GridInfo info)
{
// Return the ToString value
return ((GridInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
+137 -288
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -82,6 +80,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Group> _CacheList = new List<Group>();
protected static void AddToCache(Group group)
{
@@ -91,7 +90,9 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(group)) _CacheList.Remove(group); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Group>> _CacheByPrimaryKey = new Dictionary<string, List<Group>>();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Group>> _CacheByGroupName = new Dictionary<string, List<Group>>();
private static void ConvertListToDictionary()
{
@@ -126,15 +127,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextGID = -1;
public static int NextGID
{
get { return _nextGID--; }
}
public static int NextGID => _nextGID--;
private int _GID;
[System.ComponentModel.DataObjectField(true, true)]
public int GID
@@ -270,10 +265,7 @@ namespace VEPROMS.CSLA.Library
return _GroupAssignments;
}
}
public void Reset_GroupAssignments()
{
_GroupAssignmentCount = -1;
}
public void Reset_GroupAssignments() => _GroupAssignmentCount = -1;
private int _GroupMembershipCount = 0;
/// <summary>
/// Count of GroupMemberships for this Group
@@ -305,10 +297,7 @@ namespace VEPROMS.CSLA.Library
return _GroupMemberships;
}
}
public void Reset_GroupMemberships()
{
_GroupMembershipCount = -1;
}
public void Reset_GroupMemberships() => _GroupMembershipCount = -1;
public override bool IsDirty
{
get
@@ -323,37 +312,22 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_GroupAssignments == null ? false : _GroupAssignments.IsDirtyList(list)) || (_GroupMemberships == null ? false : _GroupMemberships.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_GroupAssignments != null && _GroupAssignments.IsDirtyList(list)) || (_GroupMemberships != null && _GroupMemberships.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_GroupAssignments == null ? true : _GroupAssignments.IsValidList(list)) && (_GroupMemberships == null ? true : _GroupMemberships.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_GroupAssignments == null || _GroupAssignments.IsValidList(list)) && (_GroupMemberships == null || _GroupMemberships.IsValidList(list));
}
// CSLATODO: Replace base Group.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Group</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Group.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Group</returns>
protected override object GetIdValue()
{
return MyGroupUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyGroupUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -383,8 +357,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -411,33 +385,11 @@ namespace VEPROMS.CSLA.Library
_GroupExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(GID, "<Role(s)>");
//AuthorizationRules.AllowRead(GroupName, "<Role(s)>");
//AuthorizationRules.AllowRead(GroupType, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
//AuthorizationRules.AllowWrite(GroupName, "<Role(s)>");
//AuthorizationRules.AllowWrite(GroupType, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
_GroupExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -445,56 +397,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_GroupExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
/// <summary>
/// determines if related records (Foreign Keys) will keep this Item from being deleted
/// </summary>
public bool CanDelete
{
get
{
// Check to make sure that there are not any related records
int usedByCount = 0;
usedByCount += _GroupAssignmentCount;
usedByCount += _GroupMembershipCount;
return (usedByCount == 0);
}
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _GroupUnique = 0;
protected static int GroupUnique
{ get { return ++_GroupUnique; } }
private int _MyGroupUnique = GroupUnique;
public int MyGroupUnique // Absolutely Unique ID - Editable
{ get { return _MyGroupUnique; } }
protected static int GroupUnique => ++_GroupUnique;
private readonly int _MyGroupUnique = GroupUnique;
// Absolutely Unique ID - Editable
public int MyGroupUnique => _MyGroupUnique;
protected Group()
{/* require use of factory methods */
AddToCache(this);
@@ -503,15 +413,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Group()
{
_CountFinalized++;
@@ -548,8 +454,6 @@ namespace VEPROMS.CSLA.Library
}
public static Group New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Group");
try
{
return DataPortal.Create<Group>();
@@ -617,8 +521,6 @@ namespace VEPROMS.CSLA.Library
}
public static Group Get(int gid)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Group");
try
{
Group tmp = GetCachedByPrimaryKey(gid);
@@ -641,8 +543,6 @@ namespace VEPROMS.CSLA.Library
}
public static Group GetByGroupName(string groupName)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Group");
try
{
Group tmp = GetCachedByGroupName(groupName);
@@ -668,14 +568,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Group(dr);
return null;
}
internal Group(SafeDataReader dr)
{
ReadData(dr);
}
internal Group(SafeDataReader dr) => ReadData(dr);
public static void Delete(int gid)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Group");
try
{
DataPortal.Delete(new PKCriteria(gid));
@@ -687,12 +582,6 @@ namespace VEPROMS.CSLA.Library
}
public override Group Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Group");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Group");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Group");
try
{
BuildRefreshList();
@@ -712,24 +601,16 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _GID;
public int GID
{ get { return _GID; } }
public PKCriteria(int gid)
{
_GID = gid;
}
private readonly int _GID;
public int GID => _GID;
public PKCriteria(int gid) => _GID = gid;
}
[Serializable()]
private class GroupNameCriteria
{
private string _GroupName;
public string GroupName
{ get { return _GroupName; } }
public GroupNameCriteria(string groupName)
{
_GroupName = groupName;
}
private readonly string _GroupName;
public string GroupName => _GroupName;
public GroupNameCriteria(string groupName) => _GroupName = groupName;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -843,7 +724,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Group.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -868,41 +749,49 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addGroup";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@GroupName", _GroupName);
cm.Parameters.AddWithValue("@GroupType", _GroupType);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
// Output Calculated Columns
SqlParameter param_GID = new SqlParameter("@newGID", SqlDbType.Int);
param_GID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_GID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_GID = (int)cm.Parameters["@newGID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addGroup";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@GroupName", _GroupName);
cm.Parameters.AddWithValue("@GroupType", _GroupType);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
// Output Calculated Columns
SqlParameter param_GID = new SqlParameter("@newGID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_GID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_GID = (int)cm.Parameters["@newGID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_GroupAssignments != null) _GroupAssignments.Update(this);
if (_GroupMemberships != null) _GroupMemberships.Update(this);
_GroupAssignments?.Update(this);
_GroupMemberships?.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.SQLInsert", GetHashCode());
}
catch (Exception ex)
@@ -912,7 +801,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Group.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int gid, string groupName, int? groupType, string config, DateTime dts, string usrID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.Add", 0);
@@ -930,11 +819,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UsrID", usrID);
// Output Calculated Columns
SqlParameter param_GID = new SqlParameter("@newGID", SqlDbType.Int);
param_GID.Direction = ParameterDirection.Output;
SqlParameter param_GID = new SqlParameter("@newGID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_GID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -949,7 +842,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Group.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -972,43 +865,49 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateGroup";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@GID", _GID);
cm.Parameters.AddWithValue("@GroupName", _GroupName);
cm.Parameters.AddWithValue("@GroupType", _GroupType);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateGroup";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@GID", _GID);
cm.Parameters.AddWithValue("@GroupName", _GroupName);
cm.Parameters.AddWithValue("@GroupType", _GroupType);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UsrID", _UsrID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
if (_GroupAssignments != null) _GroupAssignments.Update(this);
if (_GroupMemberships != null) _GroupMemberships.Update(this);
_GroupAssignments?.Update(this);
_GroupMemberships?.Update(this);
}
catch (Exception ex)
{
@@ -1019,20 +918,24 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Group.Add(cn, ref _GID, _GroupName, _GroupType, _Config, _DTS, _UsrID);
else
_LastChanged = Group.Update(cn, ref _GID, _GroupName, _GroupType, _Config, _DTS, _UsrID, ref _LastChanged);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = Group.Add(cn, ref _GID, _GroupName, _GroupType, _Config, _DTS, _UsrID);
else
_LastChanged = Group.Update(cn, ref _GID, _GroupName, _GroupType, _Config, _DTS, _UsrID, ref _LastChanged);
}
MarkOld();
}
if (_GroupAssignments != null) _GroupAssignments.Update(this);
if (_GroupMemberships != null) _GroupMemberships.Update(this);
_GroupAssignments?.Update(this);
_GroupMemberships?.Update(this);
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int gid, string groupName, int? groupType, string config, DateTime dts, string usrID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.Update", 0);
@@ -1052,8 +955,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UsrID", usrID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -1067,12 +972,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Group.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_GID));
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Delete", GetHashCode());
@@ -1097,7 +1002,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Group.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int gid)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.Remove", 0);
@@ -1138,16 +1043,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _GID;
private readonly int _GID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int gid)
{
_GID = gid;
}
public bool Exists => _exists;
public ExistsCommand(int gid) => _GID = gid;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Execute", GetHashCode());
@@ -1155,7 +1054,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -1177,7 +1076,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
GroupExtension _GroupExtension = new GroupExtension();
readonly GroupExtension _GroupExtension = new GroupExtension();
[Serializable()]
partial class GroupExtension : extensionBase
{
@@ -1186,14 +1085,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUsrID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUsrID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1222,57 +1115,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Group)
if (destType == typeof(string) && value is Group group)
{
// Return the ToString value
return ((Group)value).ToString();
return group.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create GroupExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Group
// {
// partial class GroupExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUsrID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _AID;
[System.ComponentModel.DataObjectField(true, true)]
public int AID
@@ -343,19 +337,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current GroupAssignment</returns>
protected override object GetIdValue()
{
return MyGroupAssignmentUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base GroupAssignment.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current GroupAssignment</returns>
//public override string ToString()
//{
// return base.ToString();
//}
protected override object GetIdValue() => MyGroupAssignmentUnique; // Absolutely Unique ID
public override bool IsDirty
{
get
@@ -370,18 +352,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyRole == null ? false : _MyRole.IsDirtyList(list)) || (_MyFolder == null ? false : _MyFolder.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyRole != null && _MyRole.IsDirtyList(list)) || (_MyFolder != null && _MyFolder.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRole == null ? true : _MyRole.IsValidList(list)) && (_MyFolder == null ? true : _MyFolder.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyRole == null || _MyRole.IsValidList(list)) && (_MyFolder == null || _MyFolder.IsValidList(list));
}
#endregion
#region ValidationRules
@@ -413,7 +392,7 @@ namespace VEPROMS.CSLA.Library
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -475,80 +454,22 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AID, "<Role(s)>");
//AuthorizationRules.AllowRead(RID, "<Role(s)>");
//AuthorizationRules.AllowWrite(RID, "<Role(s)>");
//AuthorizationRules.AllowRead(FolderID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FolderID, "<Role(s)>");
//AuthorizationRules.AllowRead(StartDate, "<Role(s)>");
//AuthorizationRules.AllowWrite(StartDate, "<Role(s)>");
//AuthorizationRules.AllowRead(EndDate, "<Role(s)>");
//AuthorizationRules.AllowWrite(EndDate, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _GroupAssignmentUnique = 0;
private static int GroupAssignmentUnique
{ get { return ++_GroupAssignmentUnique; } }
private int _MyGroupAssignmentUnique = GroupAssignmentUnique;
public int MyGroupAssignmentUnique // Absolutely Unique ID - Editable FK
{ get { return _MyGroupAssignmentUnique; } }
internal static GroupAssignment New(Role myRole, Folder myFolder)
{
return new GroupAssignment(myRole, myFolder);
}
internal static GroupAssignment Get(SafeDataReader dr)
{
return new GroupAssignment(dr);
}
private static int GroupAssignmentUnique => ++_GroupAssignmentUnique;
private readonly int _MyGroupAssignmentUnique = GroupAssignmentUnique;
// Absolutely Unique ID - Editable FK
public int MyGroupAssignmentUnique => _MyGroupAssignmentUnique;
internal static GroupAssignment New(Role myRole, Folder myFolder) => new GroupAssignment(myRole, myFolder);
internal static GroupAssignment Get(SafeDataReader dr) => new GroupAssignment(dr);
public GroupAssignment()
{
MarkAsChild();
@@ -579,15 +500,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~GroupAssignment()
{
_CountFinalized++;
@@ -639,32 +556,45 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Assignment.Add(cn, ref _AID, myGroup, _MyRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Assignment.Add(cn, ref _AID, myGroup, _MyRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID);
}
MarkOld();
}
internal void Update(Group myGroup)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Assignment.Update(cn, ref _AID, myGroup.GID, _RID, _FolderID, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Assignment.Update(cn, ref _AID, myGroup.GID, _RID, _FolderID, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Group myGroup)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Assignment.Remove(cn, _AID);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Assignment.Remove(cn, _AID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
GroupAssignmentExtension _GroupAssignmentExtension = new GroupAssignmentExtension();
readonly GroupAssignmentExtension _GroupAssignmentExtension = new GroupAssignmentExtension();
[Serializable()]
partial class GroupAssignmentExtension : extensionBase
{
@@ -673,18 +603,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual string DefaultStartDate
{
get { return DateTime.Now.ToShortDateString(); }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUsrID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual string DefaultStartDate => DateTime.Now.ToShortDateString();
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUsrID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -713,61 +634,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is GroupAssignment)
if (destType == typeof(string) && value is GroupAssignment assignment)
{
// Return the ToString value
return ((GroupAssignment)value).ToString();
return assignment.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create GroupAssignmentExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class GroupAssignment
// {
// partial class GroupAssignmentExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual SmartDate DefaultStartDate
// {
// get { return DateTime.Now.ToShortDateString(); }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUsrID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public GroupAssignment this[Assignment myAssignment]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public GroupAssignment this[Assignment myAssignment]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<GroupAssignment> Items
{
get { return base.Items; }
}
public GroupAssignment GetItem(Assignment myAssignment)
public new System.Collections.Generic.IList<GroupAssignment> Items => base.Items;
public GroupAssignment GetItem(Assignment myAssignment)
{
foreach (GroupAssignment assignment in this)
if (assignment.AID == myAssignment.AID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public GroupAssignment Add(Role myRole, Folder myFolder) // One to Many
{
GroupAssignment assignment = GroupAssignment.New(myRole, myFolder);
this.Add(assignment);
Add(assignment);
return assignment;
}
public void Remove(Assignment myAssignment)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (GroupAssignment child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (GroupAssignment child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static GroupAssignments New()
{
return new GroupAssignments();
}
internal static GroupAssignments Get(SafeDataReader dr)
{
return new GroupAssignments(dr);
}
public static GroupAssignments GetByGID(int gid)
#endregion
#region Factory Methods
internal static GroupAssignments New() => new GroupAssignments();
internal static GroupAssignments Get(SafeDataReader dr) => new GroupAssignments(dr);
public static GroupAssignments GetByGID(int gid)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on GroupAssignments.GetByGID", ex);
}
}
private GroupAssignments()
{
MarkAsChild();
}
internal GroupAssignments(SafeDataReader dr)
private GroupAssignments() => MarkAsChild();
internal GroupAssignments(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~GroupAssignments()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~GroupAssignments()
{
_CountFinalized++;
}
@@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(GroupAssignment.Get(dr));
this.RaiseListChangedEvents = true;
Add(GroupAssignment.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class GIDCriteria
{
public GIDCriteria(int gid)
{
_GID = gid;
}
private int _GID;
public GIDCriteria(int gid) => _GID = gid;
private int _GID;
public int GID
{
get { return _GID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(GIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupAssignments.DataPortal_FetchGID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new GroupAssignment(dr));
while (dr.Read()) Add(new GroupAssignment(dr));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupAssignments.DataPortal_FetchGID", ex);
throw new DbCslaException("GroupAssignments.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Group group)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
GroupAssignmentsPropertyDescriptor pd = new GroupAssignmentsPropertyDescriptor(this, i);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class GroupAssignmentsPropertyDescriptor : vlnListPropertyDescriptor
{
private GroupAssignment Item { get { return (GroupAssignment)_Item; } }
public GroupAssignmentsPropertyDescriptor(GroupAssignments collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is GroupAssignments)
if (destType == typeof(string) && value is GroupAssignments assignments)
{
// Return department and department role separated by comma.
return ((GroupAssignments)value).Items.Count.ToString() + " Assignments";
return $"{assignments.Items.Count} Assignments";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class GroupInfo : ReadOnlyBase<GroupInfo>, IDisposable
{
public event GroupInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<GroupInfo> _CacheList = new List<GroupInfo>();
protected static void AddToCache(GroupInfo groupInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(groupInfo)) _CacheList.Remove(groupInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<GroupInfo>> _CacheByPrimaryKey = new Dictionary<string, List<GroupInfo>>();
private static void ConvertListToDictionary()
{
@@ -79,16 +76,6 @@ namespace VEPROMS.CSLA.Library
get { return _ErrorMessage; }
}
protected Group _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _GID;
[System.ComponentModel.DataObjectField(true, true)]
public int GID
@@ -216,32 +203,19 @@ namespace VEPROMS.CSLA.Library
foreach (GroupInfo tmp in _CacheByPrimaryKey[_GID.ToString()])
tmp._GroupMembershipCount = -1; // This will cause the data to be requeried
}
// CSLATODO: Replace base GroupInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current GroupInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check GroupInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current GroupInfo</returns>
protected override object GetIdValue()
{
return MyGroupInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyGroupInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _GroupInfoUnique = 0;
private static int GroupInfoUnique
{ get { return ++_GroupInfoUnique; } }
private int _MyGroupInfoUnique = GroupInfoUnique;
public int MyGroupInfoUnique // Absolutely Unique ID - Info
{ get { return _MyGroupInfoUnique; } }
private static int GroupInfoUnique => ++_GroupInfoUnique;
private readonly int _MyGroupInfoUnique = GroupInfoUnique;
// Absolutely Unique ID - Info
public int MyGroupInfoUnique => _MyGroupInfoUnique;
protected GroupInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -250,15 +224,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~GroupInfo()
{
_CountFinalized++;
@@ -275,10 +245,7 @@ namespace VEPROMS.CSLA.Library
if (listGroupInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(GID.ToString()); // remove the list
}
public virtual Group Get()
{
return _Editable = Group.Get(_GID);
}
public virtual Group Get() => _Editable = Group.Get(_GID);
public static void Refresh(Group tmp)
{
string key = tmp.GID.ToString();
@@ -299,8 +266,6 @@ namespace VEPROMS.CSLA.Library
}
public static GroupInfo Get(int gid)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Group");
try
{
GroupInfo tmp = GetCachedByPrimaryKey(gid);
@@ -339,13 +304,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _GID;
public int GID
{ get { return _GID; } }
public PKCriteria(int gid)
{
_GID = gid;
}
private readonly int _GID;
public int GID => _GID;
public PKCriteria(int gid) => _GID = gid;
}
private void ReadData(SafeDataReader dr)
{
@@ -407,7 +368,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
GroupInfoExtension _GroupInfoExtension = new GroupInfoExtension();
readonly GroupInfoExtension _GroupInfoExtension = new GroupInfoExtension();
[Serializable()]
partial class GroupInfoExtension : extensionBase { }
[Serializable()]
@@ -423,10 +384,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is GroupInfo)
if (destType == typeof(string) && value is GroupInfo info)
{
// Return the ToString value
return ((GroupInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<GroupInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<GroupInfo> Items => base.Items;
public void AddEvents()
{
foreach (GroupInfo tmp in this)
{
@@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~GroupInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~GroupInfoList()
{
_CountFinalized++;
}
@@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on GroupInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all GroupInfo.
/// </summary>
public static void Reset()
{
_GroupInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static GroupInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<GroupInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on GroupInfoList.Get", ex);
// }
//}
private GroupInfoList()
/// <summary>
/// Reset the list of all GroupInfo.
/// </summary>
public static void Reset() => _GroupInfoList = null;
private GroupInfoList()
{ /* require use of factory methods */ }
#endregion
#region Data Access Portal
@@ -149,41 +127,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -205,7 +172,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class GroupInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private GroupInfo Item { get { return (GroupInfo)_Item; } }
public GroupInfoListPropertyDescriptor(GroupInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -214,10 +180,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is GroupInfoList)
if (destType == typeof(string) && value is GroupInfoList list)
{
// Return department and department role separated by comma.
return ((GroupInfoList)value).Items.Count.ToString() + " Groups";
return $"{list.Items.Count} Groups";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _UGID;
[System.ComponentModel.DataObjectField(true, true)]
public int UGID
@@ -323,19 +317,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current GroupMembership</returns>
protected override object GetIdValue()
{
return MyGroupMembershipUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base GroupMembership.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current GroupMembership</returns>
//public override string ToString()
//{
// return base.ToString();
//}
protected override object GetIdValue() => MyGroupMembershipUnique; // Absolutely Unique ID
public override bool IsDirty
{
get
@@ -350,7 +332,7 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyUser == null ? false : _MyUser.IsDirtyList(list));
return base.IsDirty || (_MyUser != null && _MyUser.IsDirtyList(list));
}
public override bool IsValid
{
@@ -359,9 +341,9 @@ namespace VEPROMS.CSLA.Library
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyUser == null ? true : _MyUser.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyUser == null || _MyUser.IsValidList(list));
}
#endregion
#region ValidationRules
@@ -391,8 +373,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -447,80 +429,22 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(UGID, "<Role(s)>");
//AuthorizationRules.AllowRead(UID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UID, "<Role(s)>");
//AuthorizationRules.AllowRead(StartDate, "<Role(s)>");
//AuthorizationRules.AllowWrite(StartDate, "<Role(s)>");
//AuthorizationRules.AllowRead(EndDate, "<Role(s)>");
//AuthorizationRules.AllowWrite(EndDate, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _GroupMembershipUnique = 0;
private static int GroupMembershipUnique
{ get { return ++_GroupMembershipUnique; } }
private int _MyGroupMembershipUnique = GroupMembershipUnique;
public int MyGroupMembershipUnique // Absolutely Unique ID - Editable FK
{ get { return _MyGroupMembershipUnique; } }
internal static GroupMembership New(User myUser)
{
return new GroupMembership(myUser);
}
internal static GroupMembership Get(SafeDataReader dr)
{
return new GroupMembership(dr);
}
private static int GroupMembershipUnique => ++_GroupMembershipUnique;
private readonly int _MyGroupMembershipUnique = GroupMembershipUnique;
// Absolutely Unique ID - Editable FK
public int MyGroupMembershipUnique => _MyGroupMembershipUnique;
internal static GroupMembership New(User myUser) => new GroupMembership(myUser);
internal static GroupMembership Get(SafeDataReader dr) => new GroupMembership(dr);
public GroupMembership()
{
MarkAsChild();
@@ -550,15 +474,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~GroupMembership()
{
_CountFinalized++;
@@ -608,33 +528,46 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Group myGroup)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Membership.Add(cn, ref _UGID, _MyUser, myGroup, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Membership.Add(cn, ref _UGID, _MyUser, myGroup, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID);
}
MarkOld();
}
internal void Update(Group myGroup)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Membership.Update(cn, ref _UGID, _UID, myGroup.GID, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Membership.Update(cn, ref _UGID, _UID, myGroup.GID, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Group myGroup)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Membership.Remove(cn, _UGID);
if (IsNew) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Membership.Remove(cn, _UGID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
GroupMembershipExtension _GroupMembershipExtension = new GroupMembershipExtension();
readonly GroupMembershipExtension _GroupMembershipExtension = new GroupMembershipExtension();
[Serializable()]
partial class GroupMembershipExtension : extensionBase
{
@@ -643,18 +576,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual string DefaultStartDate
{
get { return DateTime.Now.ToShortDateString(); }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUsrID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual string DefaultStartDate => DateTime.Now.ToShortDateString();
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUsrID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -683,61 +607,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is GroupMembership)
if (destType == typeof(string) && value is GroupMembership membership)
{
// Return the ToString value
return ((GroupMembership)value).ToString();
return membership.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create GroupMembershipExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class GroupMembership
// {
// partial class GroupMembershipExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual SmartDate DefaultStartDate
// {
// get { return DateTime.Now.ToShortDateString(); }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUsrID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public GroupMembership this[Membership myMembership]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public GroupMembership this[Membership myMembership]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<GroupMembership> Items
{
get { return base.Items; }
}
public GroupMembership GetItem(Membership myMembership)
public new System.Collections.Generic.IList<GroupMembership> Items => base.Items;
public GroupMembership GetItem(Membership myMembership)
{
foreach (GroupMembership membership in this)
if (membership.UGID == myMembership.UGID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public GroupMembership Add(User myUser) // One to Many
{
GroupMembership membership = GroupMembership.New(myUser);
this.Add(membership);
Add(membership);
return membership;
}
public void Remove(Membership myMembership)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (GroupMembership child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (GroupMembership child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static GroupMemberships New()
{
return new GroupMemberships();
}
internal static GroupMemberships Get(SafeDataReader dr)
{
return new GroupMemberships(dr);
}
public static GroupMemberships GetByGID(int gid)
#endregion
#region Factory Methods
internal static GroupMemberships New() => new GroupMemberships();
internal static GroupMemberships Get(SafeDataReader dr) => new GroupMemberships(dr);
public static GroupMemberships GetByGID(int gid)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on GroupMemberships.GetByGID", ex);
}
}
private GroupMemberships()
{
MarkAsChild();
}
internal GroupMemberships(SafeDataReader dr)
private GroupMemberships() => MarkAsChild();
internal GroupMemberships(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~GroupMemberships()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~GroupMemberships()
{
_CountFinalized++;
}
@@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(GroupMembership.Get(dr));
this.RaiseListChangedEvents = true;
Add(GroupMembership.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class GIDCriteria
{
public GIDCriteria(int gid)
{
_GID = gid;
}
private int _GID;
public GIDCriteria(int gid) => _GID = gid;
private int _GID;
public int GID
{
get { return _GID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(GIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupMemberships.DataPortal_FetchGID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new GroupMembership(dr));
while (dr.Read()) Add(new GroupMembership(dr));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupMemberships.DataPortal_FetchGID", ex);
throw new DbCslaException("GroupMemberships.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Group group)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
GroupMembershipsPropertyDescriptor pd = new GroupMembershipsPropertyDescriptor(this, i);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class GroupMembershipsPropertyDescriptor : vlnListPropertyDescriptor
{
private GroupMembership Item { get { return (GroupMembership)_Item; } }
public GroupMembershipsPropertyDescriptor(GroupMemberships collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is GroupMemberships)
if (destType == typeof(string) && value is GroupMemberships memberships)
{
// Return department and department role separated by comma.
return ((GroupMemberships)value).Items.Count.ToString() + " Memberships";
return $"{memberships.Items.Count} Memberships";
}
return base.ConvertTo(context, culture, value, destType);
}
+123 -269
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty)
refreshImages.Add(this);
}
private void ClearRefreshList()
{
_RefreshImages = new List<Image>();
}
private void ClearRefreshList() => _RefreshImages = new List<Image>();
private void BuildRefreshList()
{
ClearRefreshList();
@@ -56,16 +51,18 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Image> _CacheList = new List<Image>();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
protected static void AddToCache(Image image)
{
// B2021-147 commented out to fix out of memory bug
//if (!_CacheList.Contains(image)) _CacheList.Add(image); // In AddToCache
}
protected static void RemoveFromCache(Image image)
{
while (_CacheList.Contains(image)) _CacheList.Remove(image); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Image>> _CacheByPrimaryKey = new Dictionary<string, List<Image>>();
private static void ConvertListToDictionary()
{
@@ -91,10 +88,7 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)]
public int ContentID
@@ -232,40 +226,18 @@ namespace VEPROMS.CSLA.Library
}
}
private byte[] _LastChanged = new byte[8];//timestamp
public override bool IsDirty
{
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
// CSLATODO: Replace base Image.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Image</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty => base.IsDirty;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsDirtyList(List<object> list) => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
public bool IsValidList(List<object> list) => (IsNew && !IsDirty) || base.IsValid;
// CSLATODO: Check Image.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Image</returns>
protected override object GetIdValue()
{
return MyImageUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyImageUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -293,8 +265,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -321,35 +293,11 @@ namespace VEPROMS.CSLA.Library
_ImageExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(ImageType, "<Role(s)>");
//AuthorizationRules.AllowRead(FileName, "<Role(s)>");
//AuthorizationRules.AllowRead(Data, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ImageType, "<Role(s)>");
//AuthorizationRules.AllowWrite(FileName, "<Role(s)>");
//AuthorizationRules.AllowWrite(Data, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_ImageExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -357,42 +305,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_ImageExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _ImageUnique = 0;
protected static int ImageUnique
{ get { return ++_ImageUnique; } }
private int _MyImageUnique = ImageUnique;
public int MyImageUnique // Absolutely Unique ID - Editable
{ get { return _MyImageUnique; } }
protected static int ImageUnique => ++_ImageUnique;
private readonly int _MyImageUnique = ImageUnique;
// Absolutely Unique ID - Editable
public int MyImageUnique => _MyImageUnique;
protected Image()
{/* require use of factory methods */
AddToCache(this);
@@ -401,15 +321,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Image()
{
_CountFinalized++;
@@ -434,8 +350,6 @@ namespace VEPROMS.CSLA.Library
}
public static Image New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Image");
try
{
return DataPortal.Create<Image>();
@@ -516,8 +430,6 @@ namespace VEPROMS.CSLA.Library
}
public static Image Get(int contentID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Image");
try
{
Image tmp = GetCachedByPrimaryKey(contentID);
@@ -543,14 +455,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Image(dr);
return null;
}
internal Image(SafeDataReader dr)
{
ReadData(dr);
}
internal Image(SafeDataReader dr) => ReadData(dr);
public static void Delete(int contentID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Image");
try
{
DataPortal.Delete(new PKCriteria(contentID));
@@ -562,12 +469,6 @@ namespace VEPROMS.CSLA.Library
}
public override Image Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Image");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Image");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Image");
try
{
BuildRefreshList();
@@ -587,13 +488,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _ContentID;
public int ContentID
{ get { return _ContentID; } }
public PKCriteria(int contentID)
{
_ContentID = contentID;
}
private readonly int _ContentID;
public int ContentID => _ContentID;
public PKCriteria(int contentID) => _ContentID = contentID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -665,7 +562,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Image.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -690,35 +587,41 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addImage";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@ImageType", _ImageType);
cm.Parameters.AddWithValue("@FileName", _FileName);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addImage";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@ImageType", _ImageType);
cm.Parameters.AddWithValue("@FileName", _FileName);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.SQLInsert", GetHashCode());
@@ -730,7 +633,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Image.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, Content myContent, int imageType, string fileName, byte[] data, string config, DateTime dts, string userID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.Add", 0);
@@ -750,8 +653,10 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -765,7 +670,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Image.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -788,40 +693,46 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateImage";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@ImageType", _ImageType);
cm.Parameters.AddWithValue("@FileName", _FileName);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateImage";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ContentID", ContentID);
cm.Parameters.AddWithValue("@ImageType", _ImageType);
cm.Parameters.AddWithValue("@FileName", _FileName);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -834,18 +745,22 @@ namespace VEPROMS.CSLA.Library
}
internal void Update(Content content)
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Image.Add(cn, content, _ImageType, _FileName, _Data, _Config, _DTS, _UserID);
else
_LastChanged = Image.Update(cn, content.ContentID, _ImageType, _FileName, _Data, _Config, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = Image.Add(cn, content, _ImageType, _FileName, _Data, _Config, _DTS, _UserID);
else
_LastChanged = Image.Update(cn, content.ContentID, _ImageType, _FileName, _Data, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, int contentID, int imageType, string fileName, byte[] data, string config, DateTime dts, string userID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.Update", 0);
@@ -866,8 +781,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -881,12 +798,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Image.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_ContentID));
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.DataPortal_Delete", GetHashCode());
@@ -911,7 +828,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Image.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int contentID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.Remove", 0);
@@ -952,16 +869,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _ContentID;
private readonly int _ContentID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int contentID)
{
_ContentID = contentID;
}
public bool Exists => _exists;
public ExistsCommand(int contentID) => _ContentID = contentID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.DataPortal_Execute", GetHashCode());
@@ -969,7 +880,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -991,7 +902,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
ImageExtension _ImageExtension = new ImageExtension();
readonly ImageExtension _ImageExtension = new ImageExtension();
[Serializable()]
partial class ImageExtension : extensionBase
{
@@ -1000,18 +911,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultImageType
{
get { return 1; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultImageType => 1;
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1040,61 +942,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Image)
if (destType == typeof(string) && value is Image myimage)
{
// Return the ToString value
return ((Image)value).ToString();
return myimage.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create ImageExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Image
// {
// partial class ImageExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultImageType
// {
// get { return 1; }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
+103 -237
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty)
refreshImageAudits.Add(this);
}
private void ClearRefreshList()
{
_RefreshImageAudits = new List<ImageAudit>();
}
private void ClearRefreshList() => _RefreshImageAudits = new List<ImageAudit>();
private void BuildRefreshList()
{
ClearRefreshList();
@@ -56,6 +51,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<ImageAudit> _CacheList = new List<ImageAudit>();
protected static void AddToCache(ImageAudit imageAudit)
{
@@ -65,6 +61,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(imageAudit)) _CacheList.Remove(imageAudit); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<ImageAudit>> _CacheByPrimaryKey = new Dictionary<string, List<ImageAudit>>();
private static void ConvertListToDictionary()
{
@@ -90,15 +87,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextAuditID = -1;
public static int NextAuditID
{
get { return _nextAuditID--; }
}
public static int NextAuditID => _nextAuditID--;
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -256,40 +247,14 @@ namespace VEPROMS.CSLA.Library
}
}
}
public override bool IsDirty
{
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
// CSLATODO: Replace base ImageAudit.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ImageAudit</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
// CSLATODO: Check ImageAudit.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current ImageAudit</returns>
protected override object GetIdValue()
{
return MyImageAuditUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyImageAuditUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -317,8 +282,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -345,39 +310,11 @@ namespace VEPROMS.CSLA.Library
_ImageAuditExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AuditID, "<Role(s)>");
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(ImageType, "<Role(s)>");
//AuthorizationRules.AllowRead(FileName, "<Role(s)>");
//AuthorizationRules.AllowRead(Data, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(DeleteStatus, "<Role(s)>");
//AuthorizationRules.AllowWrite(ContentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ImageType, "<Role(s)>");
//AuthorizationRules.AllowWrite(FileName, "<Role(s)>");
//AuthorizationRules.AllowWrite(Data, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DeleteStatus, "<Role(s)>");
_ImageAuditExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -385,42 +322,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_ImageAuditExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _ImageAuditUnique = 0;
protected static int ImageAuditUnique
{ get { return ++_ImageAuditUnique; } }
private int _MyImageAuditUnique = ImageAuditUnique;
public int MyImageAuditUnique // Absolutely Unique ID - Editable
{ get { return _MyImageAuditUnique; } }
protected static int ImageAuditUnique => ++_ImageAuditUnique;
private readonly int _MyImageAuditUnique = ImageAuditUnique;
// Absolutely Unique ID - Editable
public int MyImageAuditUnique => _MyImageAuditUnique;
protected ImageAudit()
{/* require use of factory methods */
AddToCache(this);
@@ -429,15 +338,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ImageAudit()
{
_CountFinalized++;
@@ -462,8 +367,6 @@ namespace VEPROMS.CSLA.Library
}
public static ImageAudit New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a ImageAudit");
try
{
return DataPortal.Create<ImageAudit>();
@@ -516,8 +419,6 @@ namespace VEPROMS.CSLA.Library
}
public static ImageAudit Get(long auditID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a ImageAudit");
try
{
ImageAudit tmp = GetCachedByPrimaryKey(auditID);
@@ -543,14 +444,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new ImageAudit(dr);
return null;
}
internal ImageAudit(SafeDataReader dr)
{
ReadData(dr);
}
internal ImageAudit(SafeDataReader dr) => ReadData(dr);
public static void Delete(long auditID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a ImageAudit");
try
{
DataPortal.Delete(new PKCriteria(auditID));
@@ -562,12 +458,6 @@ namespace VEPROMS.CSLA.Library
}
public override ImageAudit Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a ImageAudit");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a ImageAudit");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a ImageAudit");
try
{
BuildRefreshList();
@@ -587,13 +477,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private long _AuditID;
public long AuditID
{ get { return _AuditID; } }
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
private readonly long _AuditID;
public long AuditID => _AuditID;
public PKCriteria(long auditID) => _AuditID = auditID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -664,7 +550,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ImageAudit.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -689,36 +575,42 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addImageAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@ImageType", _ImageType);
cm.Parameters.AddWithValue("@FileName", _FileName);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addImageAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@ImageType", _ImageType);
cm.Parameters.AddWithValue("@FileName", _FileName);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.SQLInsert", GetHashCode());
@@ -730,7 +622,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ImageAudit.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Add(SqlConnection cn, ref long auditID, int contentID, int imageType, string fileName, byte[] data, string config, DateTime dts, string userID, int deleteStatus)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.Add", 0);
@@ -751,8 +643,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -767,7 +661,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ImageAudit.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -790,37 +684,41 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateImageAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@ImageType", _ImageType);
cm.Parameters.AddWithValue("@FileName", _FileName);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateImageAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@ImageType", _ImageType);
cm.Parameters.AddWithValue("@FileName", _FileName);
cm.Parameters.AddWithValue("@Data", _Data);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -833,18 +731,22 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
ImageAudit.Add(cn, ref _AuditID, _ContentID, _ImageType, _FileName, _Data, _Config, _DTS, _UserID, _DeleteStatus);
else
ImageAudit.Update(cn, ref _AuditID, _ContentID, _ImageType, _FileName, _Data, _Config, _DTS, _UserID, _DeleteStatus);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
ImageAudit.Add(cn, ref _AuditID, _ContentID, _ImageType, _FileName, _Data, _Config, _DTS, _UserID, _DeleteStatus);
else
ImageAudit.Update(cn, ref _AuditID, _ContentID, _ImageType, _FileName, _Data, _Config, _DTS, _UserID, _DeleteStatus);
}
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Update(SqlConnection cn, ref long auditID, int contentID, int imageType, string fileName, byte[] data, string config, DateTime dts, string userID, int deleteStatus)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.Update", 0);
@@ -878,12 +780,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ImageAudit.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_AuditID));
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.DataPortal_Delete", GetHashCode());
@@ -908,7 +810,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ImageAudit.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, long auditID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.Remove", 0);
@@ -934,7 +836,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
ImageAuditExtension _ImageAuditExtension = new ImageAuditExtension();
readonly ImageAuditExtension _ImageAuditExtension = new ImageAuditExtension();
[Serializable()]
partial class ImageAuditExtension : extensionBase
{
@@ -971,49 +873,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ImageAudit)
if (destType == typeof(string) && value is ImageAudit audit)
{
// Return the ToString value
return ((ImageAudit)value).ToString();
return audit.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create ImageAuditExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ImageAudit
// {
// partial class ImageAuditExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class ImageAuditInfo : ReadOnlyBase<ImageAuditInfo>, IDisposable
{
public event ImageAuditInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<ImageAuditInfo> _CacheList = new List<ImageAuditInfo>();
protected static void AddToCache(ImageAuditInfo imageAuditInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(imageAuditInfo)) _CacheList.Remove(imageAuditInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<ImageAuditInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ImageAuditInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected ImageAudit _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -171,32 +155,19 @@ namespace VEPROMS.CSLA.Library
return _DeleteStatus;
}
}
// CSLATODO: Replace base ImageAuditInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ImageAuditInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check ImageAuditInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current ImageAuditInfo</returns>
protected override object GetIdValue()
{
return MyImageAuditInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyImageAuditInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _ImageAuditInfoUnique = 0;
private static int ImageAuditInfoUnique
{ get { return ++_ImageAuditInfoUnique; } }
private int _MyImageAuditInfoUnique = ImageAuditInfoUnique;
public int MyImageAuditInfoUnique // Absolutely Unique ID - Info
{ get { return _MyImageAuditInfoUnique; } }
private static int ImageAuditInfoUnique => ++_ImageAuditInfoUnique;
private readonly int _MyImageAuditInfoUnique = ImageAuditInfoUnique;
// Absolutely Unique ID - Info
public int MyImageAuditInfoUnique => _MyImageAuditInfoUnique;
protected ImageAuditInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -205,15 +176,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ImageAuditInfo()
{
_CountFinalized++;
@@ -230,10 +197,7 @@ namespace VEPROMS.CSLA.Library
if (listImageAuditInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list
}
public virtual ImageAudit Get()
{
return _Editable = ImageAudit.Get(_AuditID);
}
public virtual ImageAudit Get() => _Editable = ImageAudit.Get(_AuditID);
public static void Refresh(ImageAudit tmp)
{
string key = tmp.AuditID.ToString();
@@ -257,8 +221,6 @@ namespace VEPROMS.CSLA.Library
}
public static ImageAuditInfo Get(long auditID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a ImageAudit");
try
{
ImageAuditInfo tmp = GetCachedByPrimaryKey(auditID);
@@ -297,13 +259,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private long _AuditID;
public long AuditID
{ get { return _AuditID; } }
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
private readonly long _AuditID;
public long AuditID => _AuditID;
public PKCriteria(long auditID) => _AuditID = auditID;
}
private void ReadData(SafeDataReader dr)
{
@@ -366,7 +324,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
ImageAuditInfoExtension _ImageAuditInfoExtension = new ImageAuditInfoExtension();
readonly ImageAuditInfoExtension _ImageAuditInfoExtension = new ImageAuditInfoExtension();
[Serializable()]
partial class ImageAuditInfoExtension : extensionBase { }
[Serializable()]
@@ -382,10 +340,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ImageAuditInfo)
if (destType == typeof(string) && value is ImageAuditInfo info)
{
// Return the ToString value
return ((ImageAuditInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<ImageAuditInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<ImageAuditInfo> Items => base.Items;
public void AddEvents()
{
foreach (ImageAuditInfo tmp in this)
{
@@ -51,16 +48,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ImageAuditInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ImageAuditInfoList()
{
_CountFinalized++;
}
@@ -97,26 +90,11 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ImageAuditInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all ImageAuditInfo.
/// </summary>
public static void Reset()
{
_ImageAuditInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static ImageAuditInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<ImageAuditInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on ImageAuditInfoList.Get", ex);
// }
//}
private ImageAuditInfoList()
/// <summary>
/// Reset the list of all ImageAuditInfo.
/// </summary>
public static void Reset() => _ImageAuditInfoList = null;
private ImageAuditInfoList()
{ /* require use of factory methods */ }
#endregion
#region Data Access Portal
@@ -149,41 +127,30 @@ namespace VEPROMS.CSLA.Library
}
this.RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
@@ -205,7 +172,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class ImageAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private ImageAuditInfo Item { get { return (ImageAuditInfo)_Item; } }
public ImageAuditInfoListPropertyDescriptor(ImageAuditInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -214,10 +180,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ImageAuditInfoList)
if (destType == typeof(string) && value is ImageAuditInfoList list)
{
// Return department and department role separated by comma.
return ((ImageAuditInfoList)value).Items.Count.ToString() + " ImageAudits";
return $"{list.Items.Count} ImageAudits";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class ImageInfo : ReadOnlyBase<ImageInfo>, IDisposable
{
public event ImageInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<ImageInfo> _CacheList = new List<ImageInfo>();
protected static void AddToCache(ImageInfo imageInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(imageInfo)) _CacheList.Remove(imageInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<ImageInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ImageInfo>>();
private static void ConvertListToDictionary()
{
@@ -70,21 +67,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected Image _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)]
public int ContentID
@@ -164,32 +148,19 @@ namespace VEPROMS.CSLA.Library
return _UserID;
}
}
// CSLATODO: Replace base ImageInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ImageInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check ImageInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current ImageInfo</returns>
protected override object GetIdValue()
{
return MyImageInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyImageInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _ImageInfoUnique = 0;
private static int ImageInfoUnique
{ get { return ++_ImageInfoUnique; } }
private int _MyImageInfoUnique = ImageInfoUnique;
public int MyImageInfoUnique // Absolutely Unique ID - Info
{ get { return _MyImageInfoUnique; } }
private static int ImageInfoUnique => ++_ImageInfoUnique;
private readonly int _MyImageInfoUnique = ImageInfoUnique;
// Absolutely Unique ID - Info
public int MyImageInfoUnique => _MyImageInfoUnique;
protected ImageInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -198,15 +169,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ImageInfo()
{
_CountFinalized++;
@@ -223,10 +190,7 @@ namespace VEPROMS.CSLA.Library
if (listImageInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list
}
public virtual Image Get()
{
return _Editable = Image.Get(_ContentID);
}
public virtual Image Get() => _Editable = Image.Get(_ContentID);
public static void Refresh(Image tmp)
{
string key = tmp.ContentID.ToString();
@@ -244,20 +208,10 @@ namespace VEPROMS.CSLA.Library
_DTS = tmp.DTS;
_UserID = tmp.UserID;
_ImageInfoExtension.Refresh(this);
//RHM Removed 20090724 - Duplicates function of code above.
// - Dispose caused error when a new step was added.
// - Resequence of transitions did not work properly.
// if(_MyContent != null)
// {
// _MyContent.Dispose();// Dispose related value
// _MyContent = null;// Reset related value
// }
OnChange();// raise an event
}
public static ImageInfo Get(int contentID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Image");
try
{
ImageInfo tmp = GetCachedByPrimaryKey(contentID);
@@ -296,13 +250,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _ContentID;
public int ContentID
{ get { return _ContentID; } }
public PKCriteria(int contentID)
{
_ContentID = contentID;
}
private readonly int _ContentID;
public int ContentID => _ContentID;
public PKCriteria(int contentID) => _ContentID = contentID;
}
private void ReadData(SafeDataReader dr)
{
@@ -363,7 +313,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
ImageInfoExtension _ImageInfoExtension = new ImageInfoExtension();
readonly ImageInfoExtension _ImageInfoExtension = new ImageInfoExtension();
[Serializable()]
partial class ImageInfoExtension : extensionBase { }
[Serializable()]
@@ -379,10 +329,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ImageInfo)
if (destType == typeof(string) && value is ImageInfo info)
{
// Return the ToString value
return ((ImageInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
+161 -324
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -133,6 +131,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<Item> _CacheList = new List<Item>();
protected static void AddToCache(Item item)
{
@@ -142,6 +141,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(item)) _CacheList.Remove(item); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Item>> _CacheByPrimaryKey = new Dictionary<string, List<Item>>();
private static void ConvertListToDictionary()
{
@@ -167,15 +167,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextItemID = -1;
public static int NextItemID
{
get { return _nextItemID--; }
}
public static int NextItemID => _nextItemID--;
private int _ItemID;
[System.ComponentModel.DataObjectField(true, true)]
public int ItemID
@@ -315,10 +309,7 @@ namespace VEPROMS.CSLA.Library
return _ItemAnnotations;
}
}
public void Reset_ItemAnnotations()
{
_ItemAnnotationCount = -1;
}
public void Reset_ItemAnnotations() => _ItemAnnotationCount = -1;
private int _ItemDocVersionCount = 0;
/// <summary>
/// Count of ItemDocVersions for this Item
@@ -350,10 +341,7 @@ namespace VEPROMS.CSLA.Library
return _ItemDocVersions;
}
}
public void Reset_ItemDocVersions()
{
_ItemDocVersionCount = -1;
}
public void Reset_ItemDocVersions() => _ItemDocVersionCount = -1;
private int _NextItemCount = 0;
/// <summary>
/// Count of NextItems for this Item
@@ -385,10 +373,7 @@ namespace VEPROMS.CSLA.Library
return _NextItems;
}
}
public void Reset_NextItems()
{
_NextItemCount = -1;
}
public void Reset_NextItems() => _NextItemCount = -1;
private int _ItemPartCount = 0;
/// <summary>
/// Count of ItemParts for this Item
@@ -420,10 +405,7 @@ namespace VEPROMS.CSLA.Library
return _ItemParts;
}
}
public void Reset_ItemParts()
{
_ItemPartCount = -1;
}
public void Reset_ItemParts() => _ItemPartCount = -1;
private int _ItemTransition_RangeIDCount = 0;
/// <summary>
/// Count of ItemTransitions for this Item
@@ -455,10 +437,7 @@ namespace VEPROMS.CSLA.Library
return _ItemTransitions_RangeID;
}
}
public void Reset_ItemTransitions_RangeID()
{
_ItemTransition_RangeIDCount = -1;
}
public void Reset_ItemTransitions_RangeID() => _ItemTransition_RangeIDCount = -1;
private int _ItemTransition_ToIDCount = 0;
/// <summary>
/// Count of ItemTransitions for this Item
@@ -490,10 +469,7 @@ namespace VEPROMS.CSLA.Library
return _ItemTransitions_ToID;
}
}
public void Reset_ItemTransitions_ToID()
{
_ItemTransition_ToIDCount = -1;
}
public void Reset_ItemTransitions_ToID() => _ItemTransition_ToIDCount = -1;
public override bool IsDirty
{
get
@@ -508,37 +484,22 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_ItemAnnotations == null ? false : _ItemAnnotations.IsDirtyList(list)) || (_ItemDocVersions == null ? false : _ItemDocVersions.IsDirtyList(list)) || (_NextItems == null ? false : _NextItems.IsDirtyList(list)) || (_ItemParts == null ? false : _ItemParts.IsDirtyList(list)) || (_ItemTransitions_RangeID == null ? false : _ItemTransitions_RangeID.IsDirtyList(list)) || (_ItemTransitions_ToID == null ? false : _ItemTransitions_ToID.IsDirtyList(list)) || (_MyContent == null ? false : _MyContent.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_ItemAnnotations != null && _ItemAnnotations.IsDirtyList(list)) || (_ItemDocVersions != null && _ItemDocVersions.IsDirtyList(list)) || (_NextItems != null && _NextItems.IsDirtyList(list)) || (_ItemParts != null && _ItemParts.IsDirtyList(list)) || (_ItemTransitions_RangeID != null && _ItemTransitions_RangeID.IsDirtyList(list)) || (_ItemTransitions_ToID != null && _ItemTransitions_ToID.IsDirtyList(list)) || (_MyContent != null && _MyContent.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_ItemAnnotations == null ? true : _ItemAnnotations.IsValidList(list)) && (_ItemDocVersions == null ? true : _ItemDocVersions.IsValidList(list)) && (_NextItems == null ? true : _NextItems.IsValidList(list)) && (_ItemParts == null ? true : _ItemParts.IsValidList(list)) && (_ItemTransitions_RangeID == null ? true : _ItemTransitions_RangeID.IsValidList(list)) && (_ItemTransitions_ToID == null ? true : _ItemTransitions_ToID.IsValidList(list)) && (_MyContent == null ? true : _MyContent.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_ItemAnnotations == null || _ItemAnnotations.IsValidList(list)) && (_ItemDocVersions == null || _ItemDocVersions.IsValidList(list)) && (_NextItems == null || _NextItems.IsValidList(list)) && (_ItemParts == null || _ItemParts.IsValidList(list)) && (_ItemTransitions_RangeID == null || _ItemTransitions_RangeID.IsValidList(list)) && (_ItemTransitions_ToID == null || _ItemTransitions_ToID.IsValidList(list)) && (_MyContent == null || _MyContent.IsValidList(list));
}
// CSLATODO: Replace base Item.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Item</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Item.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current Item</returns>
protected override object GetIdValue()
{
return MyItemUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyItemUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -573,8 +534,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -603,31 +564,11 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(PreviousID, "<Role(s)>");
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(PreviousID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ContentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_ItemExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -635,60 +576,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_ItemExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
/// <summary>
/// determines if related records (Foreign Keys) will keep this Item from being deleted
/// </summary>
public bool CanDelete
{
get
{
// Check to make sure that there are not any related records
int usedByCount = 0;
usedByCount += _ItemAnnotationCount;
usedByCount += _ItemDocVersionCount;
usedByCount += _ItemPartCount;
usedByCount += _ItemTransition_RangeIDCount;
usedByCount += _ItemTransition_ToIDCount;
usedByCount += _NextItemCount;
return (usedByCount == 0);
}
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _ItemUnique = 0;
protected static int ItemUnique
{ get { return ++_ItemUnique; } }
private int _MyItemUnique = ItemUnique;
public int MyItemUnique // Absolutely Unique ID - Editable
{ get { return _MyItemUnique; } }
protected static int ItemUnique => ++_ItemUnique;
private readonly int _MyItemUnique = ItemUnique;
// Absolutely Unique ID - Editable
public int MyItemUnique => _MyItemUnique;
protected Item()
{/* require use of factory methods */
AddToCache(this);
@@ -697,15 +592,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~Item()
{
_CountFinalized++;
@@ -732,16 +623,6 @@ namespace VEPROMS.CSLA.Library
_ItemTransitions_RangeID = null;
if (_ItemTransitions_ToID != null)
_ItemTransitions_ToID = null;
//if (_MyPrevious != null)
// _MyPrevious = null;
//if (_NextItems != null)
// _NextItems = null;
//if (_ItemAnnotations != null)
// _ItemAnnotations.Dispose();
//if (_ItemDocVersions != null)
// _ItemDocVersions = null;
//if (_ItemParts != null)
// _ItemParts = null;
}
private void RemoveFromDictionaries()
{
@@ -756,8 +637,6 @@ namespace VEPROMS.CSLA.Library
}
public static Item New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Item");
try
{
return DataPortal.Create<Item>();
@@ -823,8 +702,6 @@ namespace VEPROMS.CSLA.Library
}
public static Item Get(int itemID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Item");
try
{
Item tmp = GetCachedByPrimaryKey(itemID);
@@ -850,15 +727,14 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Item(dr, previous);
return null;
}
internal Item(SafeDataReader dr)
{
ReadData(dr);
}
internal Item(SafeDataReader dr) => ReadData(dr);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
private Item(SafeDataReader dr, Item previous)
{
ReadData(dr);
MarkAsChild();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal Item(SafeDataReader dr, int parentID)
{
ReadData(dr);
@@ -866,8 +742,6 @@ namespace VEPROMS.CSLA.Library
}
public static void Delete(int itemID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Item");
try
{
DataPortal.Delete(new PKCriteria(itemID));
@@ -879,12 +753,6 @@ namespace VEPROMS.CSLA.Library
}
public override Item Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Item");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Item");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Item");
try
{
BuildRefreshList();
@@ -904,13 +772,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _ItemID;
public int ItemID
{ get { return _ItemID; } }
public PKCriteria(int itemID)
{
_ItemID = itemID;
}
private readonly int _ItemID;
public int ItemID => _ItemID;
public PKCriteria(int itemID) => _ItemID = itemID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -1000,7 +864,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Item.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -1025,45 +889,53 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyContent != null) _MyContent.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyContent?.Update();
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addItem";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@PreviousID", PreviousID);
cm.Parameters.AddWithValue("@ContentID", ContentID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_ItemID = new SqlParameter("@newItemID", SqlDbType.Int);
param_ItemID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_ItemID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_ItemID = (int)cm.Parameters["@newItemID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addItem";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@PreviousID", PreviousID);
cm.Parameters.AddWithValue("@ContentID", ContentID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_ItemID = new SqlParameter("@newItemID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_ItemID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_ItemID = (int)cm.Parameters["@newItemID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_ItemAnnotations != null) _ItemAnnotations.Update(this);
if (_ItemDocVersions != null) _ItemDocVersions.Update(this);
if (_NextItems != null) _NextItems.Update(this);
if (_ItemParts != null) _ItemParts.Update(this);
if (_ItemTransitions_RangeID != null) _ItemTransitions_RangeID.Update(this);
if (_ItemTransitions_ToID != null) _ItemTransitions_ToID.Update(this);
_ItemAnnotations?.Update(this);
_ItemDocVersions?.Update(this);
_NextItems?.Update(this);
_ItemParts?.Update(this);
_ItemTransitions_RangeID?.Update(this);
_ItemTransitions_ToID?.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.SQLInsert", GetHashCode());
}
catch (Exception ex)
@@ -1073,7 +945,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Item.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int itemID, Item myPrevious, Content myContent, DateTime dts, string userID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.Add", 0);
@@ -1090,11 +962,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns
SqlParameter param_ItemID = new SqlParameter("@newItemID", SqlDbType.Int);
param_ItemID.Direction = ParameterDirection.Output;
SqlParameter param_ItemID = new SqlParameter("@newItemID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_ItemID);
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -1178,7 +1054,7 @@ namespace VEPROMS.CSLA.Library
return dt;
}
catch (Exception ex)
catch (Exception)
{
//B2025-004
//if it fails loading previously open tabs, simply treat it as if no tabs were open
@@ -1189,7 +1065,7 @@ namespace VEPROMS.CSLA.Library
}
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -1212,47 +1088,53 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.SQLUpdate", GetHashCode());
try
{
if (_MyContent != null) _MyContent.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyContent?.Update();
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateItem";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ItemID", _ItemID);
cm.Parameters.AddWithValue("@PreviousID", PreviousID);
cm.Parameters.AddWithValue("@ContentID", ContentID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateItem";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ItemID", _ItemID);
cm.Parameters.AddWithValue("@PreviousID", PreviousID);
cm.Parameters.AddWithValue("@ContentID", ContentID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
}
MarkOld();
// use the open connection to update child objects
if (_ItemAnnotations != null) _ItemAnnotations.Update(this);
if (_ItemDocVersions != null) _ItemDocVersions.Update(this);
if (_NextItems != null) _NextItems.Update(this);
if (_ItemParts != null) _ItemParts.Update(this);
if (_ItemTransitions_RangeID != null) _ItemTransitions_RangeID.Update(this);
if (_ItemTransitions_ToID != null) _ItemTransitions_ToID.Update(this);
_ItemAnnotations?.Update(this);
_ItemDocVersions?.Update(this);
_NextItems?.Update(this);
_ItemParts?.Update(this);
_ItemTransitions_RangeID?.Update(this);
_ItemTransitions_ToID?.Update(this);
}
catch (Exception ex)
{
@@ -1263,34 +1145,43 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = Item.Add(cn, ref _ItemID, _MyPrevious, _MyContent, _DTS, _UserID);
else
_LastChanged = Item.Update(cn, ref _ItemID, _PreviousID, _ContentID, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
_LastChanged = Item.Add(cn, ref _ItemID, _MyPrevious, _MyContent, _DTS, _UserID);
else
_LastChanged = Item.Update(cn, ref _ItemID, _PreviousID, _ContentID, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
if (_ItemAnnotations != null) _ItemAnnotations.Update(this);
if (_ItemDocVersions != null) _ItemDocVersions.Update(this);
if (_NextItems != null) _NextItems.Update(this);
if (_ItemParts != null) _ItemParts.Update(this);
if (_ItemTransitions_RangeID != null) _ItemTransitions_RangeID.Update(this);
if (_ItemTransitions_ToID != null) _ItemTransitions_ToID.Update(this);
_ItemAnnotations?.Update(this);
_ItemDocVersions?.Update(this);
_NextItems?.Update(this);
_ItemParts?.Update(this);
_ItemTransitions_RangeID?.Update(this);
_ItemTransitions_ToID?.Update(this);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Item item)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Item.Remove(cn, _ItemID);
if (IsNew) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Item.Remove(cn, _ItemID);
}
MarkNew();
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int itemID, int? previousID, int contentID, DateTime dts, string userID, ref byte[] lastChanged)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.Update", 0);
@@ -1309,8 +1200,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_LastChanged);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -1324,12 +1217,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Item.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_ItemID));
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Delete", GetHashCode());
@@ -1354,7 +1247,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Item.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int itemID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.Remove", 0);
@@ -1395,16 +1288,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _ItemID;
private readonly int _ItemID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int itemID)
{
_ItemID = itemID;
}
public bool Exists => _exists;
public ExistsCommand(int itemID) => _ItemID = itemID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Execute", GetHashCode());
@@ -1412,7 +1299,7 @@ namespace VEPROMS.CSLA.Library
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cn.Open();
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
@@ -1434,7 +1321,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
ItemExtension _ItemExtension = new ItemExtension();
readonly ItemExtension _ItemExtension = new ItemExtension();
[Serializable()]
partial class ItemExtension : extensionBase
{
@@ -1443,14 +1330,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1479,57 +1360,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Item)
if (destType == typeof(string) && value is Item myitem)
{
// Return the ToString value
return ((Item)value).ToString();
return myitem.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create ItemExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Item
// {
// partial class ItemExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _AnnotationID;
[System.ComponentModel.DataObjectField(true, true)]
public int AnnotationID
@@ -224,19 +218,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current ItemAnnotation</returns>
protected override object GetIdValue()
{
return MyItemAnnotationUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base ItemAnnotation.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ItemAnnotation</returns>
//public override string ToString()
//{
// return base.ToString();
//}
protected override object GetIdValue() => MyItemAnnotationUnique; // Absolutely Unique ID
public override bool IsDirty
{
get
@@ -251,18 +233,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyAnnotationType == null ? false : _MyAnnotationType.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyAnnotationType != null && _MyAnnotationType.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyAnnotationType == null ? true : _MyAnnotationType.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyAnnotationType == null || _MyAnnotationType.IsValidList(list));
}
#endregion
#region ValidationRules
@@ -292,8 +271,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -324,80 +303,22 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AnnotationID, "<Role(s)>");
//AuthorizationRules.AllowRead(TypeID, "<Role(s)>");
//AuthorizationRules.AllowWrite(TypeID, "<Role(s)>");
//AuthorizationRules.AllowRead(RtfText, "<Role(s)>");
//AuthorizationRules.AllowWrite(RtfText, "<Role(s)>");
//AuthorizationRules.AllowRead(SearchText, "<Role(s)>");
//AuthorizationRules.AllowWrite(SearchText, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _ItemAnnotationUnique = 0;
private static int ItemAnnotationUnique
{ get { return ++_ItemAnnotationUnique; } }
private int _MyItemAnnotationUnique = ItemAnnotationUnique;
public int MyItemAnnotationUnique // Absolutely Unique ID - Editable FK
{ get { return _MyItemAnnotationUnique; } }
internal static ItemAnnotation New(AnnotationType myAnnotationType)
{
return new ItemAnnotation(myAnnotationType);
}
internal static ItemAnnotation Get(SafeDataReader dr)
{
return new ItemAnnotation(dr);
}
private static int ItemAnnotationUnique => ++_ItemAnnotationUnique;
private readonly int _MyItemAnnotationUnique = ItemAnnotationUnique;
// Absolutely Unique ID - Editable FK
public int MyItemAnnotationUnique => _MyItemAnnotationUnique;
internal static ItemAnnotation New(AnnotationType myAnnotationType) => new ItemAnnotation(myAnnotationType);
internal static ItemAnnotation Get(SafeDataReader dr) => new ItemAnnotation(dr);
public ItemAnnotation()
{
MarkAsChild();
@@ -425,15 +346,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ItemAnnotation()
{
_CountFinalized++;
@@ -474,33 +391,46 @@ namespace VEPROMS.CSLA.Library
internal void Insert(Item myItem)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Annotation.Add(cn, ref _AnnotationID, myItem, _MyAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Annotation.Add(cn, ref _AnnotationID, myItem, _MyAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID);
}
MarkOld();
}
internal void Update(Item myItem)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = Annotation.Update(cn, ref _AnnotationID, myItem.ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, ref _LastChanged);
if (!IsDirty) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = Annotation.Update(cn, ref _AnnotationID, myItem.ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Item myItem)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
if (!IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
Annotation.Remove(cn, _AnnotationID);
if (IsNew) return;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
Annotation.Remove(cn, _AnnotationID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
ItemAnnotationExtension _ItemAnnotationExtension = new ItemAnnotationExtension();
readonly ItemAnnotationExtension _ItemAnnotationExtension = new ItemAnnotationExtension();
[Serializable()]
partial class ItemAnnotationExtension : extensionBase
{
@@ -509,14 +439,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -545,57 +469,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ItemAnnotation)
if (destType == typeof(string) && value is ItemAnnotation annotation)
{
// Return the ToString value
return ((ItemAnnotation)value).ToString();
return annotation.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create ItemAnnotationExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ItemAnnotation
// {
// partial class ItemAnnotationExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,13 +29,10 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
// One To Many
public ItemAnnotation this[Annotation myAnnotation]
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
// One To Many
public ItemAnnotation this[Annotation myAnnotation]
{
get
{
@@ -47,11 +42,8 @@ namespace VEPROMS.CSLA.Library
return null;
}
}
public new System.Collections.Generic.IList<ItemAnnotation> Items
{
get { return base.Items; }
}
public ItemAnnotation GetItem(Annotation myAnnotation)
public new System.Collections.Generic.IList<ItemAnnotation> Items => base.Items;
public ItemAnnotation GetItem(Annotation myAnnotation)
{
foreach (ItemAnnotation annotation in this)
if (annotation.AnnotationID == myAnnotation.AnnotationID)
@@ -61,7 +53,7 @@ namespace VEPROMS.CSLA.Library
public ItemAnnotation Add(AnnotationType myAnnotationType) // One to Many
{
ItemAnnotation annotation = ItemAnnotation.New(myAnnotationType);
this.Add(annotation);
Add(annotation);
return annotation;
}
public void Remove(Annotation myAnnotation)
@@ -103,23 +95,20 @@ namespace VEPROMS.CSLA.Library
return true;
return false;
}
public override bool IsValid
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
get { return IsValidList(new List<object>()); }
}
public bool IsValidList(List<object> list)
{
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (ItemAnnotation child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
// run through all the child objects
// and if any are invalid then the
// collection is invalid
foreach (ItemAnnotation child in this)
if (!child.IsValidList(list))
{
//Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString());
return false;
}
return true;
}
#endregion
#region ValidationRules
public IVEHasBrokenRules HasBrokenRules
@@ -137,20 +126,14 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
#endregion
#region Factory Methods
internal static ItemAnnotations New()
{
return new ItemAnnotations();
}
internal static ItemAnnotations Get(SafeDataReader dr)
{
return new ItemAnnotations(dr);
}
public static ItemAnnotations GetByItemID(int itemID)
#endregion
#region Factory Methods
internal static ItemAnnotations New() => new ItemAnnotations();
internal static ItemAnnotations Get(SafeDataReader dr) => new ItemAnnotations(dr);
public static ItemAnnotations GetByItemID(int itemID)
{
try
{
@@ -161,11 +144,8 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ItemAnnotations.GetByItemID", ex);
}
}
private ItemAnnotations()
{
MarkAsChild();
}
internal ItemAnnotations(SafeDataReader dr)
private ItemAnnotations() => MarkAsChild();
internal ItemAnnotations(SafeDataReader dr)
{
MarkAsChild();
Fetch(dr);
@@ -174,16 +154,12 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemAnnotations()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ItemAnnotations()
{
_CountFinalized++;
}
@@ -198,19 +174,16 @@ namespace VEPROMS.CSLA.Library
// called to load data from the database
private void Fetch(SafeDataReader dr)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
while (dr.Read())
this.Add(ItemAnnotation.Get(dr));
this.RaiseListChangedEvents = true;
Add(ItemAnnotation.Get(dr));
RaiseListChangedEvents = true;
}
[Serializable()]
private class ItemIDCriteria
{
public ItemIDCriteria(int itemID)
{
_ItemID = itemID;
}
private int _ItemID;
public ItemIDCriteria(int itemID) => _ItemID = itemID;
private int _ItemID;
public int ItemID
{
get { return _ItemID; }
@@ -219,7 +192,7 @@ namespace VEPROMS.CSLA.Library
}
private void DataPortal_Fetch(ItemIDCriteria criteria)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAnnotations.DataPortal_FetchItemID", GetHashCode());
try
{
@@ -233,7 +206,7 @@ namespace VEPROMS.CSLA.Library
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read()) this.Add(new ItemAnnotation(dr));
while (dr.Read()) Add(new ItemAnnotation(dr));
}
}
}
@@ -243,11 +216,11 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAnnotations.DataPortal_FetchItemID", ex);
throw new DbCslaException("ItemAnnotations.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
internal void Update(Item item)
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
try
{
// update (thus deleting) any deleted child objects
@@ -266,49 +239,38 @@ namespace VEPROMS.CSLA.Library
}
finally
{
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
ItemAnnotationsPropertyDescriptor pd = new ItemAnnotationsPropertyDescriptor(this, i);
@@ -325,7 +287,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class ItemAnnotationsPropertyDescriptor : vlnListPropertyDescriptor
{
private ItemAnnotation Item { get { return (ItemAnnotation)_Item; } }
public ItemAnnotationsPropertyDescriptor(ItemAnnotations collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -334,10 +295,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ItemAnnotations)
if (destType == typeof(string) && value is ItemAnnotations annotations)
{
// Return department and department role separated by comma.
return ((ItemAnnotations)value).Items.Count.ToString() + " Annotations";
return $"{annotations.Items.Count} Annotations";
}
return base.ConvertTo(context, culture, value, destType);
}
+99 -229
View File
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
if (IsDirty)
refreshItemAudits.Add(this);
}
private void ClearRefreshList()
{
_RefreshItemAudits = new List<ItemAudit>();
}
private void ClearRefreshList() => _RefreshItemAudits = new List<ItemAudit>();
private void BuildRefreshList()
{
ClearRefreshList();
@@ -56,6 +51,7 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<ItemAudit> _CacheList = new List<ItemAudit>();
protected static void AddToCache(ItemAudit itemAudit)
{
@@ -65,6 +61,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(itemAudit)) _CacheList.Remove(itemAudit); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<ItemAudit>> _CacheByPrimaryKey = new Dictionary<string, List<ItemAudit>>();
private static void ConvertListToDictionary()
{
@@ -90,15 +87,9 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
private static int _nextAuditID = -1;
public static int NextAuditID
{
get { return _nextAuditID--; }
}
public static int NextAuditID => _nextAuditID--;
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -218,40 +209,14 @@ namespace VEPROMS.CSLA.Library
}
}
}
public override bool IsDirty
{
get { return base.IsDirty; }
}
public bool IsDirtyList(List<object> list)
{
return base.IsDirty;
}
public override bool IsValid
{
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
}
public bool IsValidList(List<object> list)
{
return (IsNew && !IsDirty) ? true : base.IsValid;
}
// CSLATODO: Replace base ItemAudit.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ItemAudit</returns>
//public override string ToString()
//{
// return base.ToString();
//}
public override bool IsDirty => base.IsDirty;
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
// CSLATODO: Check ItemAudit.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current ItemAudit</returns>
protected override object GetIdValue()
{
return MyItemAuditUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyItemAuditUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -279,8 +244,8 @@ namespace VEPROMS.CSLA.Library
get
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -299,35 +264,11 @@ namespace VEPROMS.CSLA.Library
_ItemAuditExtension.AddInstanceValidationRules(ValidationRules);
// CSLATODO: Add other validation rules
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(AuditID, "<Role(s)>");
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
//AuthorizationRules.AllowRead(PreviousID, "<Role(s)>");
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(DeleteStatus, "<Role(s)>");
//AuthorizationRules.AllowWrite(ItemID, "<Role(s)>");
//AuthorizationRules.AllowWrite(PreviousID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ContentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(DeleteStatus, "<Role(s)>");
_ItemAuditExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -335,42 +276,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_ItemAuditExtension.AddInstanceAuthorizationRules(AuthorizationRules);
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _ItemAuditUnique = 0;
protected static int ItemAuditUnique
{ get { return ++_ItemAuditUnique; } }
private int _MyItemAuditUnique = ItemAuditUnique;
public int MyItemAuditUnique // Absolutely Unique ID - Editable
{ get { return _MyItemAuditUnique; } }
protected static int ItemAuditUnique => ++_ItemAuditUnique;
private readonly int _MyItemAuditUnique = ItemAuditUnique;
// Absolutely Unique ID - Editable
public int MyItemAuditUnique => _MyItemAuditUnique;
protected ItemAudit()
{/* require use of factory methods */
AddToCache(this);
@@ -379,15 +292,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ItemAudit()
{
_CountFinalized++;
@@ -412,8 +321,6 @@ namespace VEPROMS.CSLA.Library
}
public static ItemAudit New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a ItemAudit");
try
{
return DataPortal.Create<ItemAudit>();
@@ -462,8 +369,6 @@ namespace VEPROMS.CSLA.Library
}
public static ItemAudit Get(long auditID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a ItemAudit");
try
{
ItemAudit tmp = GetCachedByPrimaryKey(auditID);
@@ -489,14 +394,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new ItemAudit(dr);
return null;
}
internal ItemAudit(SafeDataReader dr)
{
ReadData(dr);
}
internal ItemAudit(SafeDataReader dr) => ReadData(dr);
public static void Delete(long auditID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a ItemAudit");
try
{
DataPortal.Delete(new PKCriteria(auditID));
@@ -508,12 +408,6 @@ namespace VEPROMS.CSLA.Library
}
public override ItemAudit Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a ItemAudit");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a ItemAudit");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a ItemAudit");
try
{
BuildRefreshList();
@@ -533,13 +427,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private long _AuditID;
public long AuditID
{ get { return _AuditID; } }
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
private readonly long _AuditID;
public long AuditID => _AuditID;
public PKCriteria(long auditID) => _AuditID = auditID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -608,7 +498,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ItemAudit.DataPortal_Fetch", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
try
@@ -633,34 +523,40 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addItemAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ItemID", _ItemID);
cm.Parameters.AddWithValue("@PreviousID", _PreviousID);
cm.Parameters.AddWithValue("@ContentID", _ContentID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addItemAudit";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@ItemID", _ItemID);
cm.Parameters.AddWithValue("@PreviousID", _PreviousID);
cm.Parameters.AddWithValue("@ContentID", _ContentID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
_AuditID = (long)cm.Parameters["@newAuditID"].Value;
}
}
MarkOld();
// update child objects
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.SQLInsert", GetHashCode());
@@ -672,7 +568,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ItemAudit.SQLInsert", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Add(SqlConnection cn, ref long auditID, int itemID, int? previousID, int contentID, DateTime dts, string userID, int deleteStatus)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.Add", 0);
@@ -691,8 +587,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus);
// Output Calculated Columns
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt);
param_AuditID.Direction = ParameterDirection.Output;
SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_AuditID);
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
@@ -707,7 +605,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ItemAudit.Add", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
@@ -730,35 +628,39 @@ namespace VEPROMS.CSLA.Library
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateItemAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@ItemID", _ItemID);
cm.Parameters.AddWithValue("@PreviousID", _PreviousID);
cm.Parameters.AddWithValue("@ContentID", _ContentID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "updateItemAudit";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@AuditID", _AuditID);
cm.Parameters.AddWithValue("@ItemID", _ItemID);
cm.Parameters.AddWithValue("@PreviousID", _PreviousID);
cm.Parameters.AddWithValue("@ContentID", _ContentID);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus);
// Output Calculated Columns
// CSLATODO: Define any additional output parameters
cm.ExecuteNonQuery();
// Save all values being returned from the Procedure
}
}
}
MarkOld();
// use the open connection to update child objects
}
@@ -771,18 +673,22 @@ namespace VEPROMS.CSLA.Library
}
internal void Update()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
ItemAudit.Add(cn, ref _AuditID, _ItemID, _PreviousID, _ContentID, _DTS, _UserID, _DeleteStatus);
else
ItemAudit.Update(cn, ref _AuditID, _ItemID, _PreviousID, _ContentID, _DTS, _UserID, _DeleteStatus);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (IsNew)
ItemAudit.Add(cn, ref _AuditID, _ItemID, _PreviousID, _ContentID, _DTS, _UserID, _DeleteStatus);
else
ItemAudit.Update(cn, ref _AuditID, _ItemID, _PreviousID, _ContentID, _DTS, _UserID, _DeleteStatus);
}
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Update(SqlConnection cn, ref long auditID, int itemID, int? previousID, int contentID, DateTime dts, string userID, int deleteStatus)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.Update", 0);
@@ -814,12 +720,12 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ItemAudit.Update", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_AuditID));
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.DataPortal_Delete", GetHashCode());
@@ -844,7 +750,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ItemAudit.DataPortal_Delete", ex);
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, long auditID)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.Remove", 0);
@@ -870,7 +776,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
ItemAuditExtension _ItemAuditExtension = new ItemAuditExtension();
readonly ItemAuditExtension _ItemAuditExtension = new ItemAuditExtension();
[Serializable()]
partial class ItemAuditExtension : extensionBase
{
@@ -907,49 +813,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ItemAudit)
if (destType == typeof(string) && value is ItemAudit audit)
{
// Return the ToString value
return ((ItemAudit)value).ToString();
return audit.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create ItemAuditExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ItemAudit
// {
// partial class ItemAuditExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,14 +26,12 @@ namespace VEPROMS.CSLA.Library
public partial class ItemAuditInfo : ReadOnlyBase<ItemAuditInfo>, IDisposable
{
public event ItemAuditInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
private void OnChange() => Changed?.Invoke(this);
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<ItemAuditInfo> _CacheList = new List<ItemAuditInfo>();
protected static void AddToCache(ItemAuditInfo itemAuditInfo)
{
@@ -45,6 +41,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(itemAuditInfo)) _CacheList.Remove(itemAuditInfo); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<ItemAuditInfo>> _CacheByPrimaryKey = new Dictionary<string, List<ItemAuditInfo>>();
private static void ConvertListToDictionary()
{
@@ -74,21 +71,8 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
public string ErrorMessage => _ErrorMessage;
protected ItemAudit _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private long _AuditID;
[System.ComponentModel.DataObjectField(true, true)]
public long AuditID
@@ -153,32 +137,19 @@ namespace VEPROMS.CSLA.Library
return _DeleteStatus;
}
}
// CSLATODO: Replace base ItemAuditInfo.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ItemAuditInfo</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check ItemAuditInfo.GetIdValue to assure that the ID returned is unique
/// <summary>
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current ItemAuditInfo</returns>
protected override object GetIdValue()
{
return MyItemAuditInfoUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyItemAuditInfoUnique; // Absolutely Unique ID
#endregion
#region Factory Methods
private static int _ItemAuditInfoUnique = 0;
private static int ItemAuditInfoUnique
{ get { return ++_ItemAuditInfoUnique; } }
private int _MyItemAuditInfoUnique = ItemAuditInfoUnique;
public int MyItemAuditInfoUnique // Absolutely Unique ID - Info
{ get { return _MyItemAuditInfoUnique; } }
private static int ItemAuditInfoUnique => ++_ItemAuditInfoUnique;
private readonly int _MyItemAuditInfoUnique = ItemAuditInfoUnique;
// Absolutely Unique ID - Info
public int MyItemAuditInfoUnique => _MyItemAuditInfoUnique;
protected ItemAuditInfo()
{/* require use of factory methods */
AddToCache(this);
@@ -187,15 +158,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ItemAuditInfo()
{
_CountFinalized++;
@@ -212,10 +179,7 @@ namespace VEPROMS.CSLA.Library
if (listItemAuditInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list
}
public virtual ItemAudit Get()
{
return _Editable = ItemAudit.Get(_AuditID);
}
public virtual ItemAudit Get() => _Editable = ItemAudit.Get(_AuditID);
public static void Refresh(ItemAudit tmp)
{
string key = tmp.AuditID.ToString();
@@ -237,8 +201,6 @@ namespace VEPROMS.CSLA.Library
}
public static ItemAuditInfo Get(long auditID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a ItemAudit");
try
{
ItemAuditInfo tmp = GetCachedByPrimaryKey(auditID);
@@ -277,13 +239,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private long _AuditID;
public long AuditID
{ get { return _AuditID; } }
public PKCriteria(long auditID)
{
_AuditID = auditID;
}
private readonly long _AuditID;
public long AuditID => _AuditID;
public PKCriteria(long auditID) => _AuditID = auditID;
}
private void ReadData(SafeDataReader dr)
{
@@ -344,7 +302,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Refresh
#region extension
ItemAuditInfoExtension _ItemAuditInfoExtension = new ItemAuditInfoExtension();
readonly ItemAuditInfoExtension _ItemAuditInfoExtension = new ItemAuditInfoExtension();
[Serializable()]
partial class ItemAuditInfoExtension : extensionBase { }
[Serializable()]
@@ -360,10 +318,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ItemAuditInfo)
if (destType == typeof(string) && value is ItemAuditInfo info)
{
// Return the ToString value
return ((ItemAuditInfo)value).ToString();
return info.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -13,8 +13,6 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
@@ -28,11 +26,10 @@ namespace VEPROMS.CSLA.Library
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
internal new IList<ItemAuditInfo> Items
{ get { return base.Items; } }
public void AddEvents()
#endregion
#region Business Methods
internal new IList<ItemAuditInfo> Items => base.Items;
public void AddEvents()
{
foreach (ItemAuditInfo tmp in this)
{
@@ -44,23 +41,19 @@ namespace VEPROMS.CSLA.Library
for (int i = 0; i < Count; i++)
{
if (base[i] == sender)
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i));
}
}
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~ItemAuditInfoList()
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ItemAuditInfoList()
{
_CountFinalized++;
}
@@ -97,32 +90,17 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on ItemAuditInfoList.Get", ex);
}
}
/// <summary>
/// Reset the list of all ItemAuditInfo.
/// </summary>
public static void Reset()
{
_ItemAuditInfoList = null;
}
// CSLATODO: Add alternative gets -
//public static ItemAuditInfoList Get(<criteria>)
//{
// try
// {
// return DataPortal.Fetch<ItemAuditInfoList>(new FilteredCriteria(<criteria>));
// }
// catch (Exception ex)
// {
// throw new DbCslaException("Error on ItemAuditInfoList.Get", ex);
// }
//}
private ItemAuditInfoList()
/// <summary>
/// Reset the list of all ItemAuditInfo.
/// </summary>
public static void Reset() => _ItemAuditInfoList = null;
private ItemAuditInfoList()
{ /* require use of factory methods */ }
#endregion
#region Data Access Portal
private void DataPortal_Fetch()
{
this.RaiseListChangedEvents = false;
RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfoList.DataPortal_Fetch", GetHashCode());
try
{
@@ -136,7 +114,7 @@ namespace VEPROMS.CSLA.Library
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read()) this.Add(new ItemAuditInfo(dr));
while (dr.Read()) Add(new ItemAuditInfo(dr));
IsReadOnly = true;
}
}
@@ -147,48 +125,37 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("ItemAuditInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
RaiseListChangedEvents = true;
}
#endregion
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
#endregion
#region ICustomTypeDescriptor impl
public string GetClassName() => TypeDescriptor.GetClassName(this, true);
public AttributeCollection GetAttributes() => TypeDescriptor.GetAttributes(this, true);
public string GetComponentName() => TypeDescriptor.GetComponentName(this, true);
public TypeConverter GetConverter() => TypeDescriptor.GetConverter(this, true);
public EventDescriptor GetDefaultEvent() => TypeDescriptor.GetDefaultEvent(this, true);
public PropertyDescriptor GetDefaultProperty() => TypeDescriptor.GetDefaultProperty(this, true);
public object GetEditor(Type editorBaseType) => TypeDescriptor.GetEditor(this, editorBaseType, true);
public EventDescriptorCollection GetEvents(Attribute[] attributes) => TypeDescriptor.GetEvents(this, attributes, true);
public EventDescriptorCollection GetEvents() => TypeDescriptor.GetEvents(this, true);
public object GetPropertyOwner(PropertyDescriptor pd) => this;
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Items.Count; i++)
for (int i = 0; i < Items.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
ItemAuditInfoListPropertyDescriptor pd = new ItemAuditInfoListPropertyDescriptor(this, i);
@@ -205,7 +172,6 @@ namespace VEPROMS.CSLA.Library
/// </summary>
public partial class ItemAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor
{
private ItemAuditInfo Item { get { return (ItemAuditInfo)_Item; } }
public ItemAuditInfoListPropertyDescriptor(ItemAuditInfoList collection, int index) : base(collection, index) { ;}
}
#endregion
@@ -214,10 +180,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ItemAuditInfoList)
if (destType == typeof(string) && value is ItemAuditInfoList list)
{
// Return department and department role separated by comma.
return ((ItemAuditInfoList)value).Items.Count.ToString() + " ItemAudits";
return $"{list.Items.Count} ItemAudits";
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -9,12 +9,9 @@
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
@@ -31,11 +28,8 @@ namespace VEPROMS.CSLA.Library
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
private readonly string _ErrorMessage = string.Empty;
public string ErrorMessage => _ErrorMessage;
private int _VersionID;
[System.ComponentModel.DataObjectField(true, true)]
public int VersionID
@@ -329,19 +323,7 @@ namespace VEPROMS.CSLA.Library
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
/// </summary>
/// <returns>A Unique ID for the current ItemDocVersion</returns>
protected override object GetIdValue()
{
return MyItemDocVersionUnique; // Absolutely Unique ID
}
// CSLATODO: Replace base ItemDocVersion.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current ItemDocVersion</returns>
//public override string ToString()
//{
// return base.ToString();
//}
protected override object GetIdValue() => MyItemDocVersionUnique; // Absolutely Unique ID
public override bool IsDirty
{
get
@@ -356,18 +338,15 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_MyFolder != null && _MyFolder.IsDirtyList(list));
}
public override bool IsValid => IsValidList(new List<object>());
public bool IsValidList(List<object> list)
{
if (list.Contains(this))
return (IsNew && !IsDirty) ? true : base.IsValid;
return (IsNew && !IsDirty) || base.IsValid;
list.Add(this);
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_MyFolder == null || _MyFolder.IsValidList(list));
}
#endregion
#region ValidationRules
@@ -399,7 +378,7 @@ namespace VEPROMS.CSLA.Library
{
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
return hasBrokenRules?.BrokenRules;
}
}
protected override void AddBusinessRules()
@@ -432,84 +411,22 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
// if (_started > _ended)
// {
// e.Description = "Start date can't be after end date";
// return false;
// }
// else
// return true;
//}
#endregion
#region Authorization Rules
protected override void AddAuthorizationRules()
{
//CSLATODO: Who can read/write which fields
//AuthorizationRules.AllowRead(VersionID, "<Role(s)>");
//AuthorizationRules.AllowRead(FolderID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FolderID, "<Role(s)>");
//AuthorizationRules.AllowRead(VersionType, "<Role(s)>");
//AuthorizationRules.AllowWrite(VersionType, "<Role(s)>");
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
//AuthorizationRules.AllowRead(Title, "<Role(s)>");
//AuthorizationRules.AllowWrite(Title, "<Role(s)>");
//AuthorizationRules.AllowRead(FormatID, "<Role(s)>");
//AuthorizationRules.AllowWrite(FormatID, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
}
public static bool CanAddObject()
{
// CSLATODO: Can Add Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
public static bool CanGetObject()
{
// CSLATODO: CanGet Authorization
return true;
}
public static bool CanDeleteObject()
{
// CSLATODO: CanDelete Authorization
//bool result = false;
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
//return result;
return true;
}
public static bool CanEditObject()
{
// CSLATODO: CanEdit Authorization
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
return true;
}
#endregion
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
public int CurrentEditLevel => EditLevel;
private static int _ItemDocVersionUnique = 0;
private static int ItemDocVersionUnique
{ get { return ++_ItemDocVersionUnique; } }
private int _MyItemDocVersionUnique = ItemDocVersionUnique;
public int MyItemDocVersionUnique // Absolutely Unique ID - Editable FK
{ get { return _MyItemDocVersionUnique; } }
internal static ItemDocVersion New(Folder myFolder, string name)
{
return new ItemDocVersion(myFolder, name);
}
internal static ItemDocVersion Get(SafeDataReader dr)
{
return new ItemDocVersion(dr);
}
private static int ItemDocVersionUnique => ++_ItemDocVersionUnique;
private readonly int _MyItemDocVersionUnique = ItemDocVersionUnique;
// Absolutely Unique ID - Editable FK
public int MyItemDocVersionUnique => _MyItemDocVersionUnique;
internal static ItemDocVersion New(Folder myFolder, string name) => new ItemDocVersion(myFolder, name);
internal static ItemDocVersion Get(SafeDataReader dr) => new ItemDocVersion(dr);
public ItemDocVersion()
{
MarkAsChild();
@@ -540,15 +457,11 @@ namespace VEPROMS.CSLA.Library
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private static int IncrementCountCreated => ++_CountCreated;
private readonly int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated => _CountCreated;
public static int CountNotDisposed => _CountCreated - _CountDisposed;
public static int CountNotFinalized => _CountCreated - _CountFinalized;
~ItemDocVersion()
{
_CountFinalized++;
@@ -598,32 +511,45 @@ namespace VEPROMS.CSLA.Library
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = DocVersion.Add(cn, ref _VersionID, _MyFolder, _VersionType, _Name, _Title, myItem, _MyFormat, _Config, _DTS, _UserID);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = DocVersion.Add(cn, ref _VersionID, _MyFolder, _VersionType, _Name, _Title, myItem, _MyFormat, _Config, _DTS, _UserID);
}
MarkOld();
}
internal void Update(Item myItem)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
_LastChanged = DocVersion.Update(cn, ref _VersionID, _FolderID, _VersionType, _Name, _Title, myItem != null ? (int?)myItem.ItemID : (int?)null, _FormatID, _Config, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
_LastChanged = DocVersion.Update(cn, ref _VersionID, _FolderID, _VersionType, _Name, _Title, myItem != null ? (int?)myItem.ItemID : (int?)null, _FormatID, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
internal void DeleteSelf(Item myItem)
{
// if we're not dirty then don't update the database
if (!this.IsDirty) return;
// if we're new then don't update the database
if (this.IsNew) return;
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
DocVersion.Remove(cn, _VersionID);
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
DocVersion.Remove(cn, _VersionID);
}
MarkNew();
}
#endregion
// Standard Default Code
#region extension
ItemDocVersionExtension _ItemDocVersionExtension = new ItemDocVersionExtension();
readonly ItemDocVersionExtension _ItemDocVersionExtension = new ItemDocVersionExtension();
[Serializable()]
partial class ItemDocVersionExtension : extensionBase
{
@@ -632,18 +558,9 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual int DefaultVersionType
{
get { return 0; }
}
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual int DefaultVersionType => 0;
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -672,61 +589,13 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is ItemDocVersion)
if (destType == typeof(string) && value is ItemDocVersion version)
{
// Return the ToString value
return ((ItemDocVersion)value).ToString();
return version.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create ItemDocVersionExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class ItemDocVersion
// {
// partial class ItemDocVersionExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual int DefaultVersionType
// {
// get { return 0; }
// }
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// get { return Environment.UserName.ToUpper(); }
// }
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowRead(Dbid, "<Role(s)>");
// }
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
// {
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
// }
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddRule(
// Csla.Validation.CommonRules.StringMaxLength,
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
// }
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
// {
// rules.AddInstanceRule(/* Instance Validation Rule */);
// }
// }
// }
//}
Loaded 100 of 210 files, more files were not shown because too many files have changed in this diff. Show more